public void AddMixed()
        {
            const string expression = "A.base + B - C * D / E + 1 - 2 * 3 / 4";

            _statService.Add("B");
            _statService.Add("C");
            _statService.Add("D");
            _statService.Add("E");

            _statService.Add("A", expression).Should().BeEmpty();

            _statService.Get("A").ToString().Should().Be($"[0, {expression}]");
        }
Пример #2
0
 public void Dump()
 {
     foreach (var asset in m_hashAssetDic.Values)
     {
         StatService.Get().LogStat("AssetDump", asset.ToString(), "");
     }
 }
Пример #3
0
        public GameObject Instantiate(Transform parent, bool stayWorldPosition)
        {
            GameObject go;

            if (m_pool == null)
            {
                go = Object.Instantiate(UnityObject, parent, stayWorldPosition) as GameObject;
                var direct = go.AddComponent <DirectDestroyGO>();
                direct.PrefabAsset = this;
                direct.Instantiated();
            }
            else
            {
                go = m_pool.Get(parent, stayWorldPosition);
                var cached = go.GetComponent <PoolCacheGO>();
                cached.Instantiated();
            }

            if (m_autoRecyclePrefab)
            {
                var autoRecycle = go.GetComponent <AutoRecycle>();
                autoRecycle.ResetAll();
            }

            StatService.Get().Increase(StatService.StatName.IN_USE_GO, 1);
#if UNITY_EDITOR
            StatService.Get().LogStat("Instantiate", UnityObject.name, m_transformCount);
#endif

#if UNITY_DEBUG
            var service = CSharpServiceManager.Get <AssetFullStatService>(CSharpServiceManager.ServiceType.ASSET_FULL_STAT);
            service.OnInstantiateGameObject(go);
#endif
            return(go);
        }
Пример #4
0
        private GameObject GetFromCache()
        {
            if (m_cached.Count > 0)
            {
                var go = m_cached[0];
                m_cached.RemoveSwapAt(0);
                StatService.Get().Increase(StatService.StatName.IN_POOL_GO, -1);
                return(go);
            }

            return(null);
        }
Пример #5
0
        public static void Recycle(GameObject go)
        {
            var cache = go.GetComponent <AssetServiceManagedGO>();

#if UNITY_DEBUG
            if (!cache)
            {
                Debug.LogError($"Recycle a destroy go : {go.name}");
                return;
            }
#endif
            cache.Recycle();
            StatService.Get().Increase(StatService.StatName.IN_USE_GO, -1);
        }
Пример #6
0
        public override void Destroy()
        {
            if (Status == AssetStatus.DONE)
            {
                StatService.Get().Increase(StatService.StatName.ASSET_COUNT, -1);
#if UNITY_DEBUG
                var service = CSharpServiceManager.Get <AssetFullStatService>(CSharpServiceManager.ServiceType.ASSET_FULL_STAT);
                service.OnAssetUnloaded(this);
#endif
            }
            Status      = AssetStatus.DESTROYED;
            UnityObject = null;
            RefAssetBundle?.Release();
            RefAssetBundle = null;
        }
Пример #7
0
        public virtual void SetAsset(Object unityObj, AssetBundleInstance refAssetBundle)
        {
            UnityObject = unityObj;
            if (refAssetBundle != null)
            {
                RefAssetBundle = refAssetBundle;
                RefAssetBundle.IncRef();
            }
            Status = UnityObject ? AssetStatus.DONE : AssetStatus.FAIL;
            if (Status == AssetStatus.DONE)
            {
                StatService.Get().Increase(StatService.StatName.ASSET_COUNT, 1);
                CreateTime = Time.realtimeSinceStartup;
#if UNITY_DEBUG
                var service = CSharpServiceManager.Get <AssetFullStatService>(CSharpServiceManager.ServiceType.ASSET_FULL_STAT);
                service.OnAssetLoaded(this);
#endif
            }
        }
Пример #8
0
        public void Update()
        {
            if (m_cached.Count == 0)
            {
                return;
            }

            if (m_cached.Count <= PreferSize)
            {
                return;
            }

            if (Time.time - m_cacheStart > 30)
            {
                Object.Destroy(m_cached[0]);
                StatService.Get().Increase(StatService.StatName.IN_POOL_GO, -1);
                m_cached.RemoveSwapAt(0);
            }
        }
Пример #9
0
        private IEnumerable <string> SetVariable(Node node, ParsingContext context)
        {
            if (node.Value[0] == '.')
            {
                return new[] { $"Can not use shorthand variable name ({node.Value})" }
            }
            ;                                                                                           //TODO better msg

            var variableId             = new VariableId(node.Value);
            var variableExpressionNode = node.Children.First();

            var errors = _parser.Parse(out var expression, variableExpressionNode.Value, context).FormatErrors(variableExpressionNode).ToList();

            if (errors.Any())
            {
                return(errors);
            }

            _statService.Get(variableId.StatId).AddOrUpdateVariable(variableId, expression !);

            return(Enumerable.Empty <string>());
        }
Пример #10
0
        public void Cache(GameObject go)
        {
            if (m_cached.Count == 0)
            {
                m_cacheStart = Time.time;
            }

                        #if UNITY_DEBUG
            if (m_cached.Contains(go))
            {
                throw new Exception($"GameObject exist in pool {go.name}");
            }
                        #endif

            if (m_cached.Count >= MaxSize)
            {
                Object.Destroy(go);
                return;
            }

            go.transform.SetParent(PoolNode, false);
            StatService.Get().Increase(StatService.StatName.IN_POOL_GO, 1);
            m_cached.Add(go);
        }
Пример #11
0
 public void Dispose()
 {
     StatService.Get().Increase(StatService.StatName.IN_POOL_GO, -m_cached.Count);
     m_cached.Clear();
     Object.Destroy(PoolNode.gameObject);
 }
Пример #12
0
 public void ImportStatWithVariable()
 {
     _book.Populate("FOR { .var: 33\n expr: 2\n }").Should().BeEmpty();
     _statService.GetValue("FOR").Should().Be(2);
     _statService.Get("FOR").TryGetVariable(new VariableId("FOR.var")).Should().Be(33);
 }