Beispiel #1
0
        public BaseSerializableData load(string tag, DataLocation location)
        {
            BaseSerializableData data = null;

            if (location == DataLocation.memory)
            {
                if (!readCache(tag, out data))
                {
                    ZLog.log("TODO: cache miss, read from file");
                }
            }
            else if (location == DataLocation.local)
            {
                if (!readFile(_persistPath, tag, out data))
                {
                    ZLog.warn("TODO: file miss, read from net");
                }
            }
            else if (location == DataLocation.remote)
            {
                ZLog.error("not yet");
            }

            return(data);
        }
 public void removeListener(EventID eventID, EventHandler handler)
 {
     if (registeredListener.ContainsKey(eventID))
     {
         registeredListener.Remove(eventID);
         EventDispatcher.Instance.RemoveListener(eventID, ID, handler);
     }
     else
     {
         ZLog.warn(eventID.ToString() + " does not register handler:" + handler.ToString());
     }
 }
 public void addListener(EventID eventID, EventHandler handler)
 {
     if (registeredListener.ContainsKey(eventID))
     {
         ZLog.warn("Fail to addListener. one eventID to one handler");
     }
     else
     {
         registeredListener.Add(eventID, handler);
         EventDispatcher.Instance.AddListener(eventID, ID, handler);
     }
 }
        private void DoNextAction()
        {
            if (_actionSequence.Count > 0)
            {
                ActionItem item = _actionSequence.Peek();
                _actionSequence.Dequeue();

                ZLog.log($"[{GetInstanceID().ToString()}] dequeue:{item.ToString()}");

                // exceptions may raise, but ActionSequence should keep operating.
                try
                {
                    if (item.funcWithParamAndCallBack != null)
                    {
                        item.funcWithParamAndCallBack(item.param, item.func);
                        FinishOne();
                    }
                    else if (item.funcWithParam != null)
                    {
                        item.funcWithParam(item.param);
                        FinishOne();
                    }
                    else if (item.func != null)
                    {
                        item.func();
                        FinishOne();
                    }
                    else if (item.coroutine != null)
                    {
                        StartCoroutine(DoItemCoroutine(item));
                    }
                    else if (item.yieldInstruction != null)
                    {
                        StartCoroutine(DoItemYieldInstruction(item));
                    }
                    else if (item.customYield != null)
                    {
                        StartCoroutine(DoItemCustomYieldInstruction(item));
                    }
                }
                catch (Exception e)
                {
                    ZLog.warn(e.ToString());
                    OnFinished?.Invoke(this);
                }
            }
            else
            {
                OnFinished?.Invoke(this);
            }
        }
        public bool CanPassTypeTest(CollisionAbility me, CollisionAbility other)
        {
            if (me == null || other == null)
            {
                return(false);
            }

            if (_collisionConfig != null)
            {
                return(_collisionConfig[(int)me.Type, (int)other.Type]);
            }
            else
            {
                ZLog.warn("no collison config file attached.");
                return(true);
            }
        }
Beispiel #6
0
        /// <summary>
        /// change state immediately with some data
        /// </summary>
        public void ChangeState(BaseState <T, M> newState, object param = null)
        {
            if (!IsRunning)
            {
                ZLog.error("Cannot change state, FSM is not runnning");
                return;
            }

            if (newState == null)
            {
                ZLog.error(_owner.ToString(), "cannot change state to null");
                return;
            }
            if (_lastSate == null || _curState == null)
            {
                ZLog.error(_owner.ToString(), "Fatal error: _lastSate || _curState = null, newState=", newState.ToString());
                return;
            }

            if (newState.GetType().Equals(_curState.GetType()))
            {
                ZLog.warn(_owner.ToString(), "cannot change to the same state:", _curState.ToString());
                return;
            }

            if (_owner == null)
            {
                ZLog.error("_owner = null");
                return;
            }

            _lastSate = _curState;
            _curState = newState;

            ZLog.verbose(_owner.ToString() + ": " + _lastSate.ToString() + " -> " + _curState.ToString());

            _lastSate.Exit(_owner);
            _curState.Enter(_owner, param);
        }
        /// <summary>
        /// call this rather than destroy.
        /// </summary>
        protected void Dispose()
        {
            if (!HasInit)
            {
                ZLog.warn(gameObject.name, "has't Init. Dispose() makes no sense."); return;
            }

            if (DisposeEvent != null)
            {
                if (DisposeEvent.GetInvocationList().Length > 1)
                {
                    ZLog.error(gameObject.name, "disposeEvent should only have one listener(Manager)");
                }

                DisposeEvent(GUID);
            }
            else
            {
                ZLog.warn(gameObject.name, "no manager attached, destroy itself");
                UnInit();
                Destroy(gameObject);
            }
        }