123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public abstract class BasePhotoWindow : MonoBehaviour
- {
- public void ResizeWindow()
- {
- int num = (int)this.WindowSize.x;
- int num2 = (int)this.WindowSize.y;
- this.WindowSize.x = (float)num;
- this.WindowSize.y = (float)num2;
- UTY.GetChildObject(base.gameObject, "Parent", false).GetComponent<BoxCollider>().size = new Vector3((float)num, (float)num2, 1f);
- UTY.GetChildObject(base.gameObject, "Parent", false).GetComponent<BoxCollider>().center = new Vector3((float)(num - 200) / 2f, (float)(num2 - 200) / -2f, 1f);
- UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>().width = num;
- UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>().height = num2;
- UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>().width = num;
- UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>().height = num2 - 20;
- UTY.GetChildObject(base.gameObject, "Parent/BG2", false).transform.localPosition = new Vector3(-100f, (float)((num2 - 100) * -1), 0f);
- UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar", false).GetComponent<UIWidget>().width = num;
- UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar/Btn", false).transform.localPosition = new Vector3((float)(num - 10), -10f, 0f);
- (this.windowTitle = UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar/Text", false).GetComponent<UILabel>()).text = this.InitTitle;
- }
- public virtual void SetWindowTitle(string title)
- {
- this.windowTitle.text = title;
- }
- public virtual void Awake()
- {
- GameObject gameObject = GameObject.Find("/UI Root");
- NDebug.Assert(gameObject != null, "BasePhotoWindow\nRootを見つけられませんでした");
- this.uiCamera = gameObject.GetComponent<UIRoot>().GetComponentInChildren<Camera>();
- this.ResizeWindow();
- base.transform.parent.GetComponent<BasePhotoWindowManager>().Reset();
- this.bgWidget = UTY.GetChildObject(base.gameObject, "Parent/BG", false).GetComponent<UIWidget>();
- this.bgWidget2 = UTY.GetChildObject(base.gameObject, "Parent/BG2", false).GetComponent<UIWidget>();
- this.content_game_object_ = UTY.GetChildObject(base.gameObject, "Parent/ContentParent", false);
- GameObject childObject = UTY.GetChildObject(base.gameObject, "Parent/BG/TitleBar", false);
- if (this.panel_ == null)
- {
- this.panel_ = base.GetComponentInChildren<UIPanel>();
- }
- this.title_bar_label_ = UTY.GetChildObject(childObject, "Text", false).GetComponent<UILabel>();
- Dictionary<BasePhotoWindow.BtnType, string> dictionary = new Dictionary<BasePhotoWindow.BtnType, string>();
- dictionary.Add(BasePhotoWindow.BtnType.Help, "ヘルプ");
- dictionary.Add(BasePhotoWindow.BtnType.Min, "最小化");
- dictionary.Add(BasePhotoWindow.BtnType.Reset, "UI位置初期化");
- dictionary.Add(BasePhotoWindow.BtnType.End, "閉じる");
- this.btn_dic_ = new Dictionary<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>>();
- for (int i = 0; i <= 3; i++)
- {
- BasePhotoWindow.BtnType key = (BasePhotoWindow.BtnType)i;
- this.btn_dic_.Add(key, new KeyValuePair<UIButton, List<Action>>(UTY.GetChildObject(childObject, "Btn/" + key.ToString(), false).GetComponent<UIButton>(), new List<Action>()));
- EventDelegate.Add(this.btn_dic_[key].Key.onClick, new EventDelegate.Callback(this.OnButtonClickEvent));
- this.mini_btn_init_pos_.Add(key, this.btn_dic_[key].Key.transform.localPosition);
- if (dictionary.ContainsKey(key))
- {
- UIButton key2 = this.btn_dic_[key].Key;
- EventDelegate eventDelegate = new EventDelegate(this, "OnBtnMouseHoverIn");
- eventDelegate.parameters[0].value = dictionary[key];
- key2.gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
- EventDelegate.Add(key2.gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
- EventDelegate.Add(key2.gameObject.GetComponent<UIEventTrigger>().onDragStart, new EventDelegate.Callback(this.OnMouseHoverOut));
- }
- }
- this.window_active_delegate_ = new EventDelegate(new EventDelegate.Callback(this.ActiveWindow));
- this.init_pos_ = base.transform.localPosition;
- for (int j = 0; j <= 3; j++)
- {
- this.SetButtonEnabled((BasePhotoWindow.BtnType)j, false, false);
- }
- this.GetButtonOnClickEventList(BasePhotoWindow.BtnType.Reset).Add(delegate
- {
- this.ResetPosition();
- });
- this.SetButtonEnabled(BasePhotoWindow.BtnType.Reset, true, false);
- if (!this.InitVisible)
- {
- this.visible = false;
- }
- if (this.subWindows == null)
- {
- this.subWindows = new BasePhotoSubWindow[0];
- }
- foreach (BasePhotoSubWindow basePhotoSubWindow in this.subWindows)
- {
- basePhotoSubWindow.Initizalize(this);
- }
- }
- public virtual void Start()
- {
- }
- public virtual void OnEnable()
- {
- if (this.visible && !this.IsWindowInTheScreen())
- {
- this.ResetPosition();
- this.panelDirty = 6;
- }
- }
- public virtual void Update()
- {
- if (0 < this.panelDirty)
- {
- this.panelDirty--;
- if (this.panel_ != null && this.panelDirty % 2 == 0)
- {
- UIPanel[] componentsInChildren = base.GetComponentsInChildren<UIPanel>();
- if (componentsInChildren != null)
- {
- foreach (UIPanel uipanel in componentsInChildren)
- {
- uipanel.SetDirty();
- }
- }
- }
- }
- }
- public virtual void UpdateChildren()
- {
- UIEventTrigger[] componentsInChildren = base.GetComponentsInChildren<UIEventTrigger>(true);
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- if (componentsInChildren[i].onPress.IndexOf(this.window_active_delegate_) < 0)
- {
- componentsInChildren[i].onPress.Add(this.window_active_delegate_);
- }
- }
- }
- public virtual void ActiveWindow()
- {
- this.mgr_.ActiveWindow(this);
- }
- public void SetButtonEnabled(BasePhotoWindow.BtnType type, bool enabled, bool force_update = false)
- {
- this.btn_dic_[type].Key.gameObject.SetActive(enabled);
- foreach (KeyValuePair<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> keyValuePair in this.btn_dic_)
- {
- keyValuePair.Value.Key.transform.localPosition = this.mini_btn_init_pos_[keyValuePair.Key];
- }
- UIGrid component = this.btn_dic_[BasePhotoWindow.BtnType.Help].Key.transform.parent.gameObject.GetComponent<UIGrid>();
- if (component != null)
- {
- if (force_update)
- {
- component.Reposition();
- }
- else
- {
- component.repositionNow = true;
- }
- }
- }
- public List<Action> GetButtonOnClickEventList(BasePhotoWindow.BtnType type)
- {
- return this.btn_dic_[type].Value;
- }
- public virtual void OnButtonClickEvent()
- {
- int instanceID = UIButton.current.GetInstanceID();
- foreach (KeyValuePair<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> keyValuePair in this.btn_dic_)
- {
- if (instanceID == keyValuePair.Value.Key.GetInstanceID())
- {
- List<Action> value = keyValuePair.Value.Value;
- for (int i = 0; i < value.Count; i++)
- {
- value[i]();
- }
- }
- }
- }
- public virtual void ResetPosition()
- {
- base.transform.localPosition = this.init_pos_;
- }
- public virtual bool IsWindowInTheScreen()
- {
- if (this.uiCamera == null)
- {
- return true;
- }
- int margin = -30;
- Rect windowRectFromScreenPoint = this.GetWindowRectFromScreenPoint(margin);
- Rect rect = new Rect(0f, 0f, (float)Screen.width, (float)Screen.height);
- windowRectFromScreenPoint.position = new Vector3(windowRectFromScreenPoint.position.x, windowRectFromScreenPoint.y, 0f);
- bool flag = rect.Overlaps(windowRectFromScreenPoint);
- return rect.Overlaps(windowRectFromScreenPoint);
- }
- public virtual void OnActiveChangeWindowEvent(bool is_active)
- {
- }
- public virtual void SetWindowManager(BasePhotoWindowManager mgr)
- {
- this.mgr_ = mgr;
- }
- public string title
- {
- get
- {
- return this.title_bar_label_.text;
- }
- set
- {
- this.title_bar_label_.text = value;
- }
- }
- public int depth
- {
- get
- {
- return this.panel.GetComponentInChildren<UIPanel>().depth / 10;
- }
- set
- {
- int num = value * 10;
- UIPanel[] componentsInChildren = this.panel.gameObject.GetComponentsInChildren<UIPanel>(true);
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].depth = num++;
- }
- }
- }
- public virtual bool baseDraw
- {
- get
- {
- return this.bgWidget.alpha != 0f;
- }
- set
- {
- UIRect uirect = this.bgWidget;
- float alpha = (float)((!value) ? 0 : 1);
- this.bgWidget2.alpha = alpha;
- uirect.alpha = alpha;
- }
- }
- public virtual bool visible
- {
- get
- {
- return this.panel.alpha != 0f;
- }
- set
- {
- this.panel.alpha = (float)((!value) ? 0 : 1);
- if (value && !this.IsWindowInTheScreen())
- {
- this.ResetPosition();
- this.panelDirty = 6;
- }
- }
- }
- public UIPanel panel
- {
- get
- {
- if (this.panel_ == null)
- {
- this.panel_ = base.GetComponentInChildren<UIPanel>();
- }
- return this.panel_;
- }
- }
- public EventDelegate window_active_delegate
- {
- get
- {
- return this.window_active_delegate_;
- }
- }
- public virtual GameObject content_game_object
- {
- get
- {
- return this.content_game_object_;
- }
- }
- public Dictionary<string, Dictionary<string, string>> GetWoldStoreData()
- {
- return this.mgr.GetWoldStoreData(this.windowName);
- }
- public virtual KeyValuePair<string, Dictionary<string, string>> Serialize()
- {
- string key = base.gameObject.name + "title";
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- Vector3 localPosition = base.transform.localPosition;
- dictionary.Add("pos", string.Concat(new string[]
- {
- localPosition.x.ToString("G9"),
- ",",
- localPosition.y.ToString("G9"),
- ",",
- localPosition.z.ToString("G9")
- }));
- dictionary.Add("visible", this.visible.ToString());
- for (int i = 0; i < this.subWindows.Length; i++)
- {
- dictionary.Add(i.ToString() + ":visible", this.subWindows[i].visible.ToString());
- }
- return new KeyValuePair<string, Dictionary<string, string>>(key, dictionary);
- }
- public virtual void Deserialize(Dictionary<string, Dictionary<string, string>> data)
- {
- string key = base.gameObject.name + "title";
- if (!data.ContainsKey(key))
- {
- return;
- }
- Dictionary<string, string> dictionary = data[key];
- string[] array = dictionary["pos"].Split(new char[]
- {
- ','
- });
- base.transform.localPosition = new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
- if (dictionary.ContainsKey("visible"))
- {
- this.visible = bool.Parse(dictionary["visible"]);
- }
- for (int i = 0; i < this.subWindows.Length; i++)
- {
- string key2 = i.ToString() + ":visible";
- if (dictionary.ContainsKey(key2))
- {
- this.subWindows[i].visible = bool.Parse(dictionary[key2]);
- }
- }
- }
- public Rect GetWindowRectFromScreenPoint()
- {
- return this.GetWindowRectFromScreenPoint(0);
- }
- public Rect GetWindowRectFromScreenPoint(int margin)
- {
- Vector3 position = this.bgWidget.transform.position;
- this.bgWidget.transform.localPosition = new Vector3(this.bgWidget.transform.localPosition.x - (float)margin, this.bgWidget.transform.localPosition.y + (float)margin, 0f);
- Vector2 vector = new Vector2(this.WindowSize.x + (float)(margin * 2), this.WindowSize.y + (float)(margin * 2));
- Vector3 vector2 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
- Rect result = default(Rect);
- result.position = new Vector2(vector2.x, (float)Screen.height - vector2.y);
- Vector3 position2 = this.bgWidget.transform.position;
- Vector3 vector3 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
- this.bgWidget.transform.localPosition = this.bgWidget.transform.localPosition + new Vector3(vector.x, -vector.y, 0f);
- Vector3 vector4 = this.uiCamera.WorldToScreenPoint(this.bgWidget.transform.position);
- this.bgWidget.transform.position = position2;
- float x = vector4.x - vector3.x;
- float y = (float)Screen.height - vector4.y - ((float)Screen.height - vector3.y);
- result.size = new Vector2(x, y);
- this.bgWidget.transform.position = position;
- return result;
- }
- public BasePhotoWindowManager mgr
- {
- get
- {
- return this.mgr_;
- }
- }
- public abstract string windowName { get; }
- protected void OnBtnMouseHoverIn(string text)
- {
- MouseExposition @object = MouseExposition.GetObject();
- @object.text = text;
- }
- protected void OnMouseHoverOut()
- {
- MouseExposition @object = MouseExposition.GetObject();
- @object.text = string.Empty;
- }
- public string InitTitle = "キャラクター";
- public Vector2 WindowSize;
- public bool InitVisible = true;
- public BasePhotoSubWindow[] subWindows;
- private UIWidget bgWidget;
- private UIWidget bgWidget2;
- private int panelDirty;
- private UILabel windowTitle;
- protected Camera uiCamera;
- protected UILabel title_bar_label_;
- protected UIPanel panel_;
- protected BasePhotoWindowManager mgr_;
- protected Dictionary<BasePhotoWindow.BtnType, KeyValuePair<UIButton, List<Action>>> btn_dic_;
- protected EventDelegate window_active_delegate_;
- protected GameObject content_game_object_;
- protected Vector3 init_pos_;
- private Dictionary<BasePhotoWindow.BtnType, Vector3> mini_btn_init_pos_ = new Dictionary<BasePhotoWindow.BtnType, Vector3>();
- public enum BtnType
- {
- Help,
- Reset,
- Min,
- End
- }
- }
|