Example #1
0
        public void SetState <T>(T state)
        {
#if LOG_DEBUG
            Debug.Log(string.Format("PRESENT<{0}={1:X8}>:STATE:{2}",
                                    this.GetType().Name,
                                    (uint)this.GetHashCode(),
                                    state));
#endif// LOG_DEBUG
#if LOG_MEMORY
            var presentType    = Present.IsOpened ? Present.CurrentPresentType : null;
            var stateOfPresent = state.GetHashCode();
            Debug.Log(string.Format("APP:{0}, {1}, {2}",
                                    DebugImpl.CreateUptimeChunk(),
                                    DebugImpl.CreatePresentChunk("AT", presentType, stateOfPresent),
                                    DebugImpl.CreatePresentChunk("EVENT:SET_STATE_PREV", presentType, this.GetState())));
#endif// LOG_MEMORY
            this.fsm.SetState(state);
        }
Example #2
0
            internal void OpenNextPresent(Type presentType, LoadRuleData rule, object openArg, Action callback)
            {
                if (null == rule)
                {
                    rule = Present.DefaultLoadRule;
                }

#if LOG_DEBUG
                Debug.Log(string.Format("PRESENT<{0}={1:X8}>:NEXT:{2}, RULE:{3}, ARG:{4}, CB:{5}, STACK_TRACE:\n{6}",
                                        this.CurrentPresentName,
                                        (uint)this.CurrentPresentHashCode,
                                        null != presentType ? presentType.Name : "null",
                                        rule,
                                        openArg,
                                        callback,
                                        new System.Diagnostics.StackTrace(true).ToString()));
#endif// LOG_DEBUG
#if LOG_MEMORY
                var stateOfPresent = null != this.loadedPresent ? this.loadedPresent.GetState() : -1;
                Debug.Log(string.Format("APP:{0}, {1}, {2}",
                                        DebugImpl.CreateUptimeChunk(),
                                        DebugImpl.CreatePresentChunk("AT", presentType, -1),
                                        DebugImpl.CreatePresentChunk("EVENT:SET_PRESENT_PREV", this.presentType, stateOfPresent)));
#endif// LOG_MEMORY

                this.ClosePresent(presentType);

                if (null != this.asyncOperFakeOpenForGarbageCollect || null != this.asyncOper || this.fastOpenWait)
                {
#if LOG_DEBUG
                    Debug.Log(string.Format("PRESENT<{0}={1:X8}>:NEXT_DUPLICATED:{2}",
                                            this.CurrentPresentName,
                                            (uint)this.CurrentPresentHashCode,
                                            null != presentType ? presentType.Name : "null"));
#endif// LOG_DEBUG
                    this.OpenPresentWait(presentType, rule, openArg, callback);
                    return;
                }
                else if (null != this.wait)
                {
                    Debug.LogError(string.Format("PRESENT<{0}={1:X8}>:NEXT_DUPLICATED_EXCEPTION#2:{2}, RULE:{3}, ARG:{4}, CB{5}, WAIT:{6}, CURRENT:{7}",
                                                 this.CurrentPresentName,
                                                 (uint)this.CurrentPresentHashCode,
                                                 null != presentType ? presentType.Name : "null",
                                                 rule,
                                                 openArg,
                                                 callback,
                                                 this.wait,
                                                 this.presentType));
                    return;
                }

                this.presentTypePrev = this.presentType;
                this.presentType     = presentType;

                this.openArg = openArg;

                this.openCallback = callback;
                this.isChanging   = true;

                Preference.Save();
                this.preloadPresent = (Present)Activator.CreateInstance(this.presentType);
#if LOG_DEBUG
                Debug.Log(string.Format("PRESENT<{0}={1:X8}>:CREATE_INSTANCE:<{2}={3:X8}>",
                                        this.CurrentPresentName,
                                        (uint)this.CurrentPresentHashCode,
                                        null != this.preloadPresent ? this.preloadPresent.GetType().Name : "null",
                                        null != this.preloadPresent ? (uint)this.preloadPresent.GetHashCode() : 0u));
#endif// LOG_DEBUG
                try
                {
                    this.preloadPresent.OnPreloading();
                }
                catch (Exception e)
                {
                    Debug.LogError(string.Format("PRESENT<{0}={1:X8}>:LOAD_EXCEPT:{2}",
                                                 this.CurrentPresentName,
                                                 (uint)this.CurrentPresentHashCode,
                                                 e));
                }

                switch (rule.Rule)
                {
                case LoadRule.FlushGarbage:
                    this.asyncOperFakeOpenForGarbageCollect = SceneManager.LoadSceneAsync("Next");
                    break;

                case LoadRule.Direct:
                    if (this.preloadPresent.DoOpen)
                    {
                        this.asyncOper = SceneManager.LoadSceneAsync(this.presentType.Name);
                    }
                    else
                    {
                        this.fastOpenWait = true;
                    }
                    break;

                case LoadRule.PreloadedScene:
                    this.asyncOper = rule.Preloaded;
                    break;
                }
            }