LightWindow.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class LightWindow : BaseMaidPhotoWindow
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. this.tabPanel = this.contentGrid.GetComponent<UIWFTabPanel>();
  11. EventDelegate.Add(this.addBtn.onClick, new EventDelegate.Callback(this.OnClickAddButton));
  12. EventDelegate.Add(this.removeBtn.onClick, new EventDelegate.Callback(this.OnClickRemoveButton));
  13. this.checkBoxVisible.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxVisible));
  14. this.checkBoxPoint.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxSwitching));
  15. this.checkBoxSpot.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxSwitching));
  16. this.cameraMoveSupport = base.gameObject.AddComponent<WfCameraMoveSupport>();
  17. EventDelegate.Add(this.cameraFocusBtn.onClick, new EventDelegate.Callback(this.OnClickCameraFocus));
  18. this.scrollView = NGUITools.FindInParents<UIScrollView>(this.contentGrid.transform);
  19. this.targetList.Add(new PhotoTransTargetObject(null, "メインライト", PhotoTransTargetObject.Type.Maid, Vector2.one));
  20. this.CreateTabButton(this.contentGrid.gameObject, this.targetList[0]);
  21. this.tabPanel.UpdateChildren();
  22. this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponentInChildren<UIWFTabButton>());
  23. Utility.ResetNGUI(this.contentGrid);
  24. Utility.ResetNGUI(this.scrollView);
  25. this.UpdateChildren();
  26. }
  27. public override void Start()
  28. {
  29. base.Start();
  30. this.AddTransTargetObject(this.InstantiateLight(), "1 : ポイントライト", PhotoTransTargetObject.Type.Light);
  31. this.AddTransTargetObject(this.InstantiateLight(), "2 : ポイントライト", PhotoTransTargetObject.Type.Light);
  32. this.AddTransTargetObject(this.InstantiateLight(), "3 : ポイントライト", PhotoTransTargetObject.Type.Light);
  33. this.AddTransTargetObject(this.InstantiateLight(), "4 : ポイントライト", PhotoTransTargetObject.Type.Light);
  34. this.UpdateChildren();
  35. this.DirectionalLightWindow.SetLightWindow(this);
  36. this.DirectionalLightWindow.Init(new Action(this.UpdateButtonInfo));
  37. }
  38. public void OnDestroy()
  39. {
  40. if (GameMain.Instance == null || GameMain.Instance.BgMgr == null || GameMain.Instance.BgMgr.bg_parent_object == null)
  41. {
  42. return;
  43. }
  44. Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
  45. if (transform != null)
  46. {
  47. UnityEngine.Object.DestroyImmediate(transform.gameObject);
  48. }
  49. }
  50. public void OnSelectItem(PhotoTransTargetObject select)
  51. {
  52. if (this.selectObject != null && this.selectObject.obj != null && this.selectObject.axis_obj != null && this.selectObject.rotate_obj != null)
  53. {
  54. this.selectObject.axis_obj.Visible = (this.selectObject.rotate_obj.Visible = false);
  55. }
  56. this.selectObject = select;
  57. if (select == null)
  58. {
  59. return;
  60. }
  61. if (select.obj == null)
  62. {
  63. this.directionalLightProp.SetActive(true);
  64. this.UserLightProp.SetActive(false);
  65. WFCheckBox wfcheckBox = this.checkBoxPoint;
  66. bool check = false;
  67. this.checkBoxSpot.check = check;
  68. wfcheckBox.check = check;
  69. this.DirectionalLightWindow.UpdateGui();
  70. }
  71. else
  72. {
  73. Light componentInChildren = select.obj.GetComponentInChildren<Light>(false);
  74. if (componentInChildren == null)
  75. {
  76. Debug.LogError("Light設定がnullです");
  77. return;
  78. }
  79. this.checkBoxVisible.check = componentInChildren.enabled;
  80. this.directionalLightProp.SetActive(false);
  81. this.UserLightProp.SetActive(true);
  82. if (componentInChildren.type == LightType.Point)
  83. {
  84. UTY.GetChildObject(this.UserLightProp, "Point", false).SetActive(true);
  85. UTY.GetChildObject(this.UserLightProp, "Spot", false).SetActive(false);
  86. this.checkBoxPoint.check = true;
  87. this.checkBoxSpot.check = false;
  88. this.pointLightWindow.Init(componentInChildren, select, new Action(this.UpdateButtonInfo));
  89. }
  90. else
  91. {
  92. UTY.GetChildObject(this.UserLightProp, "Point", false).SetActive(false);
  93. UTY.GetChildObject(this.UserLightProp, "Spot", false).SetActive(true);
  94. this.checkBoxPoint.check = false;
  95. this.checkBoxSpot.check = true;
  96. this.spotLightWindow.Init(componentInChildren, select, new Action(this.UpdateButtonInfo));
  97. }
  98. }
  99. this.UpdateButtonInfo();
  100. }
  101. public void OnClickAddButton()
  102. {
  103. this.AddTransTargetObject(this.InstantiateLight(), "◆", PhotoTransTargetObject.Type.Light);
  104. }
  105. public void OnClickRemoveButton()
  106. {
  107. if (this.selectObject == null)
  108. {
  109. return;
  110. }
  111. this.RemoveTransTargetObject(this.selectObject.obj);
  112. }
  113. public void OnClickCheckBoxVisible(WFCheckBox checkbox)
  114. {
  115. if (this.selectObject == null || this.selectObject.obj == null)
  116. {
  117. return;
  118. }
  119. Light[] componentsInChildren = this.selectObject.obj.GetComponentsInChildren<Light>(true);
  120. foreach (Light light in componentsInChildren)
  121. {
  122. light.enabled = checkbox.check;
  123. }
  124. this.UpdateButtonInfo();
  125. }
  126. public void OnClickCheckBoxSwitching(WFCheckBox checkbox)
  127. {
  128. if (this.selectObject == null || this.selectObject.obj == null)
  129. {
  130. return;
  131. }
  132. if (checkbox == this.checkBoxPoint)
  133. {
  134. this.checkBoxSpot.check = !checkbox.check;
  135. }
  136. else
  137. {
  138. this.checkBoxPoint.check = !checkbox.check;
  139. }
  140. if (this.checkBoxSpot.check)
  141. {
  142. UTY.GetChildObject(this.selectObject.obj, "LightPoint", false).SetActive(false);
  143. UTY.GetChildObject(this.selectObject.obj, "LightSpot", false).SetActive(true);
  144. }
  145. else
  146. {
  147. UTY.GetChildObject(this.selectObject.obj, "LightPoint", false).SetActive(true);
  148. UTY.GetChildObject(this.selectObject.obj, "LightSpot", false).SetActive(false);
  149. }
  150. this.OnSelectItem(this.selectObject);
  151. }
  152. public void OnClickCameraFocus()
  153. {
  154. if (this.selectObject == null || this.selectObject.obj == null)
  155. {
  156. return;
  157. }
  158. Vector3 position = this.selectObject.obj.transform.position;
  159. float distance = 4f;
  160. Vector2 aroundAngle = new Vector2(-180f, 4.7f);
  161. this.cameraMoveSupport.StartCameraPosition(position, distance, aroundAngle);
  162. }
  163. public override void OnSerializeEvent()
  164. {
  165. Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
  166. woldStoreData.Clear();
  167. this.DirectionalLightWindow.OnSerializeEvent();
  168. for (int i = 1; i < this.targetList.Count; i++)
  169. {
  170. Dictionary<string, string> dictionary = new Dictionary<string, string>();
  171. PhotoTransTargetObject photoTransTargetObject = this.targetList[i];
  172. Transform transform = photoTransTargetObject.obj.transform;
  173. Light componentInChildren = photoTransTargetObject.obj.GetComponentInChildren<Light>(false);
  174. LightType type = componentInChildren.type;
  175. dictionary["light_type"] = type.ToString();
  176. dictionary["visible"] = componentInChildren.enabled.ToString();
  177. dictionary["position"] = transform.position.ToString("G9");
  178. dictionary["rotation"] = transform.rotation.ToString("G9");
  179. dictionary["color"] = componentInChildren.color.ToString("G9");
  180. dictionary["intensity"] = componentInChildren.intensity.ToString("G9");
  181. dictionary["range"] = componentInChildren.range.ToString("G9");
  182. if (type == LightType.Spot)
  183. {
  184. dictionary["spot_angle"] = componentInChildren.spotAngle.ToString("G9");
  185. }
  186. woldStoreData.Add(i.ToString(), dictionary);
  187. }
  188. }
  189. public override void OnDeserializeEvent()
  190. {
  191. this.DirectionalLightWindow.OnDeserializeEvent();
  192. Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
  193. if (woldStoreData.Count != this.targetList.Count)
  194. {
  195. Debug.LogError("ライトのセーブデータ数が一致していません");
  196. }
  197. int num = 1;
  198. while (woldStoreData.ContainsKey(num.ToString()))
  199. {
  200. Dictionary<string, string> dictionary = woldStoreData[num.ToString()];
  201. Transform transform = this.targetList[num].obj.transform;
  202. if ((LightType)Enum.Parse(typeof(LightType), dictionary["light_type"]) == LightType.Spot)
  203. {
  204. UTY.GetChildObject(transform.gameObject, "LightPoint", false).SetActive(false);
  205. UTY.GetChildObject(transform.gameObject, "LightSpot", false).SetActive(true);
  206. }
  207. else
  208. {
  209. UTY.GetChildObject(transform.gameObject, "LightPoint", false).SetActive(true);
  210. UTY.GetChildObject(transform.gameObject, "LightSpot", false).SetActive(false);
  211. }
  212. Light componentInChildren = this.targetList[num].obj.GetComponentInChildren<Light>(false);
  213. componentInChildren.enabled = bool.Parse(dictionary["visible"]);
  214. transform.position = Parse.Vector3(dictionary["position"]);
  215. transform.rotation = Parse.Quaternion(dictionary["rotation"]);
  216. componentInChildren.color = Parse.Color(dictionary["color"]);
  217. componentInChildren.intensity = float.Parse(dictionary["intensity"]);
  218. componentInChildren.range = float.Parse(dictionary["range"]);
  219. if (componentInChildren.type == LightType.Spot)
  220. {
  221. componentInChildren.spotAngle = float.Parse(dictionary["spot_angle"]);
  222. }
  223. num++;
  224. }
  225. this.UpdateButtonInfo();
  226. this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponentInChildren<UIWFTabButton>());
  227. }
  228. public void UpdateButtonInfo()
  229. {
  230. foreach (Transform transform in this.contentGrid.GetChildList())
  231. {
  232. PhotoTransTargetObject photoTransTargetObject = null;
  233. foreach (PhotoTransTargetObject photoTransTargetObject2 in this.targetList)
  234. {
  235. if (photoTransTargetObject2.guid == transform.gameObject.name)
  236. {
  237. photoTransTargetObject = photoTransTargetObject2;
  238. break;
  239. }
  240. }
  241. if (photoTransTargetObject != null)
  242. {
  243. Light light = GameMain.Instance.MainLight.GetComponent<Light>();
  244. if (photoTransTargetObject.obj != null)
  245. {
  246. light = photoTransTargetObject.obj.GetComponentInChildren<Light>();
  247. }
  248. if (!(light == null))
  249. {
  250. UILabel componentInChildren = transform.GetComponentInChildren<UILabel>();
  251. if (componentInChildren != null && light.type != LightType.Directional)
  252. {
  253. string text = componentInChildren.text;
  254. text = text.Replace("ポイントライト", "◆").Replace("スポットライト", "◆");
  255. componentInChildren.text = text.Replace("◆", (light.type != LightType.Point) ? "スポットライト" : "ポイントライト");
  256. }
  257. UISprite component = UTY.GetChildObject(transform.gameObject, "Plate/FrameThumbnail", false).GetComponent<UISprite>();
  258. if (light.type == LightType.Directional)
  259. {
  260. component.spriteName = "photo_icon_light_d";
  261. }
  262. else if (light.type == LightType.Spot)
  263. {
  264. component.spriteName = "photo_icon_light_spot";
  265. }
  266. else if (light.type == LightType.Point)
  267. {
  268. component.spriteName = "photo_icon_light_point";
  269. }
  270. Color color = light.color;
  271. color.a = ((!light.enabled) ? 0.2f : 1f);
  272. component.color = color;
  273. }
  274. }
  275. }
  276. }
  277. public void AddTransTargetObject(GameObject target_obj, string draw_name, PhotoTransTargetObject.Type type)
  278. {
  279. if (target_obj == null)
  280. {
  281. return;
  282. }
  283. PhotoTransTargetObject photoTransTargetObject = new PhotoTransTargetObject(target_obj, draw_name, type, Vector2.one);
  284. this.targetList.Add(photoTransTargetObject);
  285. UIWFTabButton uiwftabButton = this.CreateTabButton(this.contentGrid.gameObject, photoTransTargetObject);
  286. UIEventTrigger[] componentsInChildren = uiwftabButton.gameObject.GetComponentsInChildren<UIEventTrigger>();
  287. List<EventDelegate> onPress = this.contentGrid.GetChild(0).GetComponentInChildren<UIEventTrigger>().onPress;
  288. for (int i = 0; i < componentsInChildren.Length; i++)
  289. {
  290. componentsInChildren[i].onPress = onPress;
  291. }
  292. Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
  293. List<Transform> childList = this.contentGrid.GetChildList();
  294. for (int j = 0; j < childList.Count; j++)
  295. {
  296. dictionary.Add(childList[j].name, childList[j].transform);
  297. }
  298. for (int k = 0; k < this.targetList.Count; k++)
  299. {
  300. if (dictionary.ContainsKey(this.targetList[k].guid))
  301. {
  302. dictionary[this.targetList[k].guid].localPosition = new Vector3(0f, (float)(k * 10), 0f);
  303. }
  304. }
  305. this.tabPanel.UpdateChildren();
  306. this.contentGrid.Reposition();
  307. this.scrollView.UpdatePosition();
  308. }
  309. public void RemoveTransTargetObject(GameObject target_obj)
  310. {
  311. if (target_obj == null)
  312. {
  313. return;
  314. }
  315. UIWFTabButton selectButtonObject = this.tabPanel.GetSelectButtonObject();
  316. string text = string.Empty;
  317. for (int i = 0; i < this.targetList.Count; i++)
  318. {
  319. if (this.targetList[i].obj == target_obj)
  320. {
  321. text = this.targetList[i].guid;
  322. this.targetList[i].Delete();
  323. this.targetList.RemoveAt(i);
  324. this.DeletedLight(target_obj);
  325. break;
  326. }
  327. }
  328. if (!string.IsNullOrEmpty(text))
  329. {
  330. if (selectButtonObject != null && selectButtonObject.name == text)
  331. {
  332. this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
  333. }
  334. List<Transform> childList = this.contentGrid.GetChildList();
  335. for (int j = 0; j < childList.Count; j++)
  336. {
  337. if (childList[j].gameObject.name == text)
  338. {
  339. childList[j].gameObject.transform.SetParent(null, false);
  340. UnityEngine.Object.Destroy(childList[j].gameObject);
  341. }
  342. }
  343. int num = 5;
  344. Utility.ResetNGUI(this.contentGrid);
  345. if (this.contentGrid.GetChildList().Count <= num)
  346. {
  347. Utility.ResetNGUI(this.scrollView);
  348. }
  349. else
  350. {
  351. this.scrollView.UpdatePosition();
  352. this.scrollView.UpdateScrollbars();
  353. }
  354. this.tabPanel.UpdateChildren();
  355. }
  356. }
  357. public Dictionary<string, Dictionary<string, string>> GetStoreData()
  358. {
  359. return base.mgr.GetWoldStoreData(this);
  360. }
  361. private UIWFTabButton CreateTabButton(GameObject parent_obj, PhotoTransTargetObject target)
  362. {
  363. GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowsListItemLight", true);
  364. gameObject.name = target.guid.ToString();
  365. gameObject.GetComponentInChildren<UILabel>().text = target.draw_name;
  366. UIWFTabButton componentInChildren = gameObject.GetComponentInChildren<UIWFTabButton>();
  367. EventDelegate.Add(componentInChildren.onSelect, delegate()
  368. {
  369. if (!UIWFSelectButton.current.isSelected)
  370. {
  371. return;
  372. }
  373. for (int i = 0; i < this.targetList.Count; i++)
  374. {
  375. if (this.targetList[i].guid == UIWFSelectButton.current.name)
  376. {
  377. this.OnSelectItem(this.targetList[i]);
  378. break;
  379. }
  380. }
  381. });
  382. return componentInChildren;
  383. }
  384. private GameObject InstantiateLight()
  385. {
  386. Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
  387. if (transform == null)
  388. {
  389. GameObject gameObject = new GameObject("LightObject");
  390. gameObject.transform.SetParent(GameMain.Instance.BgMgr.bg_parent_object.transform, false);
  391. transform = gameObject.transform;
  392. }
  393. GameObject gameObject2 = new GameObject();
  394. if (!string.IsNullOrEmpty(base.name))
  395. {
  396. gameObject2.name = Guid.NewGuid().ToString();
  397. }
  398. gameObject2.transform.SetParent(transform, false);
  399. gameObject2.transform.localPosition = new Vector3(0f, 1f, 0f);
  400. GameObject gameObject3 = new GameObject();
  401. gameObject3.name = "LightPoint";
  402. Light light = gameObject3.AddComponent<Light>();
  403. light.type = LightType.Point;
  404. light.range = 5f;
  405. light.enabled = false;
  406. gameObject3.transform.SetParent(gameObject2.transform, false);
  407. GameObject gameObject4 = new GameObject();
  408. gameObject4.name = "LightSpot";
  409. gameObject4.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
  410. light = gameObject4.AddComponent<Light>();
  411. light.type = LightType.Spot;
  412. light.enabled = false;
  413. light.range = 3f;
  414. light.intensity = 5f;
  415. light.spotAngle = 30f;
  416. gameObject4.transform.SetParent(gameObject2.transform, false);
  417. gameObject3.SetActive(true);
  418. gameObject4.SetActive(false);
  419. return gameObject2;
  420. }
  421. private bool DeletedLight(GameObject obj)
  422. {
  423. Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
  424. if (transform == null)
  425. {
  426. return false;
  427. }
  428. for (int i = 0; i < transform.childCount; i++)
  429. {
  430. if (obj == transform.GetChild(i).gameObject)
  431. {
  432. UnityEngine.Object.DestroyImmediate(obj);
  433. return true;
  434. }
  435. }
  436. return false;
  437. }
  438. [SerializeField]
  439. private UIGrid contentGrid;
  440. [SerializeField]
  441. private UIButton addBtn;
  442. [SerializeField]
  443. private UIButton removeBtn;
  444. [SerializeField]
  445. private UIButton cameraFocusBtn;
  446. [SerializeField]
  447. private GameObject directionalLightProp;
  448. [SerializeField]
  449. private GameObject UserLightProp;
  450. [SerializeField]
  451. private WFCheckBox checkBoxVisible;
  452. [SerializeField]
  453. private WFCheckBox checkBoxPoint;
  454. [SerializeField]
  455. private WFCheckBox checkBoxSpot;
  456. [SerializeField]
  457. private WindowPartsPointLight pointLightWindow;
  458. [SerializeField]
  459. private WindowPartsSpotLight spotLightWindow;
  460. public WindowPartsDirectionalLight DirectionalLightWindow;
  461. private UIWFTabPanel tabPanel;
  462. private WfCameraMoveSupport cameraMoveSupport;
  463. private UIScrollView scrollView;
  464. private PhotoTransTargetObject selectObject;
  465. private List<PhotoTransTargetObject> targetList = new List<PhotoTransTargetObject>();
  466. }