private void DoShowBeginManualControl(AppearanceParameters parameters)
        {
            if (this.GetComponentState() == WindowObjectState.NotInitialized ||
                this.GetComponentState() == WindowObjectState.Initializing ||
                this.GetComponentState() == WindowObjectState.Initialized)
            {
                parameters.Call();
                return;
            }

            if (this.IsStateReadyToShow() == false &&
                parameters.GetForced(defaultValue: false) == false)
            {
                parameters.Call();
                return;
            }

            for (int i = 0; i < this.subComponents.Count; ++i)
            {
                var sub = this.subComponents[i] as WindowComponentBase;
                sub.DoShowBeginManualControl(parameters.ReplaceCallback(null));
            }

            WindowSystem.RunSafe(this.OnShowBegin);
            WindowSystem.RunSafe(this.OnShowBegin, parameters);

            parameters.Call();
        }
        /// <summary>
        /// Clean the specified except.
        /// </summary>
        /// <param name="except">Except.</param>
        public static void Clean(List <WindowBase> except, bool forceAll = false)
        {
            WindowSystem.instance.currentWindows.RemoveAll((window) => {
                var result = WindowSystem.instance.DestroyWindowCheckOnClean_INTERNAL(window, except, null, forceAll);
                if (result == true)
                {
                    if (window != null)
                    {
                        WindowBase.DestroyImmediate(window.gameObject);
                    }
                }

                return(result);
            });

            WindowSystem.ResetDepth();

            if (except != null)
            {
                for (int i = 0; i < except.Count; ++i)
                {
                    var instance = except[i];
                    if (instance == null)
                    {
                        continue;
                    }
                    instance.SetDepth(WindowSystem.instance.GetNextDepth(instance.preferences, instance.workCamera.depth), WindowSystem.instance.GetNextZDepth(instance.preferences));
                    instance.OnCameraReset();
                }
            }

            WindowSystem.RefreshHistory();
        }
Beispiel #3
0
        public static void Select(IInteractableComponent button)
        {
            if (button != null)
            {
                var sel = button.GetSelectable();
                if (sel != null)
                {
                    if (button.IsVisible() == false)
                    {
                        var buttonBase = (button as WindowComponentBase);

                        System.Action callback = null;
                        callback = () => {
                            WindowSystem.GetEvents().Unregister(buttonBase, WindowEventType.OnShowEnd, callback);
                            WindowSystemInput.Select_INTERNAL(button);
                        };

                        WindowSystem.GetEvents().Register(buttonBase, WindowEventType.OnShowEnd, callback);
                    }
                    else
                    {
                        WindowSystemInput.Select_INTERNAL(button);
                    }
                }
            }
        }
        /// <summary>
        /// Init this instance.
        /// </summary>
        protected virtual void Init()
        {
            this.currentWindows.Clear();
            this.functions = new Functions();
            this.audio.Init();

            this.depthStep  = (this.settings.GetMaxDepth(0) - this.settings.GetMinDepth(0)) / this.settings.poolSize;
            this.zDepthStep = this.settings.zDepthStep;
            WindowSystem.ResetDepth();

            foreach (var window in this.windows)
            {
                if (window == null)
                {
                    Debug.LogWarning("Some windows was not setup correctly. Be sure all windows have their screens.");
                    continue;
                }

                if (window.preferences.createPool == false)
                {
                    continue;
                }

                if (window.preferences.preallocatedCount > 0)
                {
                    window.CreatePool(window.preferences.preallocatedCount, (source) => { return(WindowSystem.instance.Create_INTERNAL(source, null)); });
                }
                else
                {
                    window.CreatePool(this.settings.preallocatedWindowsPoolSize);
                }
            }
        }
        /// <summary>
        /// Clean the specified except.
        /// </summary>
        /// <param name="except">Except.</param>
        public static void Clean(WindowBase except = null, bool forceAll = false)
        {
            WindowSystem.instance.currentWindows.RemoveAll((window) => {
                var result = WindowSystem.instance.DestroyWindowCheckOnClean_INTERNAL(window, null, except, forceAll);
                if (result == true)
                {
                    if (window != null)
                    {
                        WindowBase.DestroyImmediate(window.gameObject);
                    }
                }

                return(result);
            });

            WindowSystem.ResetDepth();

            if (except != null)
            {
                except.SetDepth(WindowSystem.instance.GetNextDepth(except.preferences, except.workCamera.depth), WindowSystem.instance.GetNextZDepth(except.preferences));
                except.OnCameraReset();
            }

            WindowSystem.RefreshHistory();
        }
        public void TurnOn()
        {
            if (this == null)
            {
                return;
            }

                        #if UNITY_EDITOR
            Profiler.BeginSample("WindowBase::TurnOn()");
                        #endif

            if (WindowSystem.IsCameraRenderDisableOnWindowTurnOff() == true)
            {
                if (this.workCamera != null)
                {
                    this.workCamera.enabled = true;
                }
            }
            else
            {
                if (this.gameObject != null)
                {
                    this.gameObject.SetActive(true);
                }
            }

                        #if UNITY_EDITOR
            Profiler.EndSample();
                        #endif
        }
        public static void UpdateLastInstance()
        {
            if (WindowSystem.instance == null)
            {
                return;
            }

            var lastInstance = WindowSystem.GetWindow((item) => item.window != null && (item.window.GetState() == WindowObjectState.Shown || item.window.GetState() == WindowObjectState.Showing));

            if (lastInstance != WindowSystem.instance.lastInstance)
            {
                WindowSystem.instance.previousInstance = WindowSystem.instance.lastInstance;
                if (WindowSystem.instance.previousInstance != null)
                {
                    WindowSystem.instance.previousInstance.SetInactive();
                }
            }

            WindowSystem.instance.lastInstance = lastInstance;

            if (WindowSystem.instance.lastInstance != null)
            {
                WindowSystem.instance.lastInstance.SetActive();
            }
        }
        public bool TurnOff()
        {
            if (this == null)
            {
                return(false);
            }

                        #if UNITY_EDITOR
            Profiler.BeginSample("WindowBase::TurnOff()");
                        #endif

            var result = false;
            if (WindowSystem.IsCameraRenderDisableOnWindowTurnOff() == true)
            {
                if (this.workCamera != null)
                {
                    this.workCamera.enabled = false;
                }
                result = false;
            }
            else
            {
                if (this.gameObject != null)
                {
                    this.gameObject.SetActive(false);
                }
                result = true;
            }

                        #if UNITY_EDITOR
            Profiler.EndSample();
                        #endif

            return(result);
        }
        private void SetDrag_INTERNAL(Vector2 delta)
        {
            var k = (this.GetLayoutRoot() as RectTransform).sizeDelta.x / Screen.width;

            if (this.preferences.IsDragViewportRestricted() == true)
            {
                var screenRect = WindowSystem.GetScreenRect();
                var rect       = this.GetRect();
                rect.center += delta;

                if (rect.xMin <= screenRect.xMin)
                {
                    delta.x += screenRect.xMin - rect.xMin;
                }
                if (rect.yMin - rect.height <= screenRect.yMin)
                {
                    delta.y += screenRect.yMin - (rect.yMin - rect.height);
                }
                if (rect.xMax >= screenRect.xMax)
                {
                    delta.x += screenRect.xMax - rect.xMax;
                }
                if (rect.yMax - rect.height >= screenRect.yMax)
                {
                    delta.y += screenRect.yMax - (rect.yMax - rect.height);
                }
            }

            this.MoveLayout(delta * k);
        }
Beispiel #10
0
        internal void ApplyCamera()
        {
            var settings = WindowSystem.GetSettings();

            switch (this.preferences.cameraMode)
            {
            case UIWSCameraMode.UseSettings:
                this.workCamera.orthographic = settings.camera.orthographicDefault;
                break;

            case UIWSCameraMode.Orthographic:
                this.workCamera.orthographic     = true;
                this.workCamera.orthographicSize = settings.camera.orthographicSize;
                this.workCamera.nearClipPlane    = settings.camera.orthographicNearClippingPlane;
                this.workCamera.farClipPlane     = settings.camera.orthographicFarClippingPlane;
                break;

            case UIWSCameraMode.Perspective:
                this.workCamera.orthographic  = false;
                this.workCamera.fieldOfView   = settings.camera.perspectiveSize;
                this.workCamera.nearClipPlane = settings.camera.perspectiveNearClippingPlane;
                this.workCamera.farClipPlane  = settings.camera.perspectiveFarClippingPlane;
                break;
            }
        }
Beispiel #11
0
        public static T ShowNext <T>(this WindowBase window, System.Action <T> onParametersPassCall = null) where T : WindowBase
        {
            var newPrefs = new Preferences(WindowSystem.GetSource <T>().preferences);

            newPrefs.showInSequence = true;

            var parameters = new WindowSystemShowParameters <T>()
            {
                onParametersPassCall = onParametersPassCall,
                overridePreferences  = true,
                prefereces           = newPrefs,
            };

            var instance = WindowSystem.ShowWithParameters <T>(parameters);

            UnityAction action = null;

            action = () => {
                window.events.onEveryInstance.Unregister(WindowEventType.OnHideEnd, action);

                instance.Show();
            };
            window.events.onEveryInstance.Register(WindowEventType.OnHideEnd, action);

            return(instance);
        }
Beispiel #12
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);
            }

            //}
        }
        public void Show(TransitionParameters parameters = default)
        {
            if (this.objectState <= ObjectState.Initializing)
            {
                if (this.objectState == ObjectState.NotInitialized)
                {
                    this.DoInit();
                }
                else
                {
                    Debug.LogWarning("Object is out of state: " + this, this);
                    return;
                }
            }

            this.internalManualShow = true;

            if (this.objectState == ObjectState.Showing || this.objectState == ObjectState.Shown)
            {
                parameters.RaiseCallback();
                return;
            }

            var cObj         = this;
            var cParams      = parameters;
            var cbParameters = parameters.ReplaceCallbackWithContext(WindowSystem.SetShown, cObj, cParams);

            WindowSystem.ShowInstance(this, cbParameters, internalCall: true);
        }
        private IEnumerator LoadAsync_YIELD <T>(Resource resource, System.Action <T> onComplete = null) where T : WindowObject
        {
            var resources = WindowSystem.GetResources();
            var data      = new LoadAsyncClosure <T>()
            {
                component  = this,
                onComplete = onComplete,
            };

            yield return(resources.LoadAsync <T, LoadAsyncClosure <T> >(this.GetWindow(), data, resource, (asset, closure) => {
                if (asset != null)
                {
                    var instance = closure.component.Load(asset);
                    if (closure.onComplete != null)
                    {
                        closure.onComplete.Invoke(instance);
                    }
                }
                else
                {
                    if (closure.onComplete != null)
                    {
                        closure.onComplete.Invoke(null);
                    }
                }
            }));
        }
        public void PushToPool()
        {
            if (this.createPool == false)
            {
                for (int i = this.subObjects.Count - 1; i >= 0; --i)
                {
                    this.subObjects[i].PushToPool();
                }
            }

            if (this.isObjectRoot == true)
            {
                if (this.rootObject != null)
                {
                    this.rootObject.RemoveSubObject(this);
                }

                if (this.createPool == false)
                {
                    this.DoDeInit();
                }

                WindowSystem.GetPools().Despawn(this);
            }
        }
Beispiel #16
0
        public override void DoHideEnd(AppearanceParameters parameters)
        {
            if (this == null)
            {
                return;
            }

            if (this.GetComponentState() == WindowObjectState.NotInitialized ||
                this.GetComponentState() == WindowObjectState.Initializing ||
                this.GetComponentState() == WindowObjectState.Initialized)
            {
                //parameters.Call();
                return;
            }

            if (this.manualShowHideControl == true)
            {
                this.DoHideEndManualControl(parameters);
                return;
            }

            WindowSystem.GetHistoryTracker().Add(this, HistoryTrackerEventType.HideEnd);

            WindowSystem.GetEvents().Raise(this, WindowEventType.OnHideEnd);

            this.DoHideEnd_INTERNAL(parameters);
        }
Beispiel #17
0
        public override void DoHideBegin(AppearanceParameters parameters)
        {
            if (this == null)
            {
                parameters.Call();
                return;
            }

            if (this.GetComponentState() == WindowObjectState.NotInitialized ||
                this.GetComponentState() == WindowObjectState.Initializing ||
                this.GetComponentState() == WindowObjectState.Initialized)
            {
                this.RefreshComponentState();
                parameters.Call();
                return;
            }

            if (parameters.GetManual(false) == true)
            {
                this.Hide(parameters);
                return;
            }

            if (this.manualShowHideControl == true)
            {
                this.DoHideBeginManualControl(parameters);
                return;
            }

            WindowSystem.GetHistoryTracker().Add(this, parameters, HistoryTrackerEventType.HideBegin);

            this.DoHideBegin_INTERNAL(parameters);
        }
Beispiel #18
0
        private void Hide_INTERNAL(AppearanceParameters parameters)
        {
            WindowSystem.GetHistoryTracker().Add(this, parameters, HistoryTrackerEventType.HideManual);

            this.manualShowHideControl = true;

            //parameters = parameters.ReplaceManual(manual: true);

            var callback         = parameters.GetCallback(null);
            var parametersResult = parameters.ReplaceCallback(() => {
                if (this.GetComponentState() != WindowObjectState.Hiding)
                {
                    if (callback != null)
                    {
                        callback.Invoke();
                    }
                    return;
                }

                this.DoHideEnd_INTERNAL(parameters);
                if (callback != null)
                {
                    callback.Invoke();
                }
            });

            parametersResult = parametersResult.ReplaceForced(forced: true);

            this.DoHideBegin_INTERNAL(parametersResult);
        }
Beispiel #19
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);

            //}
        }
Beispiel #20
0
        public void Show(TransitionParameters parameters = default)
        {
            if (this.objectState <= ObjectState.Initializing)
            {
                Debug.LogWarning("Object is out of state: " + this, this);
                return;
            }

            if (this.hiddenByDefault == true && this.window.GetState() == ObjectState.Showing)
            {
                {
                    this.Hide(TransitionParameters.Default.ReplaceImmediately(true));
                    this.SetInvisible();
                }

                parameters.RaiseCallback();
                return;
            }

            var cbParameters = parameters.ReplaceCallback(() => {
                WindowSystem.SetShown(this, parameters);
            });

            WindowSystem.ShowInstance(this, cbParameters);
        }
Beispiel #21
0
 public static void OnDoTransition(int index, WindowBase fromScreen, int targetId, bool hide = true)
 {
     if (fromScreen != null)
     {
         WindowSystem.OnDoTransition(index, fromScreen.windowId, targetId, hide);
     }
 }
Beispiel #22
0
        public void SetInvisible()
        {
            this.isActiveSelf = false;

            var renderBehaviourOnHidden = RenderBehaviour.Nothing;

            if (this.renderBehaviourOnHidden == RenderBehaviourSettings.UseSettings)
            {
                var settings = WindowSystem.GetSettings();
                renderBehaviourOnHidden = settings.components.renderBehaviourOnHidden;
            }
            else
            {
                renderBehaviourOnHidden = (RenderBehaviour)this.renderBehaviourOnHidden;
            }

            switch (renderBehaviourOnHidden)
            {
            case RenderBehaviour.TurnOffRenderers:

                for (int i = 0; i < this.canvasRenderers.Length; ++i)
                {
                    this.canvasRenderers[i].SetCull(true);
                }

                break;

            case RenderBehaviour.HideGameObject:

                this.gameObject.SetActive(false);

                break;
            }
        }
Beispiel #23
0
        internal override void OnHideBeginInternal()
        {
            WindowSystem.SendFullCoverageOnHideBegin(this);
            WindowSystem.SendFocusOnHideBegin(this);

            base.OnHideBeginInternal();
        }
        internal void ShowInternal(TransitionParameters parameters = default)
        {
            if (this.hiddenByDefault == true || this.internalManualShow == true)
            {
                if (this.internalManualShow == false)
                {
                    this.Hide(TransitionParameters.Default.ReplaceImmediately(true));
                    this.SetInvisible();
                }

                parameters.RaiseCallback();
                return;
            }

            if (this.objectState <= ObjectState.Initializing)
            {
                Debug.LogWarning("Object is out of state: " + this, this);
                return;
            }

            var cObj         = this;
            var cParams      = parameters;
            var cbParameters = parameters.ReplaceCallbackWithContext(WindowSystem.SetShown, cObj, cParams);

            WindowSystem.ShowInstance(this, cbParameters, internalCall: true);
        }
            public bool IsValid()
            {
                var result = true;

                if (result == true && this.platform == true)
                {
                    result = false;
                    var platform = WindowSystem.GetCurrentRuntimePlatform();
                    for (int i = 0; i < this.anyOfPlatform.Length; ++i)
                    {
                        if (this.anyOfPlatform[i] == platform)
                        {
                            result = true;
                            break;
                        }
                    }
                }

                if (result == true && this.aspect == true)
                {
                    var delta      = 0.001f;
                    var aspectSize = Screen.width / (float)Screen.height;
                    var checkTo    = this.aspectFrom.x / this.aspectFrom.y;
                    var checkFrom  = this.aspectTo.x / this.aspectTo.y;

                    //Debug.LogError("---------- CHECK: " + aspectSize + " :: " + Screen.width + " :: " + Screen.height + " // " + checkFrom + " // " + checkTo);
                    result = ((aspectSize >= checkFrom - delta) && (aspectSize <= checkTo + delta));
                }

                return(result);
            }
Beispiel #26
0
        private void Awake()
        {
            WindowSystem.instance = this;

            GameObject.DontDestroyOnLoad(this.gameObject);

            this.Init();
        }
Beispiel #27
0
        public override void OnWindowInactive()
        {
            base.OnWindowInactive();

            WindowSystem.GetEvents().Raise(this, WindowEventType.OnWindowInactive);

            WindowSystem.GetHistoryTracker().Add(this, HistoryTrackerEventType.WindowInactive);
        }
Beispiel #28
0
        public virtual void Hide(TransitionParameters parameters = default)
        {
            var cbParameters = parameters.ReplaceCallback(() => {
                WindowSystem.SetHidden(this, parameters);
            });

            WindowSystem.HideInstance(this, cbParameters);
        }
Beispiel #29
0
        //private string animationTag = null;

        public override void OnInit()
        {
            WindowSystem.GetHistoryTracker().Add(this, HistoryTrackerEventType.Init);

            this.DoResetState();

            base.OnInit();
        }
Beispiel #30
0
        /// <summary>
        /// Clean up window instance.
        /// This instance would be removed from pools, and all resources will be free.
        /// </summary>
        /// <param name="instance"></param>
        public static void Clean(WindowBase instance)
        {
            instance.DoDeInit();

            var pools = WindowSystem.GetPools();

            pools.RemoveInstance(instance);
        }