示例#1
0
        /// <summary>
        /// 载入素材
        /// </summary>
        void LoadAsset <T>(string abName, string[] assetNames, Action <UObject[]> action = null, LuaFunction func = null) where T : UObject
        {
            abName = GetRealAssetPath(abName);

            LoadAssetRequest request = new LoadAssetRequest();

            request.assetType  = typeof(T);
            request.assetNames = assetNames;
            request.luaFunc    = func;
            request.sharpFunc  = action;

#if UNITY_EDITOR
            if (AppConst.SimulateAssetBundleInEditor)
            {
                List <UObject> result = new List <UObject> ();
                for (int j = 0; j < assetNames.Length; j++)
                {
                    string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abName, assetNames [j]);
                    if (assetPaths.Length == 0)
                    {
                        Debug.LogError("There is no asset with name \"" + assetNames [j] + "\" in " + abName);
                        return;
                    }

                    UObject target = AssetDatabase.LoadMainAssetAtPath(assetPaths [0]);
                    result.Add(target);
                }

                if (request.sharpFunc != null)
                {
                    request.sharpFunc(result.ToArray());
                    request.sharpFunc = null;
                }
                if (request.luaFunc != null)
                {
                    request.luaFunc.Call((object)result.ToArray());
                    request.luaFunc.Dispose();
                    request.luaFunc = null;
                }
            }
            else
#endif
            {
                List <LoadAssetRequest> requests = null;
                if (!m_LoadRequests.TryGetValue(abName, out requests))
                {
                    requests = new List <LoadAssetRequest> ();
                    requests.Add(request);
                    m_LoadRequests.Add(abName, requests);
                    StartCoroutine(OnLoadAsset <T> (abName));
                }
                else
                {
                    requests.Add(request);
                }
            }
        }
示例#2
0
    void Update()
    {
        if (Time.realtimeSinceStartup - m_fLastGCTime > m_fGCInternal)
        {
            DoGC();
            m_fLastGCTime = Time.realtimeSinceStartup;
        }

        if (m_CallBackList.Count > 0)
        {
            LoadAssetRequest r = m_CallBackList[0];
            m_CallBackIndex = r.LoadIndex;
            //暂时不要之前的那个加载顺序的判断
            if (IsUnloadId(m_CallBackIndex))
            {
                if (r.levelSharpFunc != null)
                {
                    UnloadLevel(m_CallBackIndex);
                }
                else
                {
                    UnloadPrefab(m_CallBackIndex);
                }
                m_UnloadedIdABName.Remove(m_CallBackIndex);
            }
            else
            {
                if (r.levelSharpFunc != null)
                {
                    r.levelSharpFunc();
                    r.levelSharpFunc = null;
                }
                else if (r.sharpFunc != null)
                {
                    if (r.ObjList != null)
                    {
                        r.ObjList.m_Id = m_CallBackIndex;
                    }
                    else
                    {
                        UnloadPrefab(m_CallBackIndex);
                    }
                    r.sharpFunc(r.ObjList);
                    r.sharpFunc = null;
                }
            }
            if (r.ObjList != null)
            {
                r.ObjList.DestroyClass();
                r.ObjList = null;
            }
            m_CallBackList.RemoveAt(0);
        }
    }