コード例 #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);
        }
コード例 #2
0
        public T GetObject(TEnum objType, Transform parent, Vector3 pos, bool isLocalPos)
        {
            int typeID = Convert.ToInt32(objType);// TODO : optimize GC here

            T newObj = _pool.getObject(typeID);

            if (newObj == null && _prefabDic.ContainsKey(typeID))
            {
                newObj = GameObject.Instantiate <T>(_prefabDic[typeID]);
            }

            if (newObj != null)
            {
                newObj.transform.SetParent(parent, false);
                if (isLocalPos)
                {
                    newObj.transform.localPosition = pos;
                }
                else
                {
                    newObj.transform.position = pos;
                }
            }
            else
            {
                ZLog.error(gameObject.name, "generate type failed:", typeID.ToString());
            }

            return(newObj);
        }
コード例 #3
0
 public virtual void UnInit()
 {
     if (!HasInit)
     {
         ZLog.error("cannot UnInit twice!");
     }
     HasInit = false;
     owner   = null;
 }
コード例 #4
0
 public virtual void Init(BaseObject ownerObject)
 {
     if (HasInit)
     {
         ZLog.error("cannot Init twice!");
     }
     HasInit = true;
     owner   = ownerObject;
 }
コード例 #5
0
 public bool loadData()
 {
     if (PersistDataManager.instance.load(datafileName, loadLocation) is DATA data)
     {
         return(decoder(data, ref _owner));
     }
     else
     {
         ZLog.error("loadData fail. tag = ", datafileName);
         return(false);
     }
 }
コード例 #6
0
 /// <summary>
 /// 一次性将cache所有条目保存到某个位置,然后清除缓存。
 /// </summary>
 public void saveCacheTo(DataLocation location)
 {
     if (location == DataLocation.local)
     {
         Directory.CreateDirectory(_persistPath);                           //如果已经有了就不会创建
         string          path      = _persistPath + "/" + "cache.bytes";
         FileStream      stream    = new FileStream(path, FileMode.Create); //create new or overwritten
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(stream, _dataCache);
         _dataCache.Clear();
         stream.Close();
     }
     else if (location == DataLocation.remote)
     {
         ZLog.error("not yet");
     }
 }
コード例 #7
0
        private readonly string _streamPath = Application.streamingAssetsPath; //r

        #region public

        public void save(string tag, BaseSerializableData data, DataLocation location)
        {
            data.dataTag = tag;

            if (location == DataLocation.memory)
            {
                writeCache(tag, data);
            }
            else if (location == DataLocation.local)
            {
                writeFile(_persistPath, tag, data);
            }
            else if (location == DataLocation.remote)
            {
                ZLog.error("not yet");
            }
        }
コード例 #8
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);
        }
コード例 #9
0
        private void onFSMStop(BaseFSM fsm)
        {
            int idx = -1;

            if (_allFSMList != null && fsm != null)
            {
                idx = _allFSMList.IndexOf(fsm);
                if (idx >= 0)
                {
                    fsm.DisposeEvent -= onFSMStop;

                    if (!fsm.IsRunning)
                    {
                        _allFSMList.RemoveAt(idx);
                    }
                    else
                    {
                        ZLog.error(fsm.ToString(), "should stop before delete from list");
                    }
                }
            }
        }
コード例 #10
0
        /// <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);
            }
        }