123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- using System;
- using System.Collections.Generic;
- using I2.Loc;
- using UnityEngine;
- using wf;
- public class LightWindow : BaseMaidPhotoWindow
- {
- public override void Awake()
- {
- base.Awake();
- this.tabPanel = this.contentGrid.GetComponent<UIWFTabPanel>();
- EventDelegate.Add(this.addBtn.onClick, new EventDelegate.Callback(this.OnClickAddButton));
- EventDelegate.Add(this.removeBtn.onClick, new EventDelegate.Callback(this.OnClickRemoveButton));
- this.checkBoxVisible.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxVisible));
- this.checkBoxPoint.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxSwitching));
- this.checkBoxSpot.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxSwitching));
- this.cameraMoveSupport = base.gameObject.AddComponent<WfCameraMoveSupport>();
- EventDelegate.Add(this.cameraFocusBtn.onClick, new EventDelegate.Callback(this.OnClickCameraFocus));
- this.scrollView = NGUITools.FindInParents<UIScrollView>(this.contentGrid.transform);
- this.targetList.Add(new PhotoTransTargetObject(null, "メインライト", "ScenePhotoMode/ライト/メインライト", PhotoTransTargetObject.Type.Maid, Vector2.one));
- this.CreateTabButton(this.contentGrid.gameObject, this.targetList[0]);
- this.tabPanel.UpdateChildren();
- this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponentInChildren<UIWFTabButton>());
- Utility.ResetNGUI(this.contentGrid);
- Utility.ResetNGUI(this.scrollView);
- this.UpdateChildren();
- }
- public override void Start()
- {
- base.Start();
- this.AddTransTargetObject(this.InstantiateLight(), "1 : ポイントライト", "ScenePhotoMode/ライト/1 : ポイントライト", PhotoTransTargetObject.Type.Light);
- this.AddTransTargetObject(this.InstantiateLight(), "2 : ポイントライト", "ScenePhotoMode/ライト/2 : ポイントライト", PhotoTransTargetObject.Type.Light);
- this.AddTransTargetObject(this.InstantiateLight(), "3 : ポイントライト", "ScenePhotoMode/ライト/3 : ポイントライト", PhotoTransTargetObject.Type.Light);
- this.AddTransTargetObject(this.InstantiateLight(), "4 : ポイントライト", "ScenePhotoMode/ライト/4 : ポイントライト", PhotoTransTargetObject.Type.Light);
- this.UpdateChildren();
- this.DirectionalLightWindow.SetLightWindow(this);
- this.DirectionalLightWindow.Init(new Action(this.UpdateButtonInfo));
- }
- public void OnDestroy()
- {
- if (GameMain.Instance == null || GameMain.Instance.BgMgr == null || GameMain.Instance.BgMgr.bg_parent_object == null)
- {
- return;
- }
- Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
- if (transform != null)
- {
- UnityEngine.Object.DestroyImmediate(transform.gameObject);
- }
- }
- public void OnSelectItem(PhotoTransTargetObject select)
- {
- if (this.selectObject != null && this.selectObject.obj != null && this.selectObject.axis_obj != null && this.selectObject.rotate_obj != null)
- {
- this.selectObject.axis_obj.Visible = (this.selectObject.rotate_obj.Visible = false);
- }
- this.selectObject = select;
- if (select == null)
- {
- return;
- }
- if (select.obj == null)
- {
- this.directionalLightProp.SetActive(true);
- this.UserLightProp.SetActive(false);
- WFCheckBox wfcheckBox = this.checkBoxPoint;
- bool check = false;
- this.checkBoxSpot.check = check;
- wfcheckBox.check = check;
- this.DirectionalLightWindow.UpdateGui();
- }
- else
- {
- Light componentInChildren = select.obj.GetComponentInChildren<Light>(false);
- if (componentInChildren == null)
- {
- Debug.LogError("Light設定がnullです");
- return;
- }
- this.checkBoxVisible.check = componentInChildren.enabled;
- this.directionalLightProp.SetActive(false);
- this.UserLightProp.SetActive(true);
- if (componentInChildren.type == LightType.Point)
- {
- UTY.GetChildObject(this.UserLightProp, "Point", false).SetActive(true);
- UTY.GetChildObject(this.UserLightProp, "Spot", false).SetActive(false);
- this.checkBoxPoint.check = true;
- this.checkBoxSpot.check = false;
- this.pointLightWindow.Init(componentInChildren, select, new Action(this.UpdateButtonInfo));
- }
- else
- {
- UTY.GetChildObject(this.UserLightProp, "Point", false).SetActive(false);
- UTY.GetChildObject(this.UserLightProp, "Spot", false).SetActive(true);
- this.checkBoxPoint.check = false;
- this.checkBoxSpot.check = true;
- this.spotLightWindow.Init(componentInChildren, select, new Action(this.UpdateButtonInfo));
- }
- }
- this.UpdateButtonInfo();
- }
- public void OnClickAddButton()
- {
- this.AddTransTargetObject(this.InstantiateLight(), "◆", string.Empty, PhotoTransTargetObject.Type.Light);
- }
- public void OnClickRemoveButton()
- {
- if (this.selectObject == null)
- {
- return;
- }
- this.RemoveTransTargetObject(this.selectObject.obj);
- }
- public void OnClickCheckBoxVisible(WFCheckBox checkbox)
- {
- if (this.selectObject == null || this.selectObject.obj == null)
- {
- return;
- }
- Light[] componentsInChildren = this.selectObject.obj.GetComponentsInChildren<Light>(true);
- foreach (Light light in componentsInChildren)
- {
- light.enabled = checkbox.check;
- }
- this.UpdateButtonInfo();
- }
- public void OnClickCheckBoxSwitching(WFCheckBox checkbox)
- {
- if (this.selectObject == null || this.selectObject.obj == null)
- {
- return;
- }
- if (checkbox == this.checkBoxPoint)
- {
- this.checkBoxSpot.check = !checkbox.check;
- }
- else
- {
- this.checkBoxPoint.check = !checkbox.check;
- }
- if (this.checkBoxSpot.check)
- {
- UTY.GetChildObject(this.selectObject.obj, "LightPoint", false).SetActive(false);
- UTY.GetChildObject(this.selectObject.obj, "LightSpot", false).SetActive(true);
- }
- else
- {
- UTY.GetChildObject(this.selectObject.obj, "LightPoint", false).SetActive(true);
- UTY.GetChildObject(this.selectObject.obj, "LightSpot", false).SetActive(false);
- }
- this.OnSelectItem(this.selectObject);
- }
- public void OnClickCameraFocus()
- {
- if (this.selectObject == null || this.selectObject.obj == null)
- {
- return;
- }
- Vector3 position = this.selectObject.obj.transform.position;
- float distance = 4f;
- Vector2 aroundAngle = new Vector2(-180f, 4.7f);
- this.cameraMoveSupport.StartCameraPosition(position, distance, aroundAngle);
- }
- public override void OnSerializeEvent()
- {
- Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
- woldStoreData.Clear();
- this.DirectionalLightWindow.OnSerializeEvent();
- for (int i = 1; i < this.targetList.Count; i++)
- {
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- PhotoTransTargetObject photoTransTargetObject = this.targetList[i];
- Transform transform = photoTransTargetObject.obj.transform;
- Light componentInChildren = photoTransTargetObject.obj.GetComponentInChildren<Light>(false);
- LightType type = componentInChildren.type;
- dictionary["light_type"] = type.ToString();
- dictionary["visible"] = componentInChildren.enabled.ToString();
- dictionary["position"] = transform.position.ToString("G9");
- dictionary["rotation"] = transform.rotation.ToString("G9");
- dictionary["color"] = componentInChildren.color.ToString("G9");
- dictionary["intensity"] = componentInChildren.intensity.ToString("G9");
- dictionary["range"] = componentInChildren.range.ToString("G9");
- if (type == LightType.Spot)
- {
- dictionary["spot_angle"] = componentInChildren.spotAngle.ToString("G9");
- }
- woldStoreData.Add(i.ToString(), dictionary);
- }
- }
- public override void OnDeserializeEvent()
- {
- this.DirectionalLightWindow.OnDeserializeEvent();
- Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
- if (woldStoreData.Count != this.targetList.Count)
- {
- Debug.LogError("ライトのセーブデータ数が一致していません");
- }
- int num = 1;
- while (woldStoreData.ContainsKey(num.ToString()))
- {
- Dictionary<string, string> dictionary = woldStoreData[num.ToString()];
- Transform transform = this.targetList[num].obj.transform;
- if ((LightType)Enum.Parse(typeof(LightType), dictionary["light_type"]) == LightType.Spot)
- {
- UTY.GetChildObject(transform.gameObject, "LightPoint", false).SetActive(false);
- UTY.GetChildObject(transform.gameObject, "LightSpot", false).SetActive(true);
- }
- else
- {
- UTY.GetChildObject(transform.gameObject, "LightPoint", false).SetActive(true);
- UTY.GetChildObject(transform.gameObject, "LightSpot", false).SetActive(false);
- }
- Light componentInChildren = this.targetList[num].obj.GetComponentInChildren<Light>(false);
- componentInChildren.enabled = bool.Parse(dictionary["visible"]);
- transform.position = Parse.Vector3(dictionary["position"]);
- transform.rotation = Parse.Quaternion(dictionary["rotation"]);
- componentInChildren.color = Parse.Color(dictionary["color"]);
- componentInChildren.intensity = float.Parse(dictionary["intensity"]);
- componentInChildren.range = float.Parse(dictionary["range"]);
- if (componentInChildren.type == LightType.Spot)
- {
- componentInChildren.spotAngle = float.Parse(dictionary["spot_angle"]);
- }
- num++;
- }
- this.UpdateButtonInfo();
- this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponentInChildren<UIWFTabButton>());
- }
- public void UpdateButtonInfo()
- {
- foreach (Transform transform in this.contentGrid.GetChildList())
- {
- PhotoTransTargetObject photoTransTargetObject = null;
- foreach (PhotoTransTargetObject photoTransTargetObject2 in this.targetList)
- {
- if (photoTransTargetObject2.guid == transform.gameObject.name)
- {
- photoTransTargetObject = photoTransTargetObject2;
- break;
- }
- }
- if (photoTransTargetObject != null)
- {
- Light light = GameMain.Instance.MainLight.GetComponent<Light>();
- if (photoTransTargetObject.obj != null)
- {
- light = photoTransTargetObject.obj.GetComponentInChildren<Light>();
- }
- if (!(light == null))
- {
- UILabel componentInChildren = transform.GetComponentInChildren<UILabel>();
- if (componentInChildren != null && light.type != LightType.Directional)
- {
- string text = componentInChildren.text;
- Localize component = componentInChildren.GetComponent<Localize>();
- if (component != null)
- {
- text = component.Term;
- text = text.Replace("ポイントライト", "◆").Replace("スポットライト", "◆");
- text = text.Replace("◆", (light.type != LightType.Point) ? "スポットライト" : "ポイントライト");
- component.SetTerm(text);
- }
- else
- {
- text = text.Replace("ポイントライト", "◆").Replace("スポットライト", "◆");
- componentInChildren.text = text.Replace("◆", (light.type != LightType.Point) ? "スポットライト" : "ポイントライト");
- }
- }
- UISprite component2 = UTY.GetChildObject(transform.gameObject, "Plate/FrameThumbnail", false).GetComponent<UISprite>();
- if (light.type == LightType.Directional)
- {
- component2.spriteName = "photo_icon_light_d";
- }
- else if (light.type == LightType.Spot)
- {
- component2.spriteName = "photo_icon_light_spot";
- }
- else if (light.type == LightType.Point)
- {
- component2.spriteName = "photo_icon_light_point";
- }
- Color color = light.color;
- color.a = ((!light.enabled) ? 0.2f : 1f);
- component2.color = color;
- }
- }
- }
- }
- public void AddTransTargetObject(GameObject target_obj, string draw_name, string termName, PhotoTransTargetObject.Type type)
- {
- if (target_obj == null)
- {
- return;
- }
- PhotoTransTargetObject photoTransTargetObject = new PhotoTransTargetObject(target_obj, draw_name, termName, type, Vector2.one);
- this.targetList.Add(photoTransTargetObject);
- UIWFTabButton uiwftabButton = this.CreateTabButton(this.contentGrid.gameObject, photoTransTargetObject);
- UIEventTrigger[] componentsInChildren = uiwftabButton.gameObject.GetComponentsInChildren<UIEventTrigger>();
- List<EventDelegate> onPress = this.contentGrid.GetChild(0).GetComponentInChildren<UIEventTrigger>().onPress;
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].onPress = onPress;
- }
- Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
- List<Transform> childList = this.contentGrid.GetChildList();
- for (int j = 0; j < childList.Count; j++)
- {
- dictionary.Add(childList[j].name, childList[j].transform);
- }
- for (int k = 0; k < this.targetList.Count; k++)
- {
- if (dictionary.ContainsKey(this.targetList[k].guid))
- {
- dictionary[this.targetList[k].guid].localPosition = new Vector3(0f, (float)(k * 10), 0f);
- }
- }
- this.tabPanel.UpdateChildren();
- this.contentGrid.Reposition();
- this.scrollView.UpdatePosition();
- }
- public void RemoveTransTargetObject(GameObject target_obj)
- {
- if (target_obj == null)
- {
- return;
- }
- UIWFTabButton selectButtonObject = this.tabPanel.GetSelectButtonObject();
- string text = string.Empty;
- for (int i = 0; i < this.targetList.Count; i++)
- {
- if (this.targetList[i].obj == target_obj)
- {
- text = this.targetList[i].guid;
- this.targetList[i].Delete();
- this.targetList.RemoveAt(i);
- this.DeletedLight(target_obj);
- break;
- }
- }
- if (!string.IsNullOrEmpty(text))
- {
- if (selectButtonObject != null && selectButtonObject.name == text)
- {
- this.tabPanel.Select(this.contentGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
- }
- List<Transform> childList = this.contentGrid.GetChildList();
- for (int j = 0; j < childList.Count; j++)
- {
- if (childList[j].gameObject.name == text)
- {
- childList[j].gameObject.transform.SetParent(null, false);
- UnityEngine.Object.Destroy(childList[j].gameObject);
- }
- }
- int num = 5;
- Utility.ResetNGUI(this.contentGrid);
- if (this.contentGrid.GetChildList().Count <= num)
- {
- Utility.ResetNGUI(this.scrollView);
- }
- else
- {
- this.scrollView.UpdatePosition();
- this.scrollView.UpdateScrollbars();
- }
- this.tabPanel.UpdateChildren();
- }
- }
- public Dictionary<string, Dictionary<string, string>> GetStoreData()
- {
- return base.mgr.GetWoldStoreData(this);
- }
- private UIWFTabButton CreateTabButton(GameObject parent_obj, PhotoTransTargetObject target)
- {
- GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowsListItemLight", true);
- gameObject.name = target.guid.ToString();
- gameObject.GetComponentInChildren<UILabel>().text = target.draw_name;
- Localize componentInChildren = gameObject.GetComponentInChildren<Localize>();
- if (componentInChildren != null)
- {
- componentInChildren.SetTerm(target.nameTerm);
- }
- UIWFTabButton componentInChildren2 = gameObject.GetComponentInChildren<UIWFTabButton>();
- EventDelegate.Add(componentInChildren2.onSelect, delegate()
- {
- if (!UIWFSelectButton.current.isSelected)
- {
- return;
- }
- for (int i = 0; i < this.targetList.Count; i++)
- {
- if (this.targetList[i].guid == UIWFSelectButton.current.name)
- {
- this.OnSelectItem(this.targetList[i]);
- break;
- }
- }
- });
- return componentInChildren2;
- }
- private GameObject InstantiateLight()
- {
- Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
- if (transform == null)
- {
- GameObject gameObject = new GameObject("LightObject");
- gameObject.transform.SetParent(GameMain.Instance.BgMgr.bg_parent_object.transform, false);
- transform = gameObject.transform;
- }
- GameObject gameObject2 = new GameObject();
- if (!string.IsNullOrEmpty(base.name))
- {
- gameObject2.name = Guid.NewGuid().ToString();
- }
- gameObject2.transform.SetParent(transform, false);
- gameObject2.transform.localPosition = new Vector3(0f, 1f, 0f);
- GameObject gameObject3 = new GameObject();
- gameObject3.name = "LightPoint";
- Light light = gameObject3.AddComponent<Light>();
- light.type = LightType.Point;
- light.range = 5f;
- light.enabled = false;
- gameObject3.transform.SetParent(gameObject2.transform, false);
- GameObject gameObject4 = new GameObject();
- gameObject4.name = "LightSpot";
- gameObject4.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
- light = gameObject4.AddComponent<Light>();
- light.type = LightType.Spot;
- light.enabled = false;
- light.range = 3f;
- light.intensity = 5f;
- light.spotAngle = 30f;
- gameObject4.transform.SetParent(gameObject2.transform, false);
- gameObject3.SetActive(true);
- gameObject4.SetActive(false);
- return gameObject2;
- }
- private bool DeletedLight(GameObject obj)
- {
- Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("LightObject");
- if (transform == null)
- {
- return false;
- }
- for (int i = 0; i < transform.childCount; i++)
- {
- if (obj == transform.GetChild(i).gameObject)
- {
- UnityEngine.Object.DestroyImmediate(obj);
- return true;
- }
- }
- return false;
- }
- [SerializeField]
- private UIGrid contentGrid;
- [SerializeField]
- private UIButton addBtn;
- [SerializeField]
- private UIButton removeBtn;
- [SerializeField]
- private UIButton cameraFocusBtn;
- [SerializeField]
- private GameObject directionalLightProp;
- [SerializeField]
- private GameObject UserLightProp;
- [SerializeField]
- private WFCheckBox checkBoxVisible;
- [SerializeField]
- private WFCheckBox checkBoxPoint;
- [SerializeField]
- private WFCheckBox checkBoxSpot;
- [SerializeField]
- private WindowPartsPointLight pointLightWindow;
- [SerializeField]
- private WindowPartsSpotLight spotLightWindow;
- public WindowPartsDirectionalLight DirectionalLightWindow;
- private UIWFTabPanel tabPanel;
- private WfCameraMoveSupport cameraMoveSupport;
- private UIScrollView scrollView;
- private PhotoTransTargetObject selectObject;
- private List<PhotoTransTargetObject> targetList = new List<PhotoTransTargetObject>();
- }
|