123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using wf;
- namespace MyRoomCustom
- {
- public class CreativeRoomUIObjectSettings : MonoBehaviour
- {
- private CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL typeGizmoControl
- {
- get
- {
- return this.m_TypeGizmoControl;
- }
- set
- {
- this.m_TypeGizmoControl = value;
- }
- }
- private CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL typeObjectControl
- {
- get
- {
- return this.m_TypeObjectControl;
- }
- set
- {
- this.m_TypeObjectControl = value;
- }
- }
- public float snapValuePosition
- {
- get
- {
- return this.m_SnapValuePosition;
- }
- set
- {
- this.m_SnapValuePosition = value;
- }
- }
- public float snapValueRotation
- {
- get
- {
- return this.m_SnapValueRotation;
- }
- set
- {
- this.m_SnapValueRotation = value;
- }
- }
- public float snapValueScale
- {
- get
- {
- return this.m_SnapValueScale;
- }
- set
- {
- this.m_SnapValueScale = value;
- }
- }
- public bool isVisibleDeployObject
- {
- get
- {
- return this.m_IsVisibleDeployObject;
- }
- set
- {
- Toggle uitoggleVisibleDeployObject = this.m_UIToggleVisibleDeployObject;
- this.m_IsVisibleDeployObject = value;
- uitoggleVisibleDeployObject.isOn = value;
- }
- }
- private void Awake()
- {
- }
- private void Start()
- {
- if (this.m_GizmoControlObject == null)
- {
- this.m_GizmoControlObject = new GameObject("[CreativeRoomUI ObjectSettings] GizmoControlObject").AddComponent<CreativeRoomUIObjectSettings.GizmoObject>();
- GameObject gameObject = new GameObject("Gizmo Rot");
- GameObject gameObject2 = Utility.CreatePrefab(null, "System/Prefab/XYZAxis", true);
- GizmoRender gizmoRender = gameObject.AddComponent<GizmoRender>();
- WorldTransformAxis component = gameObject2.GetComponent<WorldTransformAxis>();
- this.m_GizmoControlObject.Initialize(gizmoRender, component);
- gizmoRender.offsetScale = 1f;
- gizmoRender.eAxis = false;
- gizmoRender.eRotate = true;
- gizmoRender.eScal = false;
- component.TargetObject = this.m_GizmoControlObject.gameObject;
- this.ButtonEvent_SetSelectingObjectEnableMove();
- if (this.m_SelectingObject != null)
- {
- Transform transform = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.pos = transform.position;
- this.m_GizmoControlObject.eulerAngles = transform.eulerAngles;
- this.m_GizmoControlObject.scale = transform.localScale;
- }
- else
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- }
- this.m_UIToggleObjectEnable.onValueChanged.AddListener(delegate(bool value)
- {
- if (this.m_SelectingObject)
- {
- this.m_SelectingObject.SetActive(value);
- this.m_DeploymentObjectInstanceArray[this.m_SelectingObject].active = value;
- }
- });
- this.m_UIToggleGizmoGridEnable.onValueChanged.AddListener(delegate(bool value)
- {
- this.typeObjectControl = ((!value) ? CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL.Default : CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL.Snap);
- });
- Action<InputField, Action<float>, Action> action = delegate(InputField input_field_, Action<float> delegate_changed, Action delegate_end)
- {
- input_field_.onValueChanged.AddListener(delegate(string str)
- {
- if (!input_field_.isFocused || this.m_SelectingObject == null || delegate_changed == null)
- {
- return;
- }
- float obj;
- if (float.TryParse(str, out obj))
- {
- delegate_changed(obj);
- }
- });
- input_field_.onEndEdit.AddListener(delegate(string str)
- {
- if (this.m_SelectingObject == null || delegate_end == null)
- {
- return;
- }
- delegate_end();
- });
- };
- action(this.m_UIInputFieldPosX, delegate(float value)
- {
- Vector3 pos = this.m_GizmoControlObject.pos;
- pos.x = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 vector = pos;
- this.m_GizmoControlObject.pos = vector;
- transform2.position = vector;
- }, delegate
- {
- this.m_UIInputFieldPosX.text = this.m_GizmoControlObject.pos.x.ToString("f3");
- });
- action(this.m_UIInputFieldPosY, delegate(float value)
- {
- Vector3 pos = this.m_GizmoControlObject.pos;
- pos.y = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 vector = pos;
- this.m_GizmoControlObject.pos = vector;
- transform2.position = vector;
- }, delegate
- {
- this.m_UIInputFieldPosY.text = this.m_GizmoControlObject.pos.y.ToString("f3");
- });
- action(this.m_UIInputFieldPosZ, delegate(float value)
- {
- Vector3 pos = this.m_GizmoControlObject.pos;
- pos.z = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 vector = pos;
- this.m_GizmoControlObject.pos = vector;
- transform2.position = vector;
- }, delegate
- {
- this.m_UIInputFieldPosZ.text = this.m_GizmoControlObject.pos.z.ToString("f3");
- });
- action(this.m_UIInputFieldEulerX, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoControlObject.eulerAngles;
- eulerAngles.x = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 eulerAngles2 = eulerAngles;
- this.m_GizmoControlObject.eulerAngles = eulerAngles2;
- transform2.eulerAngles = eulerAngles2;
- }, delegate
- {
- this.m_UIInputFieldEulerX.text = this.m_GizmoControlObject.eulerAngles.x.ToString("f3");
- });
- action(this.m_UIInputFieldEulerY, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoControlObject.eulerAngles;
- eulerAngles.y = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 eulerAngles2 = eulerAngles;
- this.m_GizmoControlObject.eulerAngles = eulerAngles2;
- transform2.eulerAngles = eulerAngles2;
- }, delegate
- {
- this.m_UIInputFieldEulerY.text = this.m_GizmoControlObject.eulerAngles.y.ToString("f3");
- });
- action(this.m_UIInputFieldEulerZ, delegate(float value)
- {
- Vector3 eulerAngles = this.m_GizmoControlObject.eulerAngles;
- eulerAngles.z = value;
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 eulerAngles2 = eulerAngles;
- this.m_GizmoControlObject.eulerAngles = eulerAngles2;
- transform2.eulerAngles = eulerAngles2;
- }, delegate
- {
- this.m_UIInputFieldEulerZ.text = this.m_GizmoControlObject.eulerAngles.z.ToString("f3");
- });
- action(this.m_UIInputFieldScale, delegate(float value)
- {
- Vector3 scale = this.m_GizmoControlObject.scale;
- value = Mathf.Clamp(value, this.m_UISliderScale.minValue, this.m_UISliderScale.maxValue);
- scale.x = (scale.y = (scale.z = value));
- Transform transform2 = this.m_SelectingObject.transform;
- Vector3 vector = scale;
- this.m_GizmoControlObject.scale = vector;
- transform2.localScale = vector;
- this.m_UISliderScale.value = value;
- }, delegate
- {
- this.m_UIInputFieldScale.text = this.m_GizmoControlObject.scale.x.ToString("f3");
- });
- this.m_UISliderScale.onValueChanged.AddListener(delegate(float value)
- {
- if (this.m_GizmoControlObject == null || this.m_SelectingObject == null)
- {
- return;
- }
- Vector3 scale = this.m_GizmoControlObject.scale;
- scale.x = (scale.y = scale.z);
- if (!this.m_SelectingObject.activeInHierarchy)
- {
- if (Mathf.Approximately(scale.x, value))
- {
- return;
- }
- this.m_UISliderScale.value = scale.x;
- return;
- }
- else
- {
- if (Mathf.Approximately(scale.x, value))
- {
- return;
- }
- this.m_GizmoControlObject.scale = Vector3.one * value;
- this.m_UIInputFieldScale.text = value.ToString("f3");
- return;
- }
- });
- Action<string, Button, Func<Vector3>> action2 = delegate(string key, Button button, Func<Vector3> delegate_get_vector3)
- {
- button.onClick.AddListener(delegate()
- {
- if (this.m_SelectingObject == null)
- {
- return;
- }
- Vector3 vector = delegate_get_vector3();
- StringWriter stringWriter = new StringWriter();
- stringWriter.WriteLine(vector.x);
- stringWriter.WriteLine(vector.y);
- stringWriter.WriteLine(vector.z);
- this.SetClipboardData(key, stringWriter.ToString());
- });
- };
- Action<string, Button, Action<Vector3>> action3 = delegate(string key, Button button, Action<Vector3> delegate_return_vector3)
- {
- button.onClick.AddListener(delegate()
- {
- if (this.m_SelectingObject == null)
- {
- return;
- }
- string clipboardData = this.GetClipboardData(key);
- if (clipboardData == string.Empty)
- {
- return;
- }
- StringReader stringReader = new StringReader(clipboardData);
- try
- {
- Vector3 obj = default(Vector3);
- obj.x = float.Parse(stringReader.ReadLine());
- obj.y = float.Parse(stringReader.ReadLine());
- obj.z = float.Parse(stringReader.ReadLine());
- delegate_return_vector3(obj);
- }
- catch
- {
- }
- });
- };
- Action<Button, Func<Vector3>, Action<Vector3>> action4 = delegate(Button button, Func<Vector3> delegate_get_vector3, Action<Vector3> delegate_return_vector3)
- {
- button.onClick.AddListener(delegate()
- {
- if (this.m_SelectingObject == null)
- {
- return;
- }
- delegate_return_vector3(delegate_get_vector3());
- this.UpdateInputFieldText(this.m_SelectingObject.transform);
- });
- };
- Transform parent = this.m_UIInputFieldPosX.transform.parent;
- Button component2 = parent.Find("Button Copy").GetComponent<Button>();
- action2("pos", component2, () => this.m_GizmoControlObject.pos);
- component2 = parent.Find("Button Paste").GetComponent<Button>();
- action3("pos", component2, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.pos = vec;
- transform2.position = vec;
- this.UpdateInputFieldText(this.m_SelectingObject.transform);
- });
- component2 = parent.Find("Button Reset").GetComponent<Button>();
- action4(component2, () => Vector3.zero, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.pos = vec;
- transform2.position = vec;
- });
- parent = this.m_UIInputFieldEulerX.transform.parent;
- component2 = parent.Find("Button Copy").GetComponent<Button>();
- action2("rot", component2, () => this.m_GizmoControlObject.eulerAngles);
- component2 = parent.Find("Button Paste").GetComponent<Button>();
- action3("rot", component2, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.eulerAngles = vec;
- transform2.eulerAngles = vec;
- this.UpdateInputFieldText(this.m_SelectingObject.transform);
- });
- component2 = parent.Find("Button Reset").GetComponent<Button>();
- action4(component2, () => Vector3.zero, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.eulerAngles = vec;
- transform2.eulerAngles = vec;
- });
- parent = this.m_UIInputFieldScale.transform.parent;
- component2 = parent.Find("Button Copy").GetComponent<Button>();
- action2("scale", component2, () => this.m_GizmoControlObject.scale);
- component2 = parent.Find("Button Paste").GetComponent<Button>();
- action3("scale", component2, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.scale = vec;
- transform2.localScale = vec;
- this.UpdateInputFieldText(this.m_SelectingObject.transform);
- });
- component2 = parent.Find("Button Reset").GetComponent<Button>();
- action4(component2, () => Vector3.one, delegate(Vector3 vec)
- {
- Transform transform2 = this.m_SelectingObject.transform;
- this.m_GizmoControlObject.scale = vec;
- transform2.localScale = vec;
- });
- this.m_UIToggleVisibleDeployObject.onValueChanged.AddListener(delegate(bool value)
- {
- this.isVisibleDeployObject = value;
- List<GameObject> list = new List<GameObject>(this.m_DeploymentObjectInstanceArray.Keys);
- List<CreativeRoomUIObjectSettings.DeployObjectInstanceData> list2 = new List<CreativeRoomUIObjectSettings.DeployObjectInstanceData>(this.m_DeploymentObjectInstanceArray.Values);
- for (int i = 0; i < list.Count; i++)
- {
- list[i].SetActive(value & list2[i].active);
- }
- });
- }
- private void LateUpdate()
- {
- if (this.m_SelectingObject == null)
- {
- return;
- }
- Transform transform = this.m_SelectingObject.transform;
- Vector3 vector = this.m_GizmoControlObject.pos - transform.position;
- Vector3 vector2 = this.m_GizmoControlObject.eulerAngles - transform.eulerAngles;
- Vector3 vector3 = this.m_GizmoControlObject.scale - transform.localScale;
- if (this.m_SelectingObject.activeInHierarchy && (vector.sqrMagnitude > 0f || vector2.sqrMagnitude > 0f || vector3.sqrMagnitude > 0f))
- {
- if (this.typeObjectControl == CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL.Default)
- {
- transform.position = this.m_GizmoControlObject.pos;
- transform.rotation = this.m_GizmoControlObject.rot;
- transform.localScale = this.m_GizmoControlObject.scale;
- this.UpdateInputFieldText(transform);
- }
- else if (this.typeObjectControl == CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL.Snap)
- {
- if (vector.sqrMagnitude >= this.snapValuePosition * this.snapValuePosition)
- {
- Vector3 pos = this.m_GizmoControlObject.pos;
- pos.x = Mathf.Round(pos.x / this.snapValuePosition) * this.snapValuePosition;
- pos.y = Mathf.Round(pos.y / this.snapValuePosition) * this.snapValuePosition;
- pos.z = Mathf.Round(pos.z / this.snapValuePosition) * this.snapValuePosition;
- transform.position = pos;
- }
- if (vector2.sqrMagnitude >= this.snapValueRotation * this.snapValueRotation)
- {
- Quaternion rot = this.m_GizmoControlObject.rot;
- Quaternion rotation = transform.rotation;
- float snapValueRotation = this.snapValueRotation;
- float num = Quaternion.Angle(rotation, rot);
- if (Mathf.Abs(num) > snapValueRotation)
- {
- Quaternion rotation2 = Quaternion.RotateTowards(rotation, rot, Mathf.Floor(num / snapValueRotation) * snapValueRotation);
- transform.rotation = rotation2;
- }
- }
- if (vector3.sqrMagnitude >= this.snapValueScale * this.snapValueScale)
- {
- Vector3 localScale = Mathf.Round(this.m_GizmoControlObject.scale.x / this.snapValueScale) * this.snapValueScale * Vector3.one;
- transform.localScale = localScale;
- }
- if (vector.sqrMagnitude + vector2.sqrMagnitude + vector3.sqrMagnitude > 0f)
- {
- this.UpdateInputFieldText(transform);
- }
- }
- }
- if (NInput.GetMouseButtonUp(0) && this.m_SelectingObject)
- {
- this.m_GizmoControlObject.pos = transform.position;
- this.m_GizmoControlObject.eulerAngles = transform.eulerAngles;
- }
- if (!GizmoRender.UIVisible && GizmoRender.UIVisible != this.m_GizmoControlObject.gameObject.activeSelf)
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- }
- public void Update()
- {
- if (EventSystem.current != null)
- {
- if (NInput.GetMouseButtonDown(0))
- {
- GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
- if (EventSystem.current.IsPointerOverGameObject() && currentSelectedGameObject != null && currentSelectedGameObject.GetComponent<RectTransform>())
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- }
- else if (NInput.GetMouseButtonUp(0))
- {
- this.SetDeploymentObjectGizmoEnable(true);
- }
- }
- }
- private void SetClipboardData(string key, string value)
- {
- if (this.m_Clipboard.ContainsKey(key))
- {
- this.m_Clipboard[key] = value;
- }
- else
- {
- this.m_Clipboard.Add(key, value);
- }
- }
- private string GetClipboardData(string key)
- {
- if (!this.m_Clipboard.ContainsKey(key))
- {
- return string.Empty;
- }
- return this.m_Clipboard[key];
- }
- public void SetDeploymentObjectGizmoEnable(bool b)
- {
- if (this.m_GizmoControlObject == null)
- {
- return;
- }
- if (!base.gameObject.activeInHierarchy)
- {
- this.m_GizmoControlObject.gameObject.SetActive(false);
- }
- else if (this.m_SelectingObject == null)
- {
- this.m_GizmoControlObject.gameObject.SetActive(false);
- }
- else
- {
- this.m_GizmoControlObject.gameObject.SetActive(b);
- }
- }
- public void CreateOdoguObjectButtons(int placementObjCategoryID)
- {
- CreativeRoomUIObjectSettings.<CreateOdoguObjectButtons>c__AnonStorey4 <CreateOdoguObjectButtons>c__AnonStorey = new CreativeRoomUIObjectSettings.<CreateOdoguObjectButtons>c__AnonStorey4();
- <CreateOdoguObjectButtons>c__AnonStorey.placementObjCategoryID = placementObjCategoryID;
- <CreateOdoguObjectButtons>c__AnonStorey.$this = this;
- <CreateOdoguObjectButtons>c__AnonStorey.dataList = PlacementData.GetDatas((PlacementData.Data data) => data.categoryID == <CreateOdoguObjectButtons>c__AnonStorey.placementObjCategoryID);
- Debug.LogFormat("カテゴリID「{0}」\nデータ数「{1}」", new object[]
- {
- <CreateOdoguObjectButtons>c__AnonStorey.placementObjCategoryID,
- <CreateOdoguObjectButtons>c__AnonStorey.dataList.Count
- });
- this.m_UIParentDeployableObjectButtons.Show<Button>(<CreateOdoguObjectButtons>c__AnonStorey.dataList.Count, delegate(int i, Button button)
- {
- PlacementData.Data data = <CreateOdoguObjectButtons>c__AnonStorey.dataList[i];
- Text componentInChildren = button.GetComponentInChildren<Text>();
- RawImage component = button.GetComponent<RawImage>();
- Texture texture = null;
- if (!<CreateOdoguObjectButtons>c__AnonStorey.$this.m_CachedItemIconDic.TryGetValue(data.ID, out texture))
- {
- texture = data.GetThumbnail();
- <CreateOdoguObjectButtons>c__AnonStorey.$this.m_CachedItemIconDic.Add(data.ID, texture);
- }
- if (texture != null)
- {
- componentInChildren.gameObject.SetActive(false);
- component.texture = texture;
- }
- else
- {
- componentInChildren.text = data.drawName;
- }
- button.onClick.AddListener(delegate()
- {
- GameObject gameObject = <CreateOdoguObjectButtons>c__AnonStorey.CreateOdoguObject(data.ID);
- if (!gameObject)
- {
- return;
- }
- <CreateOdoguObjectButtons>c__AnonStorey.AddEvent_ObjectClickSelect(gameObject);
- <CreateOdoguObjectButtons>c__AnonStorey.CreateDeploymentObjectButtons();
- <CreateOdoguObjectButtons>c__AnonStorey.SetSelectingObject(gameObject, null);
- <CreateOdoguObjectButtons>c__AnonStorey.m_UIToggleVisibleDeployObject.isOn = true;
- });
- });
- }
- private GameObject CreateOdoguObject(int objectID)
- {
- GameObject gameObject = GameObject.Find("Deployment Object Parent");
- if (gameObject == null)
- {
- gameObject = new GameObject("Deployment Object Parent");
- }
- if (!PlacementData.Contains(objectID))
- {
- Debug.LogWarningFormat("[Creative Room]配置物データID[{0}]の情報は存在しません", new object[]
- {
- objectID
- });
- return null;
- }
- PlacementData.Data data = PlacementData.GetData(objectID);
- GameObject prefab = data.GetPrefab();
- if (prefab == null)
- {
- return null;
- }
- GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(prefab);
- GameObject gameObject3 = new GameObject(gameObject2.name);
- gameObject2.transform.SetParent(gameObject3.transform, true);
- CreativeRoomUIObjectSettings.DeployObjectInstanceData value = new CreativeRoomUIObjectSettings.DeployObjectInstanceData(CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL.Default, objectID, null);
- this.m_DeploymentObjectInstanceArray.Add(gameObject3, value);
- gameObject3.transform.SetParent(gameObject.transform, false);
- return gameObject3;
- }
- private void AddEvent_ObjectClickSelect(GameObject Obj)
- {
- Collider[] cols = Obj.GetComponentsInChildren<Collider>();
- if (cols.Length <= 0)
- {
- Debug.LogWarning("配置物[" + Obj.name + "]に、当たり判定がついていないので強制的に追加しました");
- MeshRenderer componentInChildren = Obj.GetComponentInChildren<MeshRenderer>(true);
- if (componentInChildren != null)
- {
- componentInChildren.gameObject.AddComponent<BoxCollider>();
- }
- cols = Obj.GetComponentsInChildren<Collider>();
- }
- CreativeRoomUIObjectSettings.MouseEvent mouseEvent = cols[0].gameObject.AddComponent<CreativeRoomUIObjectSettings.MouseEvent>();
- mouseEvent.onPointerClick = delegate(PointerEventData data)
- {
- if (NInput.GetMouseButtonUp(0))
- {
- this.SetSelectingObject(Obj, null);
- }
- };
- mouseEvent.onBeginDrag = delegate(PointerEventData data)
- {
- for (int i = 0; i < cols.Length; i++)
- {
- cols[i].enabled = false;
- }
- };
- mouseEvent.onEndDrag = delegate(PointerEventData data)
- {
- for (int i = 0; i < cols.Length; i++)
- {
- cols[i].enabled = true;
- }
- };
- }
- public void ButtonEvent_SetSelectingObjectEnableMove()
- {
- this.m_GizmoControlObject.activeAxis = true;
- this.m_GizmoControlObject.activeRot = false;
- this.m_TypeGizmoControl = CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.Move;
- }
- public void ButtonEvent_SetSelectingObjectEnableRot()
- {
- this.m_GizmoControlObject.activeAxis = false;
- this.m_GizmoControlObject.activeRot = true;
- this.m_TypeGizmoControl = CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.Rotate;
- }
- public void ButtonEvent_SetSelectingObjectDisableGizmo()
- {
- this.m_GizmoControlObject.activeAxis = false;
- this.m_GizmoControlObject.activeRot = false;
- this.m_TypeGizmoControl = CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.None;
- }
- public void SetSelectingObject(GameObject newObj, GameObject buttonObj = null)
- {
- if (newObj && this.m_GizmoControlObject)
- {
- this.m_GizmoControlObject.pos = newObj.transform.position;
- this.m_GizmoControlObject.eulerAngles = newObj.transform.eulerAngles;
- this.m_GizmoControlObject.scale = newObj.transform.localScale;
- this.SetDeploymentObjectGizmoEnable(true);
- if (this.typeGizmoControl == CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.Move)
- {
- this.ButtonEvent_SetSelectingObjectEnableMove();
- }
- else if (this.typeGizmoControl == CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.Rotate)
- {
- this.ButtonEvent_SetSelectingObjectEnableRot();
- }
- else if (this.typeGizmoControl == CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL.None)
- {
- this.ButtonEvent_SetSelectingObjectDisableGizmo();
- }
- }
- this.m_SelectingObject = newObj;
- this.typeGizmoControl = this.typeGizmoControl;
- if (newObj)
- {
- this.m_UIToggleObjectEnable.isOn = newObj.activeInHierarchy;
- }
- if (newObj)
- {
- this.UpdateInputFieldText(newObj.transform);
- }
- if (newObj == null)
- {
- if (this.m_GizmoControlObject)
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- return;
- }
- Transform transform = this.m_UIParentDeploymentObjectButtons.transform;
- if (buttonObj == null && (buttonObj = this.m_DeploymentObjectInstanceArray[newObj].uiButtonObject) == null)
- {
- return;
- }
- Color color = new Color(0.65f, 0.65f, 0.65f, 1f);
- Color white = Color.white;
- for (int i = 0; i < transform.childCount; i++)
- {
- Transform child = transform.GetChild(i);
- Graphic targetGraphic = child.GetChild(0).GetComponent<Selectable>().targetGraphic;
- if (buttonObj != child.gameObject)
- {
- targetGraphic.color = color;
- }
- else
- {
- targetGraphic.color = white;
- }
- }
- }
- public void ButtonEvent_CameraFocus()
- {
- if (this.m_SelectingObject == null)
- {
- return;
- }
- WfCameraMoveSupport wfCameraMoveSupport = base.GetComponent<WfCameraMoveSupport>();
- if (wfCameraMoveSupport == null)
- {
- wfCameraMoveSupport = base.gameObject.AddComponent<WfCameraMoveSupport>();
- }
- Vector3 position = this.m_SelectingObject.transform.position;
- float distance = 5f;
- Vector2 aroundAngle = new Vector2(-135f, 45f);
- wfCameraMoveSupport.StartCameraPosition(position, distance, aroundAngle);
- }
- private void UpdateInputFieldText(Transform trans)
- {
- if (trans)
- {
- this.UpdateInputFieldText(trans.position, trans.eulerAngles, trans.lossyScale);
- }
- else
- {
- this.UpdateInputFieldText(Vector3.zero, Vector3.zero, Vector3.zero);
- }
- }
- private void UpdateInputFieldText(Vector3 pos, Vector3 euler, Vector3 scale)
- {
- if (!this.m_UIInputFieldPosX.isFocused)
- {
- this.m_UIInputFieldPosX.text = pos.x.ToString("f3");
- }
- if (!this.m_UIInputFieldPosY.isFocused)
- {
- this.m_UIInputFieldPosY.text = pos.y.ToString("f3");
- }
- if (!this.m_UIInputFieldPosZ.isFocused)
- {
- this.m_UIInputFieldPosZ.text = pos.z.ToString("f3");
- }
- if (!this.m_UIInputFieldEulerX.isFocused)
- {
- this.m_UIInputFieldEulerX.text = euler.x.ToString("f3");
- }
- if (!this.m_UIInputFieldEulerY.isFocused)
- {
- this.m_UIInputFieldEulerY.text = euler.y.ToString("f3");
- }
- if (!this.m_UIInputFieldEulerZ.isFocused)
- {
- this.m_UIInputFieldEulerZ.text = euler.z.ToString("f3");
- }
- if (!this.m_UIInputFieldScale.isFocused)
- {
- this.m_UIInputFieldScale.text = scale.x.ToString("f3");
- }
- this.m_UISliderScale.value = scale.x;
- }
- private void CreateDeploymentObjectButtons()
- {
- uGUIListViewer uiparentDeploymentObjectButtons = this.m_UIParentDeploymentObjectButtons;
- Transform transform = uiparentDeploymentObjectButtons.transform;
- VerticalLayoutGroup component = uiparentDeploymentObjectButtons.GetComponent<VerticalLayoutGroup>();
- component.enabled = false;
- Transform child = transform.GetChild(0);
- List<GameObject> list = new List<GameObject>(this.m_DeploymentObjectInstanceArray.Keys);
- for (int i = 0; i < this.m_DeploymentObjectInstanceArray.Count; i++)
- {
- GameObject Obj = list[i];
- CreativeRoomUIObjectSettings.DeployObjectInstanceData deployObjectInstanceData = this.m_DeploymentObjectInstanceArray[Obj];
- if (!(deployObjectInstanceData.uiButtonObject != null))
- {
- if (PlacementData.Contains(deployObjectInstanceData.objectID))
- {
- Transform transform2 = UnityEngine.Object.Instantiate<Transform>(child);
- transform2.gameObject.SetActive(true);
- transform2.SetParent(transform, false);
- Button[] componentsInChildren = transform2.GetComponentsInChildren<Button>();
- componentsInChildren[0].GetComponentInChildren<Text>().text = PlacementData.GetData(deployObjectInstanceData.objectID).drawName;
- componentsInChildren[0].onClick.RemoveAllListeners();
- componentsInChildren[1].onClick.RemoveAllListeners();
- componentsInChildren[0].onClick.AddListener(delegate()
- {
- if (this.m_SelectingObject == Obj)
- {
- this.ButtonEvent_CameraFocus();
- }
- else
- {
- this.SetSelectingObject(Obj, null);
- }
- });
- componentsInChildren[1].onClick.AddListener(delegate()
- {
- this.DestroyDeploymentObject(Obj);
- });
- deployObjectInstanceData.uiButtonObject = transform2.gameObject;
- }
- }
- }
- this.m_UITextDeployObjectNum.text = this.m_DeploymentObjectInstanceArray.Count.ToString() + "個";
- component.enabled = true;
- }
- private void DestroyDeploymentObject(GameObject Obj)
- {
- if (this.m_SelectingObject != null && this.m_SelectingObject == Obj)
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- if (this.m_DeploymentObjectInstanceArray.ContainsKey(Obj))
- {
- UnityEngine.Object.Destroy(this.m_DeploymentObjectInstanceArray[Obj].uiButtonObject);
- this.m_DeploymentObjectInstanceArray.Remove(Obj);
- UnityEngine.Object.Destroy(Obj);
- }
- this.m_UITextDeployObjectNum.text = this.m_DeploymentObjectInstanceArray.Count.ToString() + "個";
- }
- public void SaveDeployObjectData(BinaryWriter binary)
- {
- int count = this.m_DeploymentObjectInstanceArray.Count;
- binary.Write(count);
- List<GameObject> list = new List<GameObject>(this.m_DeploymentObjectInstanceArray.Keys);
- for (int i = 0; i < count; i++)
- {
- GameObject gameObject = list[i];
- CreativeRoomUIObjectSettings.DeployObjectInstanceData deployObjectInstanceData = this.m_DeploymentObjectInstanceArray[gameObject];
- binary.Write(gameObject.transform.position.x);
- binary.Write(gameObject.transform.position.y);
- binary.Write(gameObject.transform.position.z);
- binary.Write(gameObject.transform.eulerAngles.x);
- binary.Write(gameObject.transform.eulerAngles.y);
- binary.Write(gameObject.transform.eulerAngles.z);
- binary.Write(gameObject.transform.localScale.x);
- binary.Write(deployObjectInstanceData.active);
- binary.Write(deployObjectInstanceData.objectID);
- }
- }
- public void LoadDeployObjectData(BinaryReader brRead)
- {
- List<GameObject> list = new List<GameObject>(this.m_DeploymentObjectInstanceArray.Keys);
- for (int i = 0; i < list.Count; i++)
- {
- this.DestroyDeploymentObject(list[i]);
- }
- int num = brRead.ReadInt32();
- for (int j = 0; j < num; j++)
- {
- Vector3 zero = Vector3.zero;
- Vector3 zero2 = Vector3.zero;
- Vector3 localScale = Vector3.zero;
- zero[0] = brRead.ReadSingle();
- zero[1] = brRead.ReadSingle();
- zero[2] = brRead.ReadSingle();
- zero2[0] = brRead.ReadSingle();
- zero2[1] = brRead.ReadSingle();
- zero2[2] = brRead.ReadSingle();
- localScale = brRead.ReadSingle() * Vector3.one;
- bool active = brRead.ReadBoolean();
- int objectID = brRead.ReadInt32();
- GameObject gameObject = this.CreateOdoguObject(objectID);
- if (gameObject)
- {
- Transform transform = gameObject.transform;
- transform.position = zero;
- transform.eulerAngles = zero2;
- transform.localScale = localScale;
- gameObject.SetActive(active);
- this.AddEvent_ObjectClickSelect(gameObject);
- }
- }
- this.SetSelectingObject(null, null);
- this.CreateDeploymentObjectButtons();
- this.m_UIToggleVisibleDeployObject.isOn = true;
- }
- public static GameObject Load(BinaryReader brRead)
- {
- GameObject gameObject = new GameObject("Parent Deployment Object");
- Transform transform = gameObject.transform;
- int num = brRead.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- Vector3 zero = Vector3.zero;
- Vector3 zero2 = Vector3.zero;
- Vector3 localScale = Vector3.zero;
- zero[0] = brRead.ReadSingle();
- zero[1] = brRead.ReadSingle();
- zero[2] = brRead.ReadSingle();
- zero2[0] = brRead.ReadSingle();
- zero2[1] = brRead.ReadSingle();
- zero2[2] = brRead.ReadSingle();
- localScale = brRead.ReadSingle() * Vector3.one;
- bool active = brRead.ReadBoolean();
- int num2 = brRead.ReadInt32();
- if (!PlacementData.Contains(num2))
- {
- Debug.LogWarningFormat("[Creative Room]配置物データID[{0}]の情報は存在しません", new object[]
- {
- num2
- });
- }
- else
- {
- PlacementData.Data data = PlacementData.GetData(num2);
- GameObject prefab = data.GetPrefab();
- if (!(prefab == null))
- {
- GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(prefab);
- GameObject gameObject3 = new GameObject(gameObject2.name);
- gameObject2.transform.SetParent(gameObject3.transform, true);
- Transform transform2 = gameObject3.transform;
- transform2.position = zero;
- transform2.eulerAngles = zero2;
- transform2.localScale = localScale;
- gameObject2.SetActive(active);
- transform2.SetParent(transform, true);
- }
- }
- }
- return gameObject;
- }
- private void OnEnable()
- {
- CreativeRoomUIObjectSettings.<OnEnable>c__AnonStorey8 <OnEnable>c__AnonStorey = new CreativeRoomUIObjectSettings.<OnEnable>c__AnonStorey8();
- <OnEnable>c__AnonStorey.$this = this;
- <OnEnable>c__AnonStorey.categoryIDList = PlacementData.CategoryIDList;
- this.m_UIParentDeployableObjectCategoryButtons.Show<Button>(<OnEnable>c__AnonStorey.categoryIDList.Count, delegate(int i, Button button)
- {
- Text componentInChildren = button.GetComponentInChildren<Text>();
- componentInChildren.text = PlacementData.GetCategoryName(<OnEnable>c__AnonStorey.categoryIDList[i]);
- button.onClick.AddListener(delegate()
- {
- Debug.LogFormat("カテゴリ「{0}」", new object[]
- {
- PlacementData.GetCategoryName(<OnEnable>c__AnonStorey.categoryIDList[i])
- });
- <OnEnable>c__AnonStorey.CreateOdoguObjectButtons(<OnEnable>c__AnonStorey.categoryIDList[i]);
- });
- });
- }
- private void OnDisable()
- {
- this.SetDeploymentObjectGizmoEnable(false);
- }
- private void OnDestroy()
- {
- if (this.m_DeploymentObjectInstanceArray != null)
- {
- this.m_DeploymentObjectInstanceArray.Clear();
- }
- if (this.m_Clipboard != null)
- {
- this.m_Clipboard.Clear();
- }
- GameObject gameObject = GameObject.Find("Deployment Object Parent");
- if (gameObject != null)
- {
- UnityEngine.Object.Destroy(gameObject);
- }
- if (this.m_CachedItemIconDic != null)
- {
- int count = this.m_CachedItemIconDic.Count;
- List<Texture> list = new List<Texture>(this.m_CachedItemIconDic.Values);
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i] != null)
- {
- UnityEngine.Object.DestroyImmediate(list[i], true);
- }
- list[i] = null;
- }
- this.m_CachedItemIconDic.Clear();
- }
- if (this.m_GizmoControlObject)
- {
- UnityEngine.Object.Destroy(this.m_GizmoControlObject);
- }
- }
- [Header("配置オブジェクトのカテゴリ一覧関連")]
- [SerializeField]
- [Tooltip("配置オブジェクトのカテゴリ一覧関連")]
- private uGUIListViewer m_UIParentDeployableObjectCategoryButtons;
- [Header("配置可能オブジェクト一覧関連")]
- [SerializeField]
- [Tooltip("配置可能オブジェクトのボタンを並べている親オブジェクト")]
- private uGUIListViewer m_UIParentDeployableObjectButtons;
- [Header("オブジェクトパラメータ一覧関連")]
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの有効/無効を切り替えるトグル ")]
- private Toggle m_UIToggleObjectEnable;
- [SerializeField]
- [Tooltip("オブジェクトのパラメータ操作スナップの有効/無効を切り替えるトグル")]
- private Toggle m_UIToggleGizmoGridEnable;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの座標を入出力するエリア")]
- private InputField m_UIInputFieldPosX;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの座標を入出力するエリア")]
- private InputField m_UIInputFieldPosY;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの座標を入出力するエリア")]
- private InputField m_UIInputFieldPosZ;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの回転を入出力するエリア")]
- private InputField m_UIInputFieldEulerX;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの回転を入出力するエリア")]
- private InputField m_UIInputFieldEulerY;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの回転を入出力するエリア")]
- private InputField m_UIInputFieldEulerZ;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの大きさを入出力するエリア")]
- private InputField m_UIInputFieldScale;
- [SerializeField]
- [Tooltip("選択中の配置オブジェクトの大きさを入出力するスライダー")]
- private Slider m_UISliderScale;
- [Header("配置中オブジェクト一覧関連")]
- [SerializeField]
- [Tooltip("配置中オブジェクトの数を表示するテキスト")]
- private Text m_UITextDeployObjectNum;
- [SerializeField]
- [Tooltip("配置中オブジェクトのボタンを並べている親オブジェクト")]
- private uGUIListViewer m_UIParentDeploymentObjectButtons;
- [SerializeField]
- [Tooltip("すべての配置中オブジェクトの表示/非表示を切り替えるトグル")]
- private Toggle m_UIToggleVisibleDeployObject;
- private GameObject m_SelectingObject;
- private CreativeRoomUIObjectSettings.GizmoObject m_GizmoControlObject;
- private Dictionary<GameObject, CreativeRoomUIObjectSettings.DeployObjectInstanceData> m_DeploymentObjectInstanceArray = new Dictionary<GameObject, CreativeRoomUIObjectSettings.DeployObjectInstanceData>();
- private Dictionary<string, string> m_Clipboard = new Dictionary<string, string>();
- private Dictionary<int, Texture> m_CachedItemIconDic = new Dictionary<int, Texture>();
- private CreativeRoomUIObjectSettings.TYPE_GIZMO_CONTROL m_TypeGizmoControl;
- private CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL m_TypeObjectControl;
- private float m_SnapValuePosition = 0.5f;
- private float m_SnapValueRotation = 15f;
- private float m_SnapValueScale = 0.1f;
- private bool m_IsVisibleDeployObject;
- private enum TYPE_GIZMO_CONTROL
- {
- Move,
- Rotate,
- None
- }
- private enum TYPE_OBJECT_CONTROL
- {
- Default,
- Snap
- }
- private class DeployObjectInstanceData
- {
- public DeployObjectInstanceData(CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL type_, int objectID_, GameObject uiButtonObject_)
- {
- this.type = type_;
- this.objectID = objectID_;
- this.uiButtonObject = uiButtonObject_;
- this.active = true;
- }
- public CreativeRoomUIObjectSettings.TYPE_OBJECT_CONTROL type;
- public int objectID;
- public GameObject uiButtonObject;
- public bool active;
- }
- private class MouseEvent : MonoBehaviour, IPointerClickHandler, IBeginDragHandler, IEndDragHandler, IEventSystemHandler
- {
- public void OnPointerClick(PointerEventData data)
- {
- if (this.onPointerClick != null)
- {
- this.onPointerClick(data);
- }
- }
- public void OnBeginDrag(PointerEventData data)
- {
- if (this.onBeginDrag != null)
- {
- this.onBeginDrag(data);
- }
- }
- public void OnEndDrag(PointerEventData data)
- {
- if (this.onEndDrag != null)
- {
- this.onEndDrag(data);
- }
- }
- public Action<PointerEventData> onPointerClick;
- public Action<PointerEventData> onBeginDrag;
- public Action<PointerEventData> onEndDrag;
- }
- private class GizmoObject : MonoBehaviour
- {
- public GizmoRender gizmoRot { get; private set; }
- public WorldTransformAxis gizmoAxis { get; private set; }
- public Vector3 pos
- {
- get
- {
- return base.transform.position;
- }
- set
- {
- base.transform.position = value;
- }
- }
- public Vector3 eulerAngles
- {
- get
- {
- return this.gizmoRot.transform.eulerAngles;
- }
- set
- {
- this.gizmoRot.transform.eulerAngles = value;
- }
- }
- public Vector3 scale
- {
- get
- {
- return this.gizmoRot.transform.localScale;
- }
- set
- {
- this.gizmoRot.transform.localScale = value;
- }
- }
- public Quaternion rot
- {
- get
- {
- return this.gizmoRot.transform.rotation;
- }
- set
- {
- this.gizmoRot.transform.rotation = value;
- }
- }
- public bool activeAxis
- {
- get
- {
- return this.gizmoAxis.gameObject.activeInHierarchy;
- }
- set
- {
- this.gizmoAxis.gameObject.SetActive(value);
- }
- }
- public bool activeRot
- {
- get
- {
- return this.gizmoRot.gameObject.activeInHierarchy;
- }
- set
- {
- this.gizmoRot.gameObject.SetActive(value);
- }
- }
- public void Initialize(GizmoRender gizmoRot, WorldTransformAxis gizmoAxis)
- {
- this.gizmoRot = gizmoRot;
- this.gizmoAxis = gizmoAxis;
- this.gizmoRot.transform.SetParent(base.gameObject.transform);
- this.gizmoAxis.transform.SetParent(base.gameObject.transform);
- }
- private void OnDestroy()
- {
- if (this.gizmoRot != null && this.gizmoRot.lineMaterial != null)
- {
- UnityEngine.Object.Destroy(this.gizmoRot.lineMaterial);
- }
- }
- }
- }
- }
|