Exemplo n.º 1
0
        public static void UnregisterObject(WindowObject obj)
        {
            if (WindowSystem.IsDebugWeakReferences() == false)
            {
                return;
            }
            if (Application.isPlaying == false)
            {
                return;
            }

            //if ((obj.GetWindow() is MW2.UI.EditorTools.Console.ConsoleScreen) == false) {

            //Debug.Log("DEL: " + obj.name + " :: " + obj.GetInstanceID());

            var item = WindowSystemResources.instance.registered.FirstOrDefault(x => x.instanceId == obj.GetInstanceID());

            if (item != null)
            {
                WindowSystemResources.instance.registered.RemoveAll(x => x.instanceId == obj.GetInstanceID());
            }
            else
            {
                Debug.LogWarning(string.Format("Trying to unregister reference that doesn't exists: {0} ({1})", obj.name, obj.GetInstanceID()), obj);
            }

            //}
        }
Exemplo n.º 2
0
        public static void RegisterObject(WindowObject obj)
        {
            if (WindowSystem.IsDebugWeakReferences() == false)
            {
                return;
            }
            if (Application.isPlaying == false)
            {
                return;
            }

            //if ((obj.GetWindow() is MW2.UI.EditorTools.Console.ConsoleScreen) == false/*obj.GetComponentsInParent<MW2.UI.EditorTools.Console.ConsoleScreen>(true).Length == 0*/) {

            //Debug.Log("ADD: " + obj.name + " :: " + obj.GetInstanceID());

            var item = WindowSystemResources.instance.registered.FirstOrDefault(x => x.instanceId == obj.GetInstanceID());

            if (item != null)
            {
                Debug.LogError("Object is already in list: " + item.name + " :: " + item.instanceId);
            }
            WindowSystemResources.instance.registered.Add(new ObjectEntity()
            {
                name = string.Format("{0} ({1})", obj.name, obj.GetInstanceID()), instanceId = obj.GetInstanceID(), reference = obj, window = obj.GetWindow()
            });
            WeakReferenceInfo.Register(obj);

            //}
        }
Exemplo n.º 3
0
 public void Add(WindowObject component, AppearanceParameters parameters, HistoryTrackerEventType eventType)
 {
     if (WindowSystemLogger.IsActiveComponents() == true)
     {
         var stack = new StackTrace();
         this.items.Add(new Item(stack.GetFrames(), parameters, eventType));
     }
 }
        public bool RemoveSubObject(WindowObject windowObject)
        {
            if (this.subObjects.Remove(windowObject) == true)
            {
                windowObject.rootObject = null;
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public static Vector2 ConvertPointWindowToGLScreen(Vector2 point, WindowObject handler)
        {
            var size       = (handler.GetWindow <UnityEngine.UI.Windows.Types.LayoutWindowType>().layout.GetLayoutInstance().transform as RectTransform).sizeDelta;
            var screenSize = new Vector2(Screen.width, Screen.height);

            var result = new Vector2(screenSize.x / size.x, screenSize.y / size.y);

            result.Scale(new Vector2(size.x * 0.5f + point.x, size.y * 0.5f - point.y));

            return(result);
        }
Exemplo n.º 6
0
        public static void ShowInstance(WindowObject instance, TransitionParameters parameters)
        {
            if (instance.objectState == ObjectState.Showing || instance.objectState == ObjectState.Shown)
            {
                parameters.RaiseCallback();
                return;
            }
            instance.SetState(ObjectState.Showing);

            instance.OnShowBeginInternal();
            instance.OnShowBegin();
            WindowSystem.RaiseEvent(instance, WindowEvent.OnShowBegin);

            {
                if (instance.gameObject.activeSelf == false)
                {
                    instance.gameObject.SetActive(true);
                }
                instance.SetVisible();
                instance.SetResetState();

                var animationComplete = false;
                var childsComplete    = false;
                Coroutines.CallInSequence(() => {
                    childsComplete = true;

                    if (animationComplete == true)
                    {
                        parameters.RaiseCallback();
                    }
                }, instance.subObjects, (obj, cb) => {
                    obj.Show(parameters.ReplaceCallback(cb));
                });

                var closureParameters = new ShowHideClosureParameters()
                {
                    instance   = instance,
                    parameters = parameters,
                };
                WindowObjectAnimation.Show(closureParameters, instance, parameters, (cParams) => {
                    animationComplete = true;
                    if (childsComplete == true)
                    {
                        cParams.parameters.RaiseCallback();
                    }
                });
            }
        }
Exemplo n.º 7
0
        public static void HideInstance(WindowObject instance, TransitionParameters parameters)
        {
            if (instance.objectState <= ObjectState.Initializing)
            {
                Debug.LogWarning("Object is out of state: " + instance, instance);
                return;
            }

            if (instance.objectState == ObjectState.Hiding || instance.objectState == ObjectState.Hidden)
            {
                parameters.RaiseCallback();
                return;
            }
            instance.SetState(ObjectState.Hiding);

            instance.OnHideBeginInternal();
            instance.OnHideBegin();
            WindowSystem.RaiseEvent(instance, WindowEvent.OnHideBegin);

            {
                var animationComplete = false;
                var childsComplete    = false;
                Coroutines.CallInSequence(() => {
                    childsComplete = true;

                    if (animationComplete == true)
                    {
                        parameters.RaiseCallback();
                    }
                }, instance.subObjects, (obj, cb) => {
                    obj.Hide(parameters.ReplaceCallback(cb));
                });

                var closureParameters = new ShowHideClosureParameters()
                {
                    instance   = instance,
                    parameters = parameters,
                };
                WindowObjectAnimation.Hide(closureParameters, instance, parameters, (cParams) => {
                    animationComplete = true;
                    if (childsComplete == true)
                    {
                        cParams.parameters.RaiseCallback();
                    }
                });
            }
        }
Exemplo n.º 8
0
        public bool UnRegisterSubObject(WindowObject windowObject)
        {
            if (this.subObjects.Remove(windowObject) == true)
            {
                windowObject.rootObject = null;

                {
                    switch (this.objectState)
                    {
                    case ObjectState.Initializing:
                    case ObjectState.Initialized:
                        windowObject.DoDeInit();
                        break;

                    case ObjectState.Showing:
                    case ObjectState.Shown:

                        // after OnShowEnd
                        windowObject.Hide(TransitionParameters.Default.ReplaceImmediately(true));
                        windowObject.DoDeInit();
                        break;

                    case ObjectState.Hiding:

                        // after OnHideBegin
                        WindowSystem.SetHidden(windowObject, TransitionParameters.Default.ReplaceImmediately(true));
                        windowObject.DoDeInit();
                        break;

                    case ObjectState.Hidden:

                        // after OnHideEnd
                        windowObject.DoDeInit();
                        break;
                    }
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        internal static void SetShown(WindowObject instance, TransitionParameters parameters)
        {
            if (instance.objectState != ObjectState.Showing)
            {
                parameters.RaiseCallback();
                return;
            }

            var innerParameters = parameters.ReplaceCallback(null);

            for (int i = 0; i < instance.subObjects.Count; ++i)
            {
                WindowSystem.SetShown(instance.subObjects[i], innerParameters);
            }

            instance.OnShowEndInternal();
            instance.OnShowEnd();
            WindowSystem.RaiseEvent(instance, WindowEvent.OnShowEnd);

            instance.SetState(ObjectState.Shown);

            parameters.RaiseCallback();
        }
Exemplo n.º 10
0
        public bool RegisterSubObject(WindowObject windowObject)
        {
            windowObject.Setup(this.window);

            if (this.subObjects.Contains(windowObject) == false)
            {
                this.subObjects.Add(windowObject);
                windowObject.rootObject = this;

                {
                    switch (this.objectState)
                    {
                    case ObjectState.Initializing:
                    case ObjectState.Initialized:
                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }
                        break;

                    case ObjectState.Showing:
                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }

                        if (windowObject.hiddenByDefault == false)
                        {
                            WindowSystem.ShowInstance(windowObject, TransitionParameters.Default.ReplaceImmediately(true), internalCall: true);
                        }
                        break;

                    case ObjectState.Shown:
                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }

                        if (windowObject.hiddenByDefault == false)
                        {
                            WindowSystem.ShowInstance(
                                windowObject,
                                TransitionParameters.Default.ReplaceImmediately(true).ReplaceCallback(() => {
                                WindowSystem.SetShown(windowObject, TransitionParameters.Default.ReplaceImmediately(true));
                            }), internalCall: true);
                        }

                        break;

                    case ObjectState.Hiding:

                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }

                        windowObject.SetState(this.objectState);

                        break;

                    case ObjectState.Hidden:

                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }

                        windowObject.SetState(this.objectState);

                        break;

                    case ObjectState.DeInitializing:
                    case ObjectState.DeInitialized:
                        if (windowObject.GetState() == ObjectState.NotInitialized)
                        {
                            windowObject.DoInit();
                        }

                        windowObject.DoDeInit();
                        break;
                    }
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        public void ValidateEditor(bool updateParentObjects)
        {
            if (updateParentObjects == true)
            {
                var topObjects = this.GetComponentsInParent <WindowObject>(true);
                foreach (var obj in topObjects)
                {
                    if (obj != this)
                    {
                        obj.ValidateEditor();
                    }
                }
            }

            if (this.registry != null)
            {
                var holders = new List <WindowObject>();
                foreach (var reg in this.registry)
                {
                    if (reg.holder != null)
                    {
                        holders.Add(reg.holder);
                    }
                }
                this.registry.Clear();
                foreach (var holder in holders)
                {
                    if (holder != this)
                    {
                        holder.ValidateEditor(updateParentObjects: false);
                    }
                }
            }

            this.isObjectRoot    = (this.transform.parent == null);
            this.objectCanvas    = this.GetComponent <Canvas>();
            this.hasObjectCanvas = (this.objectCanvas != null);

            { // Collect render items
              /*if (this.canvasGroupRender == null) {
               *
               *  var canvasGroup = this.gameObject.GetComponent<CanvasGroup>();
               *  if (canvasGroup != null) {
               *
               *      this.canvasGroupRender = canvasGroup;
               *
               *  } else {
               *
               *      this.canvasGroupRender = this.gameObject.AddComponent<CanvasGroup>();
               *      this.canvasGroupRender.alpha = 1f;
               *      this.canvasGroupRender.interactable = true;
               *      this.canvasGroupRender.blocksRaycasts = true;
               *
               *  }
               *
               * }*/

                var canvasRenderers = this.GetComponentsInChildren <CanvasRenderer>(true).Where(x => x.GetComponentsInParent <WindowObject>(true)[0] == this).ToArray();
                for (int i = 0; i < canvasRenderers.Length; ++i)
                {
                    if (canvasRenderers[i].GetComponent <UnityEngine.UI.Graphic>() == null)
                    {
                        Object.DestroyImmediate(canvasRenderers[i], allowDestroyingAssets: true);
                        canvasRenderers[i] = null;
                    }
                }

                canvasRenderers = canvasRenderers.Where(x => x != null).ToArray();
                var rectMasks = this.GetComponentsInChildren <RectMask2D>().Where(x => x.GetComponentsInParent <WindowObject>(true)[0] == this).ToArray();
                this.canvasRenderers = new RenderItem[canvasRenderers.Length + rectMasks.Length];
                var k = 0;
                for (int i = 0; i < this.canvasRenderers.Length; ++i)
                {
                    if (i < rectMasks.Length)
                    {
                        this.canvasRenderers[i] = new RenderItem()
                        {
                            rectMask = rectMasks[i]
                        };
                    }
                    else
                    {
                        this.canvasRenderers[i] = new RenderItem()
                        {
                            canvasRenderer = canvasRenderers[k],
                            graphics       = canvasRenderers[k].GetComponent <UnityEngine.UI.Graphic>()
                        };

                        ++k;
                    }
                }
            }

            var roots = this.GetComponentsInParent <WindowObject>(true);

            if (roots.Length >= 2)
            {
                this.rootObject = roots[1];
            }
            if (this.autoRegisterSubObjects == true)
            {
                this.subObjects = this.GetComponentsInChildren <WindowObject>(true).Where(x => {
                    if (x.allowRegisterInRoot == false)
                    {
                        return(false);
                    }

                    var comps = x.GetComponentsInParent <WindowObject>(true);
                    if (comps.Length < 2)
                    {
                        return(false);
                    }

                    var c = comps[1];
                    return(x != this && c == this);
                }).ToList();
            }
        }
Exemplo n.º 12
0
        public static Vector2 ConvertPointScreenToWindow(Vector2 screenPoint, WindowObject handler)
        {
            var k = (handler.GetWindow().GetLayoutRoot() as RectTransform).sizeDelta.x / Screen.width;

            return(screenPoint * k);
        }
Exemplo n.º 13
0
 public void Setup(WindowObject obj)
 {
     this.rf = new System.WeakReference(obj);
 }
Exemplo n.º 14
0
        public TransitionParameters ReplaceCallbackWithContext(System.Action <WindowObject, TransitionParameters> callback, WindowObject context, TransitionParameters other)
        {
            var instance = this;

            instance.data.callback   = null;
            instance.contextCallback = callback;
            instance.internalData    = new TransitionInternalData()
            {
                context = context, data = other.data
            };
            return(instance);
        }
Exemplo n.º 15
0
        public static void RaiseEvent(WindowObject instance, WindowEvent windowEvent)
        {
            var events = WindowSystem.GetEvents();

            events.Raise(instance, windowEvent);
        }
Exemplo n.º 16
0
        public static Vector2 ConvertPointWindowToUnityScreen(Vector2 point, WindowObject handler)
        {
            var size = (handler.GetWindow <UnityEngine.UI.Windows.Types.LayoutWindowType>().layout.GetLayoutInstance().transform as RectTransform).sizeDelta;

            return(new Vector2(size.x * 0.5f + point.x, size.y * 0.5f + point.y));
        }
Exemplo n.º 17
0
        public static void UnRegisterAction(WindowObject instance, WindowEvent windowEvent, System.Action callback)
        {
            var events = WindowSystem.GetEvents();

            events.UnRegister(instance, windowEvent, callback);
        }
Exemplo n.º 18
0
        public static void ClearEvents(WindowObject instance)
        {
            var events = WindowSystem.GetEvents();

            events.Clear(instance);
        }