Esempio n. 1
0
 public void Update(string key, CacheBlock block)
 {
     lock (Locker)
     {
         CachePool.Update(key, block);
     }
 }
Esempio n. 2
0
 public void Clear()
 {
     lock (Locker)
     {
         CachePool.Clear();
     }
 }
Esempio n. 3
0
    public static void PlayAudioOneShot(AudioSource audioSource, int soundId, float volume = 1f)
    {
        if (_globalAudioVolume <= 0 || _audioVolume <= 0)
        {
            return;
        }

        SoundDeploy deploy = _soundTableT.GetSection(soundId);

        if (!deploy || string.IsNullOrEmpty(deploy.resource))
        {
            return;
        }

        AudioClip resource;

        if (CachePool.TryGetValue(deploy.resource, out resource))
        {
            PlayAudioOneShot(audioSource, resource, volume, deploy.volume);
        }
        else
        {
            RLoadPlayAudioOneShot(deploy.resource, audioSource, volume, deploy.volume);
        }
    }
Esempio n. 4
0
    private static void RLoadPlayAudioOneShot(string soundName, AudioSource audioSource, float volume = 1f, float gvolume = 1f)
    {
        AudioClip resource;

        ResourceMgr.Load(soundName, _object =>
        {
            resource = _object as AudioClip;
            if (resource != null)
            {
                if (!CachePool.ContainsKey(soundName))
                {
                    CachePool.Add(soundName, resource);
                }

                if (audioSource != null)
                {
                    PlayAudioOneShot(audioSource, resource, volume, gvolume);
                }
            }
            else
            {
                Debug.LogError(string.Format("The AudioClip[resource={0}] is null.", resource));
            }
        });
    }
Esempio n. 5
0
 public void RemoveAll(Predicate <CacheBlock> pre)
 {
     lock (Locker)
     {
         CachePool.RemoveAll(pre);
     }
 }
Esempio n. 6
0
 public CacheBlock GetCache(string key)
 {
     lock (Locker)
     {
         return(CachePool.Get(key));
     }
 }
Esempio n. 7
0
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
        protected override void Awake()
        {
            ThreadCache = new CachePool <InnerThread>(new RunningPool <InnerThread>(), new Threads());
            semaphore   = new Semaphore(maxThreads, ThreadCount);

            CacheArgs   = new Queue <ThreadArgs>();
            RunningArgs = new Queue <ThreadArgs>();
        }
Esempio n. 8
0
 public void RemoveInternal <_T0>(IntrusiveCollection <_T0> list)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(list == pool.GetDirectiveList());
     this.pool = null;
     this.prev = null;
     this.next = null;
 }
Esempio n. 9
0
 public static void UnloadSoundAsset(AudioSource audioSource, int soundId)
 {
     if (audioSource != null)
     {
         SoundDeploy deploy = _soundTableT.GetSection(soundId);
         CachePool.Remove(deploy.resource);
         Resources.UnloadAsset(audioSource.clip);
     }
 }
Esempio n. 10
0
 public static void FadeOutMusic(float fade = 1f)
 {
     if (_music != null && _music.AudioSource != null)
     {
         CachePool.Remove(_music.Resources);
         Resources.UnloadAsset(_music.AudioSource.clip);
         Object.Destroy(_music.AudioSource.gameObject);
     }
 }
Esempio n. 11
0
        public override void Remove(CacheItem item, string key, bool isMainSlbServer = true)
        {
            var cacheKey = GenerateCacheKey(item, key);

            if (CachePool.Contains(cacheKey))
            {
                CachePool.Remove(cacheKey);
            }
        }
Esempio n. 12
0
 public void DrawConnectLine(RuntimePort A, RuntimePort B)
 {
     CachePool.I().GetObject("Prefabs/Line", (obj) =>
     {
         obj.transform.SetParent(RuntimeGraph.I().LineGroup, false);
         RuntimeLine line = obj.GetComponent <RuntimeLine>();
         line.Draw(A, B);
     });
 }
Esempio n. 13
0
 public static void StopEnvironmentMusic(float fade = 3f)
 {
     if (_environment != null && _environment.AudioSource != null)
     {
         CachePool.Remove(_environment.Resources);
         Resources.UnloadAsset(_environment.AudioSource.clip);
         Object.Destroy(_environment.AudioSource.gameObject);
     }
 }
Esempio n. 14
0
 public override void ClearAll()
 {
     lock (Padlock)
     {
         foreach (var cacheItem in CachePool)
         {
             CachePool.Remove(cacheItem.Key);
         }
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Get a snaphot from the pool for a particular cache.
        /// </summary>
        public void DiposeSnapshot(string pointerID, CacheBase cache)
        {
            CachePool pool = null;

            if (_cachePoolMap.Contains(cache.Context.CacheRoot.Name))
            {
                pool = _cachePoolMap[cache.Context.CacheRoot.Name] as CachePool;
                pool.DiposeSnapshotInPool(pointerID);
            }
        }
Esempio n. 16
0
 public static void StopMusic()
 {
     if (_music != null && _music.AudioSource != null)
     {
         CachePool.Remove(_music.Resources);
         Resources.UnloadAsset(_music.AudioSource.clip);
         Object.Destroy(_music.AudioSource.gameObject);
         _music.AudioSource = null;
     }
 }
Esempio n. 17
0
        public override object Get(CacheItem item, string key, MethodInfo methodInfo)
        {
            var cacheKey = GenerateCacheKey(item, key);

            if (CachePool.Contains(cacheKey))
            {
                return((object)CachePool[cacheKey]);
            }
            return(null);
        }
Esempio n. 18
0
 //
 // IntrusiveCollection.Element implementation
 //
 public void InsertInternal <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                                  prev, IntrusiveCollection.Element next)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(this.pool == null);
     this.pool = ((CachePool.DirectiveList)list).GetCachePool();
     this.prev = prev;
     this.next = next;
 }
Esempio n. 19
0
 public override void ClearItem(CacheItem item, bool isMainSlbServer = true)
 {
     lock (Padlock)
     {
         foreach (var cacheItem in CachePool.Where(p => p.Key.StartsWith(item.ToString())))
         {
             CachePool.Remove(cacheItem.Key);
         }
     }
 }
Esempio n. 20
0
 public void GetInputer(string Type, string Name, object Value)
 {
     CachePool.I().GetObject("Prefabs/Content/" + Type, (obj) =>
     {
         obj.transform.SetParent(ContentParent, false);
         Inputer inputer = obj.GetComponent <Inputer>();
         inputer.SetLabel(Name);
         inputer.SetValue(Value);
         BaseInputer.Add(Name, inputer);
     });
 }
        void NextMenu(MenuItem item)
        {
            for (int i = 0; i < transform.childCount; i++)
            {
                //TODO: Change to put object
                if (transform.GetChild(i).name != "Label")
                {
                    Destroy(transform.GetChild(i).gameObject);
                }
            }

            if (item.father != null)
            {
                CachePool.I().GetObject("Prefabs/Context/BackButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    MenuItem next             = item;
                    rcItem.AddAction(() => {
                        Label.text = Label.text.Substring(0, Label.text.Length - new StringBuilder("/").Append(item.name).ToString().Length);
                        NextMenu(next.father);
                    });
                });
            }

            for (int i = 0; i < item.SubItems.Count; i++)
            {
                CachePool.I().GetObject("Prefabs/Context/ContextButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    rcItem.SetLabel(Item.SubItems[i].name);
                    MenuItem nextItem = Item.SubItems[i];
                    MenuItem cur      = item;
                    rcItem.AddAction(() => {
                        nextItem.father = cur;
                        Label.text     += new StringBuilder("/").Append(nextItem.name).ToString();
                        NextMenu(nextItem);
                    });
                });
            }

            foreach (var key in item.ActualItem.Keys)
            {
                CachePool.I().GetObject("Prefabs/Context/ActualButton", (obj) =>
                {
                    obj.transform.SetParent(transform, false);
                    RightClickMenuItem rcItem = obj.GetComponent <RightClickMenuItem>();
                    rcItem.SetLabel(key);
                    rcItem.AddAction(item.ActualItem[key]);
                });
            }
        }
Esempio n. 22
0
    private static void LoadPlayAudio(string soundName, AudioSource audioSource, float volume, bool loop, Action playCallBack)
    {
        AudioClip resource;

        if (CachePool.TryGetValue(soundName, out resource))
        {
            DoPlayAudio(audioSource, resource, volume, loop, playCallBack);
        }
        else
        {
            RLoadPlayAudio(soundName, audioSource, volume, loop, playCallBack);
        }
    }
Esempio n. 23
0
        static ThreadPool()
        {
            ThreadCache = new CachePool <IFThread>(new RunningPool <IFThread>(), new IFThreads());
            ArgCache    = new CachePool <IFThreadArg>(new RunningPool <IFThreadArg>(), new IFThreadArgPool());
            eve         = new ManualResetEvent(false);

            CacheArgs   = new Queue <IFThreadArg>();
            RunningArgs = new Queue <IFThreadArg>();

            ctrolThread = new Thread(ThreadLoop);
            ctrolThread.IsBackground = true;
            ctrolThread.Start();
        }
Esempio n. 24
0
 public static void ClearSoundCache()
 {
     if (!GameSetting.CacheSound)
     {
         var e = CachePool.GetEnumerator();
         using (e)
         {
             while (e.MoveNext())
             {
                 Resources.UnloadAsset(e.Current.Value);
             }
         }
         CachePool.Clear();
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Get a snaphot from the pool
        /// </summary>
        /// <param name="pointerID"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public Array GetSnaphot(string pointerID, CacheBase cache)
        {
            CachePool pool = null;

            if (_cachePoolMap.Contains(cache.Context.CacheRoot.Name))
            {
                pool = _cachePoolMap[cache.Context.CacheRoot.Name] as CachePool;
                return(pool.GetSnaphotInPool(pointerID, cache));
            }
            else
            {
                pool = new CachePool(_minSnaphotSizeForPooling, _maxSnapshotsInPool, _newSnapshotCreationThreshold);
                _cachePoolMap.Add(cache.Context.CacheRoot.Name, pool);
            }
            return(pool.GetSnaphotInPool(pointerID, cache));
        }
Esempio n. 26
0
        /// <summary>
        /// Get a snaphot from the pool
        /// </summary>
        /// <param name="pointerID"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public Array GetSnaphot(string pointerID, CacheBase cache)
        {
            CachePool pool = null;

            if (_cachePoolMap.Contains(cache.Context.CacheRoot.Name))
            {
                pool = _cachePoolMap[cache.Context.CacheRoot.Name] as CachePool;
                return(pool.GetSnaphotInPool(pointerID, cache));
            }
            else
            {
                pool = new CachePool();
                _cachePoolMap.Add(cache.Context.CacheRoot.Name, pool);
            }
            return(pool.GetSnaphotInPool(pointerID, cache));
        }
Esempio n. 27
0
        public override void Set(CacheItem item, string key, object data, int second = 0)
        {
            if (data == null)
            {
                return;
            }
            var cacheKey = GenerateCacheKey(item, key);

            if (CachePool.Contains(cacheKey))
            {
                CachePool[cacheKey] = data;
            }
            else
            {
                CachePool.Add(cacheKey, data, GetPolicy(second));
            }
        }
Esempio n. 28
0
    private static void RLoadPlayAudio(string soundName, AudioSource audioSource, float volume, bool loop, Action playCallBack)
    {
        AudioClip resource;

        ResourceMgr.Load(soundName, _object =>
        {
            resource = _object as AudioClip;
            if (resource)
            {
                if (!CachePool.ContainsKey(soundName))
                {
                    CachePool.Add(soundName, resource);
                }

                DoPlayAudio(audioSource, resource, volume, loop, playCallBack);
            }
            else
            {
                Debug.LogError("加载声音失败:" + soundName);
            }
        });
    }
Esempio n. 29
0
        IEnumerator IE_Load()
        {
            //Load All Nodes
            for (int i = 0; i < graph.Node.Count; i++)
            {
                CachePool.I().GetObject("Prefabs/NodeBase", (obj) =>
                {
                    obj.transform.SetParent(NodeGroup, false);
                    RuntimeNode rnode = obj.GetComponent <RuntimeNode>();
                    rnode.Load(graph.Node[i]);
                    Nodes.Add(rnode);
                });
            }

            //Connect All Ports
            for (int i = 0; i < Nodes.Count; i++)
            {
                Nodes[i].Connect();
            }
            yield return(null);

            Save();
        }
Esempio n. 30
0
 public RollObj()
 {
     list = new ArrayList();
     size = new S();
     pool = new CachePool <GameObject, Args, T>();
 }
Esempio n. 31
0
        /// <summary>
        /// Get a snaphot from the pool 
        /// </summary>
        /// <param name="pointerID"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public Array GetSnaphot(string pointerID, CacheBase cache)
        {
            CachePool pool = null;

            if (_cachePoolMap.Contains(cache.Context.CacheRoot.Name))
            {
                pool = _cachePoolMap[cache.Context.CacheRoot.Name] as CachePool;
                return pool.GetSnaphotInPool(pointerID, cache);
            }
            else
            {
                pool = new CachePool(_minSnaphotSizeForPooling, _maxSnapshotsInPool, _newSnapshotCreationThreshold);
                _cachePoolMap.Add(cache.Context.CacheRoot.Name, pool);

            }
            return pool.GetSnaphotInPool(pointerID, cache);
        }