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);
				}
			}
		}
	}
}
