LightWindow.cs 17 KB

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