Exemplo n.º 1
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="clearScene"></param>
        /// <returns></returns>
        public GameObject InstantiateObject(string path, bool setSceneObj = false, bool clearScene = true)
        {
            uint        crc         = CRC32.GetCRC32(path);
            ResourceObj resourceObj = GetObjectFromPool(crc);

            if (resourceObj == null)
            {
                resourceObj              = m_ResourceObjClassPool.Spawn(true);
                resourceObj.m_Crc        = crc;
                resourceObj.m_ClearScene = clearScene;
                //ResourceMgr提供加载方法
                resourceObj = ResourcesMgr.Instance.LoadResource(path, resourceObj);

                if (resourceObj.m_ResItem.m_Obj != null)
                {
                    resourceObj.m_CloneObj = GameObject.Instantiate(resourceObj.m_ResItem.m_Obj) as GameObject;
                }
            }

            if (setSceneObj)
            {
                resourceObj.m_CloneObj.transform.SetParent(SceneTrs, false);
            }

            int tempGuid = resourceObj.m_CloneObj.GetInstanceID();

            if (!m_ResourceObjDic.ContainsKey(tempGuid))
            {
                m_ResourceObjDic.Add(tempGuid, resourceObj);
            }

            return(resourceObj.m_CloneObj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加一个节点到头部
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public DoubleLinkedListNode <T> AddToHeader(T t)
        {
            DoubleLinkedListNode <T> pList = m_DoubleLinkedNodePool.Spawn(true);

            pList.next = null;
            pList.prev = null;
            pList.t    = t;
            return(AddToHeader(pList));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载单个assetbundle根据名字
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private AssetBundle LoadAssetBundle(string name)
        {
            AssetBundleItem item = null;
            uint            crc  = CRC32.GetCRC32(name);

            if (!m_AssetBundleItemDic.TryGetValue(crc, out item))
            {
                AssetBundle assetBundle = null;
                string      fullPath    = ABLoadPath + name;
                assetBundle = AssetBundle.LoadFromFile(fullPath);
                if (assetBundle == null)
                {
                    ZLogger.Error(" load assetbundle Error : {0}", fullPath);
                }

                item             = m_AssetBundleItemPool.Spawn(true);
                item.assetBundle = assetBundle;
                item.RefCount++;
                m_AssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.RefCount++;
            }
            return(item.assetBundle);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 异步加载资源(仅仅是不需要实例化的资源,例如texture,音频等等)
        /// </summary>
        public void AsyncLoadResource(string path, OnAsyncObjFinish dealFinish, LoadResPriority priority, bool isSprite = false, object param1 = null,
                                      object param2 = null, object param3 = null, uint crc = 0)
        {
            if (crc == 0)
            {
                crc = CRC32.GetCRC32(path);
            }

            ResourceItem item = GetCacheResourceItem(crc);

            if (item != null)
            {
                if (dealFinish != null)
                {
                    dealFinish(path, item.m_Obj, param1, param2, param3);
                }
                return;
            }

            //判断是否在加载中
            AsynvLoadResParam para = null;

            if (!m_LodingAssetDic.TryGetValue(crc, out para) || para == null)
            {
                para             = m_AsyncLoadResParamPool.Spawn(true);
                para.m_Crc       = crc;
                para.m_Path      = path;
                para.m_SpriteBoo = isSprite;
                para.m_Priority  = priority;
                m_LodingAssetDic.Add(crc, para);
                m_LoadingAssetList[(int)priority].Add(para);
            }

            //往回调列表里加回调
            //这里加的是不针对的回调
            ResMgrAsyncCallBack callBack = m_AsyncCallBackPool.Spawn(true);

            callBack.m_ResDealFinish = dealFinish;
            callBack.m_Param1        = param1;
            callBack.m_Param2        = param2;
            callBack.m_Param3        = param3;
            para.m_CallBackList.Add(callBack);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 从对象池中取出T对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxcount"></param>
        /// <returns></returns>
        public T NewClassObjectFromPool <T>(int maxcount) where T : class, new()
        {
            ClassObjectPool <T> pool = GetOrCreateClassPool <T>(maxcount);

            if (pool == null)
            {
                return(null);
            }
            return(pool.Spawn(true));
        }
Exemplo n.º 6
0
        void LoadBgAssetFinish(string path, Object obj, object param1 = null, object param2 = null, object param3 = null)
        {
            uint     tempCrc = CRC32.GetCRC32(path);
            AudioObj tempObj = AudioObjClassPool.Spawn(true);

            tempObj.m_AudioClip  = obj as AudioClip;
            tempObj.m_ClearScene = (bool)param1;
            AudioAssetDic.Add(tempCrc, tempObj);
            bgAudio.clip   = tempObj.m_AudioClip;
            bgAudio.volume = bgAudioVolume;
            bgAudio.loop   = (bool)param2;
            if (bgAudioVolume > 0f)
            {
                bgAudio.Play();
            }
            else
            {
                bgAudio.Stop();
            }
        }
Exemplo n.º 7
0
        public void PlayEffectAudio(string musicName, bool is3DBoo, Vector3 canVector3, Transform canTrs = null, bool isLoopBoo = false, bool clearScene = false)
        {
            string   tempPath = MUSIC_PATH + musicName;
            uint     tempCrc  = CRC32.GetCRC32(tempPath);
            AudioObj tempAudioObj;

            if (AudioAssetDic.TryGetValue(tempCrc, out tempAudioObj) && tempAudioObj != null)
            {
                EffectAudioPrefab tempEffectPrefabObj;
                if (EffectAudioRecyclePool.Count > 0)
                {
                    tempEffectPrefabObj = EffectAudioRecyclePool.Dequeue();
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    tempEffectPrefabObj.m_AudioTrs.transform.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou.spatialBlend            = is3DBoo ? 1 : 0;
                    tempEffectPrefabObj.m_AudioSou.clip   = tempAudioObj.m_AudioClip;
                    tempEffectPrefabObj.m_AudioSou.volume = EffectAudioVolume;
                    tempEffectPrefabObj.m_AudioSou.loop   = isLoopBoo;
                    if (EffectAudioVolume > 0f)
                    {
                        tempEffectPrefabObj.m_AudioSou.Play();
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioSou.Stop();
                    }
                    tempEffectPrefabObj.m_UsingBoo = true;
                    EffectAudioDic.Add(tempEffectPrefabObj.m_guid, tempEffectPrefabObj);
                }
                else
                {
                    tempEffectPrefabObj        = EffectAudioClassPool.Spawn(true);
                    tempEffectPrefabObj.m_guid = GetEffectAudioGuid();
                    GameObject tempObj = new GameObject(tempEffectPrefabObj.m_guid + "_Stage");
                    tempEffectPrefabObj.m_AudioTrs = tempObj.transform;
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(SoundStageTrs, false);
                    }
                    tempEffectPrefabObj.m_AudioTrs.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou = tempObj.AddComponent <AudioSource>();
                    tempEffectPrefabObj.m_AudioSou.spatialBlend = is3DBoo ? 1 : 0;
                    tempEffectPrefabObj.m_AudioSou.volume       = EffectAudioVolume;
                    tempEffectPrefabObj.m_AudioSou.clip         = tempAudioObj.m_AudioClip;
                    tempEffectPrefabObj.m_AudioSou.loop         = isLoopBoo;
                    if (EffectAudioVolume > 0f)
                    {
                        tempEffectPrefabObj.m_AudioSou.Play();
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioSou.Stop();
                    }
                    tempEffectPrefabObj.m_UsingBoo = true;
                    EffectAudioDic.Add(tempEffectPrefabObj.m_guid, tempEffectPrefabObj);
                    CoroutineMgr.Instance.StartCoroutine(tempEffectPrefabObj.m_guid, EffectAudioTimerCor(tempEffectPrefabObj.m_guid));
                }
            }
            else
            {
                EffectAudioPrefab tempEffectPrefabObj;
                if (EffectAudioRecyclePool.Count > 0)
                {
                    tempEffectPrefabObj = EffectAudioRecyclePool.Dequeue();
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    tempEffectPrefabObj.m_AudioTrs.transform.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou.spatialBlend            = is3DBoo ? 1 : 0;
                }
                else
                {
                    tempEffectPrefabObj        = EffectAudioClassPool.Spawn(true);
                    tempEffectPrefabObj.m_guid = GetEffectAudioGuid();
                    GameObject tempObj = new GameObject(tempEffectPrefabObj.m_guid + "_Stage");
                    tempEffectPrefabObj.m_AudioTrs = tempObj.transform;
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(SoundStageTrs, false);
                    }
                    tempEffectPrefabObj.m_AudioTrs.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou = tempObj.AddComponent <AudioSource>();
                    tempEffectPrefabObj.m_AudioSou.spatialBlend = is3DBoo ? 1 : 0;
                }
                ResourcesMgr.Instance.AsyncLoadResource(tempPath, LoadEffectAssetFinish, LoadResPriority.RES_HIGHT, false, clearScene, isLoopBoo, tempEffectPrefabObj);
            }
        }