Beispiel #1
0
        /// <summary>
        /// 不需要实例化的资源的卸载,根据对象(比如Sprite,Texture)
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="destoryObj"></param>
        /// <returns></returns>
        public bool ReleaseResouce(Object obj, bool destoryObj = false)
        {
            if (obj == null)
            {
                return(false);
            }
            //根据GUID查找资源
            ResInfo item = null;

            foreach (ResInfo res in mResDictionary.Values)
            {
                if (res.mGUID == obj.GetInstanceID())
                {
                    item = res;
                }
            }

            if (item == null)
            {
                AFLogger.e("mResDictionary里不存在改资源:" + obj.name + "  可能释放了多次");
                return(false);
            }
            //destoryObj为false : 不释放destoryObj,只是将item放在前面去
            DestoryResouceItme(item, destoryObj);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 异步加载
        /// </summary>
        /// <param name="finishCallback"></param>
        /// <returns></returns>
        public override IEnumerator DoLoadAsync(System.Action <uint> finishCallback)
        {
            ResourceRequest resourcesRequest;

            if (isSprite)
            {
                resourcesRequest = Resources.LoadAsync <Sprite>(mResPath);
            }
            else
            {
                resourcesRequest = Resources.LoadAsync(mResPath);
            }
            mResourceRequest = resourcesRequest;
            yield return(resourcesRequest);

            if (!resourcesRequest.isDone)
            {
                AFLogger.e("Failed to Load Resources:" + mResPath);
                OnResLoadFaild();
                mListener.InvokeGracefully(false, this);
                finishCallback(mCRC);
                yield break;
            }

            mAsset    = resourcesRequest.asset;
            mResState = ResState.Ready;
            mListener.InvokeGracefully(true, this);
            finishCallback(mCRC);
        }
Beispiel #3
0
        //同步加载资源
        public override bool LoadSync()
        {
            if (mResPath.IsNullOrEmpty())
            {
                AFLogger.e("加载路径不能为空");
                return(false);
            }

            mResState = ResState.Loading;
            if (isSprite)
            {
                mAsset = LoadAssetByEditor <Sprite>(mResPath);
            }
            else
            {
                mAsset = LoadAssetByEditor <Object>(mResPath);
            }
            if (mAsset.IsNull())
            {
                AFLogger.e("加载Editor Res资源为null,请检查路径:" + mResPath);
                mResState = ResState.Waiting;
            }
            else
            {
                mResState = ResState.Ready;
            }
            return(mAsset != null);
        }
Beispiel #4
0
        public override IEnumerator DoLoadAsync(System.Action <uint> finishCallback)
        {
            if (mResPath.IsNullOrEmpty())
            {
                AFLogger.e("加载路径不能为空");
            }
            ProcessEditor = 0;
            if (isSprite)
            {
                mAsset = LoadAssetByEditor <Sprite>(mResPath);
            }
            else
            {
                mAsset = LoadAssetByEditor <Object>(mResPath);
            }
            if (mAsset.IsNull())
            {
                mResState = ResState.Waiting;
                AFLogger.e("加载Editor ABRes资源为null,请检查路径:" + mResPath);
                mListener.InvokeGracefully(false, this);
                finishCallback(mCRC);
                yield break;
            }
            else
            {
                mResState = ResState.Ready;
            }
            yield return(new WaitForSeconds(0.5f)); //只是用来模拟异步加载

            ProcessEditor = 1;
            mListener.InvokeGracefully(true, this);
            finishCallback(mCRC);
        }
Beispiel #5
0
        public void CheckVersionCall(APPVersionStatus versionStatus)
        {
            resLoader = ResLoader.Allocate();
            if (versionStatus == APPVersionStatus.Abandon)
            {
                AFLogger.e("APP版本已经废弃");
                return;
            }
            switch (ABDataHolder.Instance.GetABResLoadFrom())
            {
            case ABResLoadFrom.EditorRes:
                isABFinish    = true;
                ABStatus.text = "AB包准备完成";
                break;

            case ABResLoadFrom.PersistentDataPathAB:
                ABHotUpdate.Instance.ABMD5Request("ABMain", ABProcessevent, ABMD5Callback);
                break;

            case ABResLoadFrom.StreamingAssetAB:
                isABFinish    = true;
                ABStatus.text = "AB包准备完成";
                break;
            }
        }
Beispiel #6
0
        private AssetBundle LoadAssetBundle(string ABName)
        {
            AssetBundleItem item = null;
            uint            crc  = Crc32.GetCrc32(ABName);

            if (mAssetBundleItemDic.TryGetValue(crc, out item) && item != null)
            {
                item.Retain();
            }
            else
            {
                AssetBundle assetBundle = null;
                string      fullPath    = ABDataHolder.Instance.GetABPrefix() + ABName;
                if (ABDataHolder.Instance.JudgeCanLoadAB(fullPath))
                {
                    assetBundle = AssetBundle.LoadFromFile(fullPath);
                }
                else
                {
                    AFLogger.e("不存在AB包路径 :" + ABName + " " + fullPath);
                }

                if (assetBundle == null)
                {
                    AFLogger.e(" Load AssetBundle Error:" + ABName + " " + fullPath);
                }

                item = SafeObjectPool <AssetBundleItem> .Instance.Allocate();

                item.assetBundle = assetBundle;
                item.Retain();
                mAssetBundleItemDic.Add(crc, item);
            }
            return(item.assetBundle);
        }
Beispiel #7
0
 public void Retain(object refOwner)
 {
     if (!Owners.Add(refOwner))
     {
         AFLogger.e("ObjectIsAlreadyRetainedByOwnerException");
     }
 }
Beispiel #8
0
        public AFSDK_ScriptingDefineSymbolAttribute(string SDKSymbol, string buildTargetGroupName)
        {
            if (SDKSymbol == null)
            {
                AFLogger.e("SDKSymbol为空");
                return;
            }
            if (SDKSymbol == string.Empty)
            {
                AFLogger.e("SDKSymbol:" + SDKSymbol + "An empty string isn't allowed.");
                return;
            }

            if (buildTargetGroupName == null)
            {
                AFLogger.e("buildTargetGroupName");
                return;
            }
            if (buildTargetGroupName == string.Empty)
            {
                AFLogger.e("buildTargetGroupName" + SDKSymbol + "An empty string isn't allowed.");
                return;
            }

            this.SDKSymbol            = SDKSymbol;
            this.buildTargetGroupName = buildTargetGroupName;
            SetBuildTarget(buildTargetGroupName);
        }
        private void ABStart(APPVersionStatus versionStatus)
        {
            resLoader = new ResLoader();
            if (versionStatus != APPVersionStatus.Abandon)
            {
                //这里为了保证PersistentDataPathAB时云端资源下载完成
                switch (ABDataHolder.Instance.GetABResLoadFrom())
                {
                case ABResLoadFrom.EditorRes:
                    ABStatus.text = "AB包准备完成";
                    LoadDataSet();
                    break;

                case ABResLoadFrom.PersistentDataPathAB:
                    ABHotUpdate.Instance.ABMD5Request(Key, ABProcessevent, ABMD5Callback);
                    break;

                case ABResLoadFrom.StreamingAssetAB:
                    ABStatus.text = "AB包准备完成";
                    LoadDataSet();
                    break;
                }
            }
            else
            {
                AFLogger.e("版本检测显示是废弃APP,请检查设置");
            }
        }
Beispiel #10
0
        public void CheckAPPVersion()
        {
            switch (ABConfig.ABResLoadfrom)
            {
            case ABResLoadFrom.PersistentDataPathAB:
                DownManager.Instance.StartByteDown(GetURLPrefix() + "APPInfo.txt", AppVersionCall, PathTool.PersistentDataPath + "APPInfo.txt", null);
                break;

            case ABResLoadFrom.StreamingAssetAB:
                string infoPath = "";
                if (ABConfig.isDevelopOrOnlineAB)
                {
                    infoPath = "AF-ABForLocal/AF-InfoFile" + ABConfig.ABDevelopmentVersion + "/APPInfo";
                }
                else
                {
                    infoPath = "AF-ABForLocal/AF-InfoFile" + ABConfig.ABOnlineVersion + "/APPInfo";
                }
                TextAsset textAsset = Resources.Load <TextAsset>(infoPath);
                if (textAsset != null)
                {
                    AppVersionCall(textAsset.bytes);
                }
                else
                {
                    AFLogger.e("Resources没有appInfo.txt,请检查");
                }
                break;

            case ABResLoadFrom.EditorRes:
                ABInit(default(byte[]));
                break;
            }
        }
Beispiel #11
0
        public void LoadAsync(ResLoadInfo resLoadInfo)
        {
            if (resLoadInfo.mResPath == "")
            {
                AFLogger.e("资源路径为空,无法进行加载");
                return;
            }
            ResInfo resInfo = ResManager.Instance.GetRes(resLoadInfo);

            if (resInfo != null && resInfo.State == ResState.Ready && (resInfo.ResObject.IsNotNull() || resInfo.ResStr.IsNotNullAndEmpty()))
            {
                resLoadInfo.mListener.InvokeGracefully(true, resInfo);
            }
            else if (resInfo == null)
            {
                resInfo = ResFactory.Create(resLoadInfo);
                //加入队列
                if (resInfo.LoadAsync())
                {
                    ResManager.Instance.CacheResource(resLoadInfo.mResPath, resInfo);
                }
            }
            else
            {
                AFLogger.e("当前请求的资源正在加载,增加回调");
                //当前请求的资源正在加载,增加回调
                resInfo.RegisterListen(resLoadInfo.mListener);
            }
        }
Beispiel #12
0
 //同步加载资源
 public override bool LoadSync()
 {
     if (mResPath.IsNullOrEmpty())
     {
         AFLogger.e("加载路径不能为空");
     }
     mResState = ResState.Loading;
     if (isSprite)
     {
         mAsset = Resources.Load(mResPath, typeof(Sprite));
     }
     else
     {
         mAsset = Resources.Load(mResPath);
     }
     if (mAsset.IsNull())
     {
         AFLogger.e("加载Resources资源为null,请检查路径:" + mResPath);
         mResState = ResState.Waiting;
     }
     else
     {
         mResState = ResState.Ready;
     }
     return(mAsset != null);
 }
Beispiel #13
0
 public void Release(object refOwner)
 {
     if (!Owners.Remove(refOwner))
     {
         AFLogger.e("ObjectIsNotRetainedByOwnerExceptionWithHint");
     }
 }
Beispiel #14
0
        public static void PopulateAvailableScriptingDefineSymbolPredicateInfos()
        {
            List <ScriptingDefineSymbolPredicateInfo> predicateInfos = new List <ScriptingDefineSymbolPredicateInfo>();

            foreach (Type type in ARSDK_SharedMethod.GetTypesOfType(typeof(AF_SDKManager)))
            {
                MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                for (int index = 0; index < methodInfos.Length; index++)
                {
                    AFSDK_ScriptingDefineSymbolAttribute[] predicateAttributes = (AFSDK_ScriptingDefineSymbolAttribute[])methodInfos[index].GetCustomAttributes(typeof(AFSDK_ScriptingDefineSymbolAttribute), false);
                    if (predicateAttributes.Length == 0)
                    {
                        continue;
                    }
                    if (methodInfos[index].ReturnType != typeof(bool) || methodInfos[index].GetParameters().Length != 0)
                    {
                        AFLogger.d((methodInfos[index].ReturnType != typeof(bool)) + " " + (methodInfos[index].GetParameters().Length != 0));
                        AFLogger.e(string.Format("The method '{0}' on '{1}' has '{2}' specified but its signature is wrong. The method must take no arguments and return bool.",
                                                 methodInfos[index].Name,
                                                 type,
                                                 typeof(AFSDK_ScriptingDefineSymbolAttribute)));

                        return;
                    }
                    predicateInfos.AddRange(predicateAttributes.Select(predicateAttribute => new ScriptingDefineSymbolPredicateInfo(predicateAttribute, methodInfos[index])));
                }
            }

            predicateInfos.Sort((x, y) => string.Compare(x.attribute.SDKSymbol, y.attribute.SDKSymbol, StringComparison.Ordinal));
            AvailableScriptingDefineSymbolPredicateInfos = predicateInfos.AsReadOnly();
        }
Beispiel #15
0
 /// <summary>
 /// 根据类型加载sprite,不是异步,不提供回调函数参数
 /// </summary>
 /// <param name="resType">从哪里加载</param>
 /// <param name="assetPath"></param>
 /// isRecycleOnDestroy : 当ResLoader被销毁时是否从内存中释放
 /// <returns></returns>
 public Sprite LoadSpriteSync(string assetPath, ResFromType resType, bool DestroyCache = false)
 {
     if (CheckNoCanLoad())
     {
         AFLogger.e("此Loader已经被释放,请注意!");
         return(null);
     }
     return(LoadSync <Sprite>(resType, assetPath, true, DestroyCache));
 }
Beispiel #16
0
 /// <summary>
 /// 释放单个资源
 /// </summary>
 /// <param name="AssetPath"></param>
 /// <param name="destoryObj">是否销毁缓存</param>
 public void ReleaseRes(string AssetPath, bool destoryObj = false)
 {
     if (CheckNoCanLoad())
     {
         AFLogger.e("此Loader已经被释放,请注意!");
         return;
     }
     ResManager.Instance.ReleaseResouce(AssetPath, destoryObj);
     mResList.Remove(AssetPath);
 }
Beispiel #17
0
 /// <summary>
 /// 释放单个Obj资源,这里不提供根据路径释放Obj,因为一个预制体可能实例化了多个,无法确认
 /// 默认是回收到recycleParent,如果想要缓存也回收,请设置destoryCache为true,recycleParent为false或者设置maxCacheCount为0
 /// </summary>
 public void ReleaseObj(GameObject obj, int maxCacheCount = -1, bool destoryCache = false, bool recycleParent = true)
 {
     if (CheckNoCanLoad())
     {
         AFLogger.e("此Loader已经被释放,请注意!");
         return;
     }
     ResManager.Instance.ReleaseObj(obj, maxCacheCount, destoryCache, recycleParent);
     mObjList.Remove(obj.GetInstanceID());
 }
Beispiel #18
0
        public bool ReleaseResouce(string ResPath)
        {
            ResInfo item = null;

            if (!mResDictionary.TryGetValue(Crc32.GetCrc32(ResPath), out item) || null == item)
            {
                AFLogger.e("mResDictionary里不存在改资源:" + ResPath + "  可能释放了多次");
            }
            DestoryResouceItme(item, item.DestroyCache);
            return(true);
        }
Beispiel #19
0
        public List <Type> GetAllType()
        {
            var assembly = Assembly.GetAssembly(typeof(AFStart));

            if (assembly == null)
            {
                AFLogger.e("当前dll is null");
                return(null);
            }
            return(assembly.GetTypes().Distinct().ToList());
        }
Beispiel #20
0
 protected void RemoveChildPanel(int uitag, UIPanelParent childUIPanel)
 {
     if (SubPanelDic.ContainsKey(uitag))
     {
         SubPanelDic[uitag].Remove(childUIPanel);
     }
     else
     {
         AFLogger.e("父级面板并不包含此子级面板,请注意");
     }
 }
Beispiel #21
0
 public void RemoveParentPanel(string scriptName)
 {
     if (ScriptsNameToPanel.ContainsKey(scriptName))
     {
         ScriptsNameToPanel.Remove(scriptName);
     }
     else
     {
         AFLogger.e("当前并不存在 : " + scriptName + "面板");
     }
 }
 public void LoadSpriteCallBack(bool result, ResInfo resInfo)
 {
     if (result)
     {
         spriteRender.sprite = resInfo.ResObject as Sprite;
     }
     else
     {
         AFLogger.e("加载" + resInfo.ResPath + "失败!");
     }
 }
Beispiel #23
0
 protected virtual void Awake()
 {
     if (mInstance == null)
     {
         mInstance = (T)this;
         mInstance.OnSingletonInit();
     }
     else
     {
         AFLogger.e("Get a second instance of this class" + this.GetType());
     }
 }
 public void LoadResPrefab(bool result, ResInfo resInfo)
 {
     if (result)
     {
         Res.Add(Instantiate(resInfo.ResObject as GameObject));
         AFLogger.d("从Resources加载并实例化了" + Res.Count + "个");
     }
     else
     {
         AFLogger.e("加载" + resInfo.ResPath + "失败!");
     }
 }
Beispiel #25
0
 protected void RemoveChildPanel(int uitag)
 {
     if (SubPanelDic.ContainsKey(uitag))
     {
         SubPanelDic[uitag].Clear();
         SubPanelDic.Remove(uitag);
     }
     else
     {
         AFLogger.e("父级面板并不包含此子级面板,请注意");
     }
 }
Beispiel #26
0
 /// <summary>
 /// 释放单个UI面板,根据UITag与obj,一般是给面板的closeself调用
 /// </summary>
 public void CloseUI(int UITag, UIPanelParent panel, int CacheCount = -1, bool destoryCache = false,
                     bool recycleParent = true)
 {
     if (UITagToScriptsName.ContainsKey(UITag))
     {
         CloseUI(UITagToScriptsName[UITag], panel, CacheCount, destoryCache, recycleParent);
     }
     else
     {
         AFLogger.e("当前并不存在 : " + UITag + "面板");
     }
 }
Beispiel #27
0
        public void RefreshPanel <T>(UIDataParent UIDataParent) where T : UIPanelParent
        {
            string scriptName = typeof(T).ToString();

            if (ScriptsNameToPanel.ContainsKey(scriptName))
            {
                ScriptsNameToPanel[scriptName].RefreshUIByData(UIDataParent);
            }
            else
            {
                AFLogger.e("当前并不存在 : " + scriptName + "面板");
            }
        }
Beispiel #28
0
        public void ChangePanelLayer <T>(PanelLayer panelLayer)
        {
            string scriptName = typeof(T).ToString();

            if (ScriptsNameToPanel.ContainsKey(scriptName))
            {
                ChangePanelLayer(panelLayer, ScriptsNameToPanel[scriptName].transform);
            }
            else
            {
                AFLogger.e("当前并不存在 : " + scriptName + "面板");
            }
        }
Beispiel #29
0
        public void RemovePanel <T>()
        {
            string scriptName = typeof(T).ToString();

            if (ScriptsNameToPanel.ContainsKey(scriptName))
            {
                ScriptsNameToPanel.Remove(scriptName);
            }
            else
            {
                AFLogger.e("当前并不存在 : " + scriptName + "面板");
            }
        }
Beispiel #30
0
        /// <summary>
        ///  回收一个资源
        /// </summary>
        /// <param name="item"></param>
        /// <param name="destroyCache"></param>
        protected void DestoryResouceItme(ResInfo item, bool destroyCache = false)
        {
            if (item == null)
            {
                AFLogger.e("DestoryResouceItme:要释放的资源为空");
                return;
            }
            if (item.IsRecycled)
            {
                AFLogger.e("资源已经被回收,请检查代码是否回收了多次:" + item.ResPath);
                mResDictionary.Remove(item.mCRC);
                return;
            }
            if (item.RefCount <= 0)
            {
                AFLogger.e("资源引用计数<=0:" + item.ResPath);
                return;
            }
            //释放减少引用计数
            item.Release();
            //如果缓存下来,移到表头
            if (!destroyCache)
            {
                m_NoRefrenceAssetMapList.InsertToHead(item);
                return;
            }
            //不缓存,要根据引用计数判断是否释放内存
            if (item.ReleaseRes())
            {
                AFLogger.i("释放资源成功:" + item.ResPath);
                //资源缓存
                if (!mResDictionary.Remove(item.mCRC))
                {
                    return;
                }

                m_NoRefrenceAssetMapList.Remove(item);
                //释放assetbundle引用
                ReleaseAssetBundle(item);
                item.Recycle2Cache();
                //在编辑器中加载,需要如此才能清除内存,因此在程序退出时要调用此方法清除内存
#if UNITY_EDITOR
                Resources.UnloadUnusedAssets();
#endif
            }
            //else
            //{
            //    AF_Logger.Info("释放资源失败(引用计数不为0或者并没有加载完成):" + item.ResPath);
            //}
        }