1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237 |
- 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)
- {
- List<PlacementData.Data> dataList = PlacementData.GetDatas((PlacementData.Data data) => data.categoryID == placementObjCategoryID);
- Debug.LogFormat("カテゴリID「{0}」\nデータ数「{1}」", new object[]
- {
- placementObjCategoryID,
- dataList.Count
- });
- this.m_UIParentDeployableObjectButtons.Show<Button>(dataList.Count, delegate(int i, Button button)
- {
- PlacementData.Data data = dataList[i];
- Text componentInChildren = button.GetComponentInChildren<Text>();
- RawImage component = button.GetComponent<RawImage>();
- Texture texture = null;
- if (!this.m_CachedItemIconDic.TryGetValue(data.ID, out texture))
- {
- texture = data.GetThumbnail();
- 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 = this.CreateOdoguObject(data.ID);
- if (!gameObject)
- {
- return;
- }
- this.AddEvent_ObjectClickSelect(gameObject);
- this.CreateDeploymentObjectButtons();
- this.SetSelectingObject(gameObject, null);
- this.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()
- {
- List<int> categoryIDList = PlacementData.CategoryIDList;
- this.m_UIParentDeployableObjectCategoryButtons.Show<Button>(categoryIDList.Count, delegate(int i, Button button)
- {
- Text componentInChildren = button.GetComponentInChildren<Text>();
- componentInChildren.text = PlacementData.GetCategoryName(categoryIDList[i]);
- button.onClick.AddListener(delegate
- {
- Debug.LogFormat("カテゴリ「{0}」", new object[]
- {
- PlacementData.GetCategoryName(categoryIDList[i])
- });
- this.CreateOdoguObjectButtons(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);
- }
- }
- }
- }
- }
|