public void Init(float depth, int raycastPriority, int orderInLayer)
        {
            if (this.initialized == false)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.LogError("Can't initialize window instance because of some components was not installed properly.");
                }
                return;
            }

            this.transform.localScale = Vector3.zero;

            this.canvas.worldCamera   = this.GetWindow().workCamera;
            this.canvas.sortingOrder  = orderInLayer;
            this.canvas.planeDistance = 10f;            // * orderInLayer;

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);

            for (int i = 0; i < this.elements.Count; ++i)
            {
                var element = this.elements[i];
                if (element.autoRegisterInRoot == true)
                {
                    element.Setup(this.GetWindow());
                    element.SetComponentState(WindowObjectState.NotInitialized, dontInactivate: true);
                }
            }

            this.root.Setup(this.GetWindow());
        }
 public void DoShowEnd(AppearanceParameters parameters)
 {
     if (this.instance != null)
     {
         this.instance.DoShowEnd(parameters);
         CanvasUpdater.ForceUpdate(this.GetLayoutInstance().canvas, this.GetLayoutInstance().canvasScaler);
     }
 }
        /// <summary>
        /// Show the specified onShowEnd.
        /// </summary>
        /// <param name="onShowEnd">On show end.</param>
        public void Show(System.Action onShowEnd, TransitionBase transition, TransitionInputParameters transitionParameters)
        {
            if (this.currentState == WindowObjectState.Showing || this.currentState == WindowObjectState.Shown)
            {
                return;
            }
            this.currentState = WindowObjectState.Showing;

            WindowSystem.AddToHistory(this);

            var counter = 0;

            System.Action callback = () => {
                if (this.currentState != WindowObjectState.Showing)
                {
                    return;
                }

                ++counter;
                if (counter < 5)
                {
                    return;
                }

                this.OnShowEnd();
                this.OnLayoutShowEnd();
                this.modules.OnShowEnd();
                this.events.OnShowEnd();
                this.transition.OnShowEnd();
                if (onShowEnd != null)
                {
                    onShowEnd();
                }

                CanvasUpdater.ForceUpdate();

                this.currentState = WindowObjectState.Shown;
            };

            this.OnLayoutShowBegin(callback);
            this.modules.OnShowBegin(callback);

            if (transition != null)
            {
                this.transition.OnShowBegin(transition, transitionParameters, callback);
            }
            else
            {
                this.transition.OnShowBegin(callback);
            }

            this.events.OnShowBegin(callback);
            this.OnShowBegin(callback);

            this.gameObject.SetActive(true);
        }
        public override void OnPlay(WindowBase window, object tag, TransitionInputParameters parameters, WindowComponentBase root, bool forward, System.Action callback)
        {
            var param = this.GetParams <Parameters>(parameters);

            if (param == null)
            {
                if (callback != null)
                {
                    callback();
                }
                return;
            }

            var duration    = this.GetDuration(parameters, forward);
            var resultState = param.GetResult(forward);

            var rect  = this.GetRoot(param, window);
            var state = new Parameters.State(rect);

            var material = param.GetMaterialInstance();

            if (TweenerGlobal.instance != null)
            {
                TweenerGlobal.instance.removeTweens(tag);
                TweenerGlobal.instance.addTween(rect, duration, 0f, 1f).onUpdate((obj, value) => {
                    if (obj != null)
                    {
                        param.Apply(material, obj, state, resultState, value);
                    }
                }).onComplete((obj) => {
                    if (callback != null)
                    {
                        callback();
                    }
                    CanvasUpdater.ForceUpdate();
                }).onCancel((obj) => {
                    if (callback != null)
                    {
                        callback();
                    }
                    CanvasUpdater.ForceUpdate();
                }).tag(tag).ease(ME.Ease.GetByType(forward == true ? param.inEase : param.outEase));
            }
            else
            {
                param.Apply(material, rect, resultState);
                if (callback != null)
                {
                    callback();
                }
                CanvasUpdater.ForceUpdate();
            }
        }
        public override void OnValidateEditor()
        {
            base.OnValidateEditor();

            WindowSystem.ApplyToSettings(this.canvas);

            if (ME.EditorUtilities.IsPrefab(this.gameObject) == true)
            {
                this.transform.localScale = Vector3.one * this.editorScale;
            }

            if (this.canvasUpdater == null || this.GetComponents <CanvasUpdater>().Length > 1)
            {
                if (this.GetComponent <CanvasUpdater>() != null)
                {
                    Component.DestroyImmediate(this.GetComponent <CanvasUpdater>());
                }
                this.canvasUpdater = this.GetComponent <CanvasUpdater>();
                if (this.canvasUpdater == null)
                {
                    this.canvasUpdater = this.gameObject.AddComponent <CanvasUpdater>();
                }
                if (this.canvasUpdater != null)
                {
                    this.canvasUpdater.OnValidate();
                }
            }

            if (this.canvasScaler == null || this.GetComponents <CanvasScaler>().Length > 1)
            {
                if (this.GetComponent <CanvasScaler>() != null)
                {
                    Component.DestroyImmediate(this.GetComponent <CanvasScaler>());
                }
                this.canvasScaler = this.GetComponent <CanvasScaler>();
                if (this.canvasScaler == null)
                {
                    this.canvasScaler = this.gameObject.AddComponent <CanvasScaler>();
                }
            }

            /*var rectTransform = (this.transform as RectTransform);
             * rectTransform.anchorMin = Vector2.zero;
             * rectTransform.anchorMax = Vector2.one;
             * rectTransform.pivot = Vector2.one * 0.5f;
             * rectTransform.localScale = Vector3.one;
             * rectTransform.localRotation = Quaternion.identity;
             * rectTransform.anchoredPosition3D = Vector3.zero;*/
        }
        public override void OnValidateEditor()
        {
            base.OnValidateEditor();

            if (Application.isPlaying == true)
            {
                return;
            }

            if (this.canvasUpdater == null || this.GetComponents <CanvasUpdater>().Length > 1)
            {
                if (this.GetComponent <CanvasUpdater>() != null)
                {
                    Component.DestroyImmediate(this.GetComponent <CanvasUpdater>());
                }
                this.canvasUpdater = this.GetComponent <CanvasUpdater>();
                if (this.canvasUpdater == null)
                {
                    this.canvasUpdater = this.gameObject.AddComponent <CanvasUpdater>();
                }
                if (this.canvasUpdater != null)
                {
                    this.canvasUpdater.OnValidate();
                }
            }

            if (this.canvasScaler == null || this.GetComponents <CanvasScaler>().Length > 1)
            {
                if (this.GetComponent <CanvasScaler>() != null)
                {
                    Component.DestroyImmediate(this.GetComponent <CanvasScaler>());
                }
                this.canvasScaler = this.GetComponent <CanvasScaler>();
                if (this.canvasScaler == null)
                {
                    this.canvasScaler = this.gameObject.AddComponent <CanvasScaler>();
                }
            }

            var rectTransform = (this.transform as RectTransform);

            rectTransform.anchorMin          = Vector2.zero;
            rectTransform.anchorMax          = Vector2.one;
            rectTransform.pivot              = Vector2.one * 0.5f;
            rectTransform.localScale         = Vector3.one;
            rectTransform.localRotation      = Quaternion.identity;
            rectTransform.anchoredPosition3D = Vector3.zero;
        }
        public void Init(float depth, int raycastPriority, int orderInLayer, WindowLayout.ScaleMode scaleMode, Vector2 fixedScaleResolution, WindowLayoutPreferences layoutPreferences)
        {
            if (this.initialized == false)
            {
                Debug.LogError("Can't initialize window instance because of some components was not installed properly.");
                return;
            }

            this.transform.localScale = Vector3.zero;

            this.canvas.sortingOrder  = orderInLayer;
            this.canvas.planeDistance = 10f;            // * orderInLayer;
            this.canvas.worldCamera   = this.GetWindow().workCamera;

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);

            var matchWidthOrHeight = 0f;

            if (scaleMode == ScaleMode.Preferences)
            {
                var fixedScale = layoutPreferences.fixedScale;
                if (fixedScale == true)
                {
                    scaleMode = ScaleMode.Fixed;
                }
                else
                {
                    scaleMode = ScaleMode.Normal;
                }

                fixedScaleResolution = layoutPreferences.fixedScaleResolution;
                matchWidthOrHeight   = layoutPreferences.matchWidthOrHeight;
            }

            this.SetScale(scaleMode, fixedScaleResolution, matchWidthOrHeight);

            for (int i = 0; i < this.elements.Count; ++i)
            {
                this.elements[i].Setup(this.GetWindow());
                this.elements[i].SetComponentState(WindowObjectState.NotInitialized, dontInactivate: true);
            }

            this.root.Setup(this.GetWindow());
        }
            public void Apply(Material material, WindowLayoutRoot root, State startState, State resultState, float value)
            {
                CanvasUpdater.ForceUpdate();

                root.alpha = Mathf.Lerp(startState.alpha, resultState.alpha, value);

                root.rectTransform.anchorMin        = Vector2.Lerp(startState.anchorMin, resultState.anchorMin, value);
                root.rectTransform.anchorMax        = Vector2.Lerp(startState.anchorMax, resultState.anchorMax, value);
                root.rectTransform.anchoredPosition = Vector2.Lerp(startState.anchoredPosition, resultState.anchoredPosition, value);
                root.rectTransform.sizeDelta        = Vector2.Lerp(startState.sizeDelta, resultState.sizeDelta, value);
                root.rectTransform.pivot            = Vector2.Lerp(startState.pivot, resultState.pivot, value);

                root.rectTransform.localRotation = Quaternion.Slerp(startState.localRotation, resultState.localRotation, value);
                root.rectTransform.localScale    = Vector3.Lerp(startState.localScale, resultState.localScale, value);

                if (material != null)
                {
                    material.SetFloat(this.GetMaterialStrengthName(), Mathf.Lerp(startState.materialStrength, resultState.materialStrength, value));
                }

                CanvasUpdater.ForceUpdate();
            }
            public void Apply(Material material, WindowLayoutRoot root, State state)
            {
                CanvasUpdater.ForceUpdate();

                root.alpha = state.alpha;

                root.rectTransform.anchorMin        = state.anchorMin;
                root.rectTransform.anchorMax        = state.anchorMax;
                root.rectTransform.anchoredPosition = state.anchoredPosition;
                root.rectTransform.sizeDelta        = state.sizeDelta;
                root.rectTransform.pivot            = state.pivot;

                root.rectTransform.localRotation = state.localRotation;
                root.rectTransform.localScale    = state.localScale;

                if (material != null)
                {
                    material.SetFloat(this.GetMaterialStrengthName(), state.materialStrength);
                }

                CanvasUpdater.ForceUpdate();
            }
        public void Init(float depth, int raycastPriority, int orderInLayer, WindowLayout.ScaleMode scaleMode, Vector2 fixedScaleResolution)
        {
            if (this.initialized == false)
            {
                Debug.LogError("Can't initialize window instance because of some components was not installed properly.");
                return;
            }

            this.transform.localScale = Vector3.zero;

            this.canvas.sortingOrder  = orderInLayer;
            this.canvas.planeDistance = 10f;            // * orderInLayer;
            this.canvas.worldCamera   = this.GetWindow().workCamera;

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);

            this.SetScale(scaleMode, fixedScaleResolution);

            for (int i = 0; i < this.elements.Count; ++i)
            {
                this.elements[i].Setup(this.GetWindow());
            }
            this.root.Setup(this.GetWindow());
        }
Exemple #11
0
        public void DoShowEnd(AppearanceParameters parameters)
        {
            this.instance.DoShowEnd(parameters);

            CanvasUpdater.ForceUpdate(this.instance.canvas, this.instance.canvasScaler);
        }
Exemple #12
0
        public IEnumerator CheckPivot_YIELD(Vector2 size, RectTransform sourceTransform, ShowPriority showPriority)
        {
            // Get pivot point according on screen rect

            // Check points
            var checks     = new Vector2[0];
            var offsetDirs = new Vector2[0];

            if (showPriority == ShowPriority.Down)
            {
                checks = new Vector2[] {
                    new Vector2(0.5f, 1f),                      // top center
                    new Vector2(0f, 1f),                        // top left
                    new Vector2(1f, 1f),                        // top right
                    new Vector2(0.5f, 0f),                      // bottom center
                    new Vector2(0f, 0f),                        // bottom left
                    new Vector2(1f, 0f),                        // bottom right
                };

                offsetDirs = new Vector2[] {
                    Vector2.down,
                    Vector2.down,
                    Vector2.down,
                    Vector2.up,
                    Vector2.up,
                    Vector2.up,
                };
            }
            else if (showPriority == ShowPriority.Up)
            {
                checks = new Vector2[] {
                    new Vector2(0.5f, 0f),                      // bottom center
                    new Vector2(0f, 0f),                        // bottom left
                    new Vector2(1f, 0f),                        // bottom right
                    new Vector2(0.5f, 1f),                      // top center
                    new Vector2(0f, 1f),                        // top left
                    new Vector2(1f, 1f),                        // top right
                };

                offsetDirs = new Vector2[] {
                    Vector2.up,
                    Vector2.up,
                    Vector2.up,
                    Vector2.down,
                    Vector2.down,
                    Vector2.down,
                };
            }

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);
            yield return(false);

            var scaleFactor = this.GetScaleFactor();

            size *= scaleFactor;

            this.ApplyPosition();

            var centerPoint = this.root.anchoredPosition;
            var sourceRect  = (this.canvas.transform as RectTransform).rect;

            for (int i = 0; i < checks.Length; ++i)
            {
                var centerOffset = offsetDirs[i] * size.y * 0.5f;
                var pivot        = checks[i];
                this.layoutRoot.pivot = pivot;

                this.root.anchoredPosition = centerPoint + centerOffset;

                Vector3[] points = new Vector3[4];
                this.layoutRoot.GetLocalCorners(points);

                var offset      = this.root.anchoredPosition;
                var bottomLeft  = offset + points[0].XY();
                var topLeft     = offset + points[1].XY();
                var topRight    = offset + points[2].XY();
                var bottomRight = offset + points[3].XY();

                if (sourceRect.Contains(bottomLeft) == false)
                {
                    //Debug.Log("Failed bottom left: " + sourceRect + " << " + bottomLeft);
                    continue;
                }

                if (sourceRect.Contains(topLeft) == false)
                {
                    //Debug.Log("Failed top left: " + sourceRect + " << " + topLeft);
                    continue;
                }

                if (sourceRect.Contains(topRight) == false)
                {
                    //Debug.Log("Failed top right: " + sourceRect + " << " + topRight);
                    continue;
                }

                if (sourceRect.Contains(bottomRight) == false)
                {
                    //Debug.Log("Failed bottom right: " + sourceRect + " << " + bottomRight);
                    continue;
                }

                break;
            }
        }
        public System.Collections.Generic.IEnumerator <byte> CheckPivot_YIELD(Vector2 size, RectTransform sourceTransform)
        {
            // Get pivot point according on screen rect

            // Check points
            var checks = new Vector2[] {
                new Vector2(0.5f, 1f),                  // top center
                new Vector2(0.5f, 0f),                  // bottom center
                new Vector2(0f, 0f),                    // bottom left
                new Vector2(1f, 0f),                    // bottom right
                new Vector2(0f, 1f),                    // top left
                new Vector2(1f, 1f)                     // top right
            };

            var offsetDirs = new Vector2[] {
                Vector2.down,
                Vector2.up,
                Vector2.up,
                Vector2.up,
                Vector2.down,
                Vector2.down
            };

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);
            yield return(0);

            var scaleFactor = this.GetScaleFactor();

            size *= scaleFactor;

            this.ApplyPosition();

            var centerPoint = this.root.anchoredPosition;
            var sourceRect  = (this.canvas.transform as RectTransform).rect;

            for (int i = 0; i < checks.Length; ++i)
            {
                var centerOffset = offsetDirs[i] * size.y * 0.5f;
                var pivot        = checks[i];
                this.layoutRoot.pivot = pivot;

                this.root.anchoredPosition = centerPoint + centerOffset;

                Vector3[] points = new Vector3[4];
                this.layoutRoot.GetLocalCorners(points);

                var offset      = this.root.anchoredPosition;
                var bottomLeft  = offset + points[0].XY();
                var topLeft     = offset + points[1].XY();
                var topRight    = offset + points[2].XY();
                var bottomRight = offset + points[3].XY();

                if (sourceRect.Contains(bottomLeft) == false)
                {
                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed bottom left: " + sourceRect + " << " + bottomLeft);
                    continue;
                }

                if (sourceRect.Contains(topLeft) == false)
                {
                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed top left: " + sourceRect + " << " + topLeft);
                    continue;
                }

                if (sourceRect.Contains(topRight) == false)
                {
                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed top right: " + sourceRect + " << " + topRight);
                    continue;
                }

                if (sourceRect.Contains(bottomRight) == false)
                {
                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Failed bottom right: " + sourceRect + " << " + bottomRight);
                    continue;
                }

                break;
            }
        }