コード例 #1
0
    public T LoadAsset <T>(ABTypes abType, string assetName) where T : UnityEngine.Object
    {
#if UNITY_EDITOR
        if (SimulationMod)
        {
            string   path      = abType.ToString() + "/" + abType.ToString() + AppConst.KABNameSuffix;
            string[] assetpath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(path, assetName);
            if (assetpath.Length == 0)
            {
                throw new GameException(AppConst.ErNoAssetFound + assetName);
            }
            else if (assetpath.Length > 1)
            {
                string same = AppConst.ErSameNameTitle;
                foreach (string name in assetpath)
                {
                    same += "\n";
                    same += name;
                }
                throw new GameException(AppConst.ErHaveSameName + same);
            }
            return(AssetDatabase.LoadAssetAtPath <T>(assetpath[0]));
        }
#endif
        AssetBundle assetBundle;
        if (m_LoadedAssetBundles.TryGetValue(abType, out assetBundle))
        {
            return(assetBundle.LoadAsset <T>(assetName));
        }

        return(default(T));
    }
コード例 #2
0
    public int LoadAssetBundle(ABTypes abType, string path = "", bool IsAsync = true, uint crc = 0, ulong offset = 0)
    {
        AssetBundleCreateRequest request = null;

#if UNITY_EDITOR
        if (SimulationMod)
        {
            return(0);
        }
#endif
        if (m_LoadedAssetBundles.ContainsKey(abType))
        {
            return(0);
        }
        else if (m_AssetBundleCreateRequests.ContainsKey(abType))
        {
            return(1);
        }
        if (path == "")
        {
            path = m_LoadingAssetBundlePath + abType.ToString() + "/" + abType.ToString() + AppConst.KABNameSuffix;
        }
        AssetBundle assetBundle = null;
        if (IsAsync)
        {
            request = AssetBundle.LoadFromFileAsync(path, crc, offset);
            m_AssetBundleCreateRequests.Add(abType, request);
            StartCoroutine(UpdateAssetBundleCreateRequest(abType, request));
        }
        else
        {
            assetBundle = AssetBundle.LoadFromFile(path, crc, offset);
            if (assetBundle == null)
            {
                return(-1);
            }
            m_LoadedAssetBundles.Add(abType, assetBundle);
        }

        return(0);
    }
コード例 #3
0
    public AssetBundleAsyncOperation LoadAssetAsync <T>(ABTypes abType, string assetName, System.Action callback = null) where T : UnityEngine.Object
    {
        AssetBundleAsyncOperation Operation = null;

#if UNITY_EDITOR
        if (SimulationMod)
        {
            string   path      = abType.ToString() + "/" + abType.ToString() + AppConst.KABNameSuffix;
            string[] assetpath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(path, assetName);
            if (assetpath.Length == 0)
            {
                throw new GameException(AppConst.ErNoAssetFound + assetName);
            }
            else if (assetpath.Length > 1)
            {
                string same = AppConst.ErSameNameTitle;
                foreach (string name in assetpath)
                {
                    same += "\n";
                    same += name;
                }
                throw new GameException(AppConst.ErHaveSameName + same);
            }

            Operation = new AssetBundleAsyncOperation(AssetDatabase.LoadAssetAtPath <T>(assetpath[0]), callback);
            return(Operation);
        }
#endif
        AssetBundle assetBundle = null;
        if (m_LoadedAssetBundles.TryGetValue(abType, out assetBundle))
        {
            Operation = new AssetBundleAsyncOperation(assetBundle.LoadAssetAsync <T>(assetName), callback);
        }

        return(Operation);
    }