Exemplo n.º 1
0
    public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
    {
        AssetBundleLoadAssetOperation operation = null;

#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
            if (assetPaths.Length == 0)
            {
                Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                return(null);
            }
            UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
            operation = new AssetBundleLoadAssetOperationSimulation(target);
        }
        else
#endif
        {
            assetBundleName = RemapVariantName(assetBundleName);
            LoadAssetBundleAsync(assetBundleName, true, true);
            operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);
            m_InProgressOperations.Add(operation);
        }
        return(operation);
    }
Exemplo n.º 2
0
        /** 加载资源 */
        public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            LogFormat(LogType.Info, "LoadAssetAsync assetBundleName={0}, assetName={1}, type={2}", assetBundleName, assetName, type);

            AssetBundleLoadAssetOperation operation = null;

            #if UNITY_EDITOR
            if (AssetManagerSetting.EditorSimulateAssetBundle)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Debug.LogErrorFormat("LoadAssetAsync用AssetDatabase模拟加载没有找到该文件  assetBundleName={0}, assetName={1}", assetBundleName, assetName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
            #endif
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(this, assetBundleName, assetName, type);

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Exemplo n.º 3
0
        public override async Task <T> LoadAsyncImpl()
        {
            Debug.Log($"Loading {AssetName} from {BundleName} bundle...");
#if UNITY_EDITOR
            if (AssetBundleManager.SimulateBundles || !EditorApplication.isPlayingOrWillChangePlaymode)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(BundleName, AssetName);
                if (assetPaths.Length != 0)
                {
                    return(AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]));
                }
                throw new Exception($"There is no asset with name {AssetName} in {BundleName}");
            }
#endif
            try {
                var bundle = await AssetBundleManager.LoadAssetBundleAsync(BundleName);

                var request = await bundle.AssetBundle.LoadAssetAsync <T>(AssetName).ToTask();

                Debug.Log($"Loaded {AssetName} from {BundleName}");
                return(request.asset as T);
            } catch (Exception e) {
                Debug.LogException(e);
                throw e;
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// 加载语言表
    /// </summary>
    public void LoadConfig()
    {
        dicLang.Clear();
        string assetPath = AppSetting.ConfigBundleDir.TrimEnd('/') + AppSetting.ExtName;

        string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetPath.ToLower(), "LanguageConfig");

        if (assetPaths.Length > 0)
        {
            UnityEngine.Object      target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
            List <LangServerConfig> list   = JsonMapper.ToObject <List <LangServerConfig> >(target.ToString());
            Debug.Log("多语言表内容" + list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                if (dicLang.ContainsKey(list[i].id))
                {
                    CLog.Error($"表[LanguageConfig]中有相同键({list[i].id})");
                }
                else
                {
                    dicLang.Add(list[i].id, list[i]);
                }
            }
        }
    }
Exemplo n.º 5
0
 static public T LoadAsset <T>(string assetBundleName, string assetName, System.Type type) where T : UnityEngine.Object
 {
                 #if UNITY_EDITOR
     if (DevABModeInEditor)
     {
         string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
         if (assetPaths.Length == 0)
         {
             Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
             return(null);
         }
         var t = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]);
         return(t as T);
     }
     else
                 #endif
     {
         QLoadedAB bundle = null;
         Debug.Log(m_LoadedAssetBundles.Count + " ********** loadedassetbundles count******** " + assetBundleName);
         m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
         if (bundle.m_AssetBundle != null)
         {
             return(bundle.m_AssetBundle.LoadAsset <T> (assetName));
         }
         else
         {
             Debug.LogError("***make sure the asset bundle finish loaded first *********");
             return(null);
         }
     }
 }
Exemplo n.º 6
0
    /// <summary>
    /// 通过资源AB标签及资源名称 获取资源路径
    /// </summary>
    /// <returns></returns>
    private static string GetAssetPath(string bundleName, string assetName)
    {
        string path = null;

        //获取资源路径  所有同名资源
        string[] assetPathFromAssetBundleAndAssetName = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName, Path.GetFileNameWithoutExtension(assetName));
        //如果资源名包含后缀  根据后缀找到对应资源的路径
        if (Path.HasExtension(assetName))
        {
            string extension = Path.GetExtension(assetName);
            for (int i = 0; i < assetPathFromAssetBundleAndAssetName.Length; i++)
            {
                string text = assetPathFromAssetBundleAndAssetName[i];
                if (Path.GetExtension(text) == extension)
                {
                    path = text;
                    break;
                }
            }
        }
        else if (assetPathFromAssetBundleAndAssetName.Length > 0)
        {
            path = assetPathFromAssetBundleAndAssetName[0];
        }
        return(path);
    }
Exemplo n.º 7
0
 public override T LoadAsset <T>(string assetName)
 {
     if (IsReady)
     {
         if (LoadedAssetMap.ContainsKey(assetName))
         {
             return(LoadedAssetMap[assetName] as T);
         }
         if (AssetsPath == null)
         {
             return(null);
         }
         var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(AssetBundleName, assetName);
         if (assetPaths.Length == 1)
         {
             T asset = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]);
             if (asset != null)
             {
                 LoadedAssetMap.Add(assetName, asset);
                 return(asset);
             }
             return(null);
         }
         if (assetPaths.Length > 1)
         {
             UnityEngine.Debug.LogError(string.Format("AssetBundle: {0} 存在同名Asset: {1}资源", AssetBundleName,
                                                      assetName));
             return(null);
         }
         return(null);
     }
     return(null);
 }
Exemplo n.º 8
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));
    }
Exemplo n.º 9
0
        private void LoadLocalPrefab(LoadItem load_item)
        {
#if UNITY_EDITOR
            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(
                load_item.asset_id.bundleName,
                load_item.asset_id.assetName);

            if (paths.Length <= 0)
            {
                return;
            }

            Debug.Log(string.Format("Load Local Prefab {0}", paths[0]));

            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(paths[0], typeof(GameObject));
            if (null == obj)
            {
                return;
            }

            AssetItem item = new AssetItem();
            item.assetId = load_item.asset_id;
            item.type    = AssetType.PREFAB;
            item.obj     = obj;
            CacheManager.Instance.AddAssetItem(item);

            this.loadDic.Remove(item.assetId);
            if (null != load_item.load_callback)
            {
                load_item.load_callback(item);
            }
#endif
        }
        // Load asset from the given assetBundle.
        static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

        #if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
        #endif
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Exemplo n.º 11
0
        public K GetAsset <K>(string bundleName, string prefab) where K : class
        {
            string path = $"{bundleName}.unity3d/{prefab}".ToLower();

            UnityEngine.Object resource = null;
            if (this.resourceCache.TryGetValue(path, out resource))
            {
                return(resource as K);
            }

            if (Define.LoadResourceType == LoadResourceType.Async)
            {
                if (!this.bundleCaches.ContainsKey($"{bundleName}.unity3d".ToLower()))
                {
                    return(null);
                }

                throw new ConfigException($"异步加载资源,资源不在resourceCache中: {bundleName} {path}");
            }

            try
            {
#if UNITY_EDITOR
                string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName.ToLower() + ".unity3d", prefab);
                resource = AssetDatabase.LoadAssetAtPath(realPath[0], typeof(GameObject));
                this.resourceCache.Add(path, resource);
#endif
            }
            catch (Exception e)
            {
                throw new ConfigException($"加载资源出错,输入路径:{path}", e);
            }

            return(resource as K);
        }
Exemplo n.º 12
0
        public AssetBundleLoadAssetOperation LoadAssetAsync <T>(GameAssetStruct gas, System.Action <T> pCallBack) where T : UnityEngine.Object
        {
            Log(LogType.Info, "Loading " + gas.AssetName + " from " + gas.BundleFullName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(gas.BundleFullName, gas.AssetName);
                if (assetPaths.Length == 0)
                {
                    Log(LogType.Error, "There is no asset with name \"" + gas.AssetName + "\" in " + gas.BundleFullName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                //Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                T target = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target, null);
                pCallBack(operation.GetAsset <T>());
            }
            else
#endif
            {
                LoadAssetBundleAsy(gas.BundleFullName);
                operation = new AssetBundleLoadAssetOperationFull(gas.BundleFullName, gas.AssetName, typeof(T), a => {
                    pCallBack(a.GetAsset <T>());
                });

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Exemplo n.º 13
0
        public T LoadAsset <T>(string assetName) where T : UnityEngine.Object
        {
            Log.Trace("[ilib-abloader] EditorContainer {0}, LoadAsset<{1}>({2}).", m_Name, typeof(T), assetName);
            var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_Name, assetName);

            return(paths.Length > 0 ? AssetDatabase.LoadAssetAtPath <T>(paths[0]) : null);
        }
Exemplo n.º 14
0
        public void LoadSceneAsync(string sceneName, LoadSceneMode mode, Action onSuccess)
        {
            Log.Trace("[ilib-abloader] EditorContainer {0}, LoadSceneAsync {1}. mode{2}", m_Name, sceneName, mode);
            var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_Name, sceneName);

            if (paths.Length == 0)
            {
                onSuccess?.Invoke();
                return;
            }
            LoadSceneParameters parameters = new LoadSceneParameters(mode);

            EditorSceneManager.LoadSceneAsyncInPlayMode(paths[0], parameters);

            //Asyncのコールバックが正常に動かないので無理やり実装
            var scene = EditorSceneManager.GetSceneByPath(paths[0]);

            EditorApplication.CallbackFunction onLoad = null;
            onLoad = () =>
            {
                if (scene.isLoaded || !scene.IsValid())
                {
                    EditorApplication.update -= onLoad;
                    onSuccess?.Invoke();
                }
            };
            EditorApplication.update += onLoad;
        }
Exemplo n.º 15
0
        private void AsyncLoadScene(SceneLoadItem load_item)
        {
#if UNITY_EDITOR
            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(
                load_item.asset_id.bundleName,
                load_item.asset_id.assetName);

            if (paths.Length <= 0)
            {
                return;
            }

            AsyncOperation asyncOperation;
            if (LoadSceneMode.Additive == load_item.load_mode)
            {
                asyncOperation = EditorApplication.LoadLevelAdditiveAsyncInPlayMode(paths[0]);
            }
            else
            {
                asyncOperation = EditorApplication.LoadLevelAsyncInPlayMode(paths[0]);
            }

            WaitLoadSceneItem wait_item = new WaitLoadSceneItem();
            wait_item.load_item      = load_item;
            wait_item.asyncOperation = asyncOperation;
            this.wait_list.Add(wait_item);
#endif
        }
Exemplo n.º 16
0
    public UnityEngine.Object GetAsset()
    {
#if UNITY_EDITOR
        if (AssetBundleLoadManager.SimulateAssetBundleInEditor)
        {
            string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_AssetBundleName, m_AssetName);
            if (assetPaths.Length == 0)
            {
                ATrace.LogError("There is no asset with name \"" + m_AssetName + "\" in " + m_AssetBundleName);
                return(null);
            }

            // @TODO: Now we only get the main object from the first asset. Should consider type also.
            UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
            return(target);
        }
#endif

        LoadedAssetBundle bundle = AssetBundleLoadManager.Instance.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
        if (bundle == null)
        {
            ATrace.Log("GetAsset fail:" + m_AssetBundleName);
            return(null);
        }
        if (m_Request != null && m_Request.isDone)
        {
            ATrace.Log("GetAsset succ:" + m_AssetBundleName);
            return(m_Request.asset);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 17
0
        public override IEnumerator LoadLevel(string assetBundleName, string sceneName, UnityEngine.SceneManagement.LoadSceneMode loadMode, System.Action complete, System.Action <float> progressCallback)
        {
            var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, sceneName);

            if (assetPaths.Length == 0)
            {
                Debug.LogError(string.Format("simulate assetBundle:\"{0}\" asset:\"{1}\" failed", assetBundleName, sceneName));
                yield break;
            }

            var assetPath      = assetPaths[0];
            var asyncOperation = EditorApplication.LoadLevelAsyncInPlayMode(assetPath);

            while (asyncOperation.isDone)
            {
                if (progressCallback != null)
                {
                    progressCallback(asyncOperation.progress);
                }

                yield return(null);
            }

            if (complete != null)
            {
                complete();
            }
        }
Exemplo n.º 18
0
    /// <summary>
    /// 加载资源
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="assetBundleName"></param>
    /// <param name="assetName"></param>
    /// <param name="isWait"></param>
    /// <returns></returns>
    private T _LoadAsset <T>(string assetBundleName, string assetName = null, bool isWait = false) where T : UObject
    {
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor == false)
        {
            string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
            if (assetPaths.Length == 0)
            {
                Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                return(null);
            }
            // @TODO: Now we only get the main object from the first asset. Should consider type also.
            UObject target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
            return(target as T);
        }
        else
#endif

        {
            AssetBundle assetBundle = LoadAssetBundle(assetBundleName);
            T           obj         = (T)assetBundle.LoadAssetAsync <T>(assetName).asset;
            if (obj == null)
            {
                Debug.LogError($"加载资源失败:{assetBundleName}  AssName:{assetName}");
            }
            return(obj);
        }
    }
Exemplo n.º 19
0
	// Load level from the given assetBundle.
	static public AssetBundleLoadOperation LoadLevelAsync (string assetBundleName, string levelName, bool isAdditive)
	{
		AssetBundleLoadOperation operation = null;
#if UNITY_EDITOR
		if (SimulateAssetBundleInEditor)
		{
			string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName);
			if (levelPaths.Length == 0)
			{
				///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
				//        from that there right scene does not exist in the asset bundle...
			
				Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
				return null;
			}

			if (isAdditive)
				EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
			else
				EditorApplication.LoadLevelInPlayMode(levelPaths[0]);

			operation = new AssetBundleLoadLevelSimulationOperation();
		}
		else
#endif
		{
			LoadAssetBundle (assetBundleName);
			operation = new AssetBundleLoadLevelOperation (assetBundleName, levelName, isAdditive);

			m_InProgressOperations.Add (operation);
		}

		return operation;
	}
Exemplo n.º 20
0
        IObservable <AssetConfig> LoadAssetConfig()
        {
            var assetFullPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(
                Constant.ASSET_CONFIG_BUNDLE_NAME, Constant.ASSET_CONFIG_ASSET_NAME);

            return(Observable.Return(AssetDatabase.LoadAssetAtPath <AssetConfig>(assetFullPath[0]),
                                     Scheduler.MainThreadIgnoreTimeScale));
        }
 static void BuildPlayerAsset()
 {
     string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName("cube", "Cube");
     foreach (var item in paths)
     {
         Debug.Log(item);
     }
 }
Exemplo n.º 22
0
        public string[] GetAssetPathsFromAssetBundleAndAssetName(string abRAssetName, string assetName)
        {
#if UNITY_EDITOR
            return(AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abRAssetName, assetName));
#else
            return(null);
#endif
        }
Exemplo n.º 23
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);
                }
            }
        }
Exemplo n.º 24
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.HelpBox(position, GetViewText(), MessageType.None);

            var dragArea = position;

            var ev = Event.current;

            switch (ev.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform when dragArea.Contains(ev.mousePosition):
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                if (ev.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        if (obj == null)
                        {
                            break;
                        }

                        string assetPath = AssetDatabase.GetAssetPath(obj);
                        string abName    = AssetDatabase.GetImplicitAssetBundleName(assetPath);
                        string varName   = AssetDatabase.GetImplicitAssetBundleVariantName(assetPath);
                        UpdateValue(obj, abName, varName);
                        property.serializedObject.ApplyModifiedProperties();
                    }
                }
                ev.Use();
                break;
            }

            case EventType.MouseDown when !string.IsNullOrEmpty(AbName) && dragArea.Contains(ev.mousePosition):
            {
                string[] paths = string.IsNullOrEmpty(AssetName)
                        ? AssetDatabase.GetAssetPathsFromAssetBundle(AbName)
                        : AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(AbName, AssetName);
                EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(paths.First()));
                ev.Use();
                break;
            }
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Exemplo n.º 25
0
        public override void OnInspectorGUI()
        {
            var self = target as SpriteLoader;

            if (cachedSprite == null && !string.IsNullOrEmpty(self.assetPath))
            {
                string assetbundleName, assetName;
                Asset.AssetLoader.GetAssetpath(self.assetPath, out assetbundleName, out assetName);
                var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetbundleName, assetName);
                foreach (var p in paths)
                {
                    cachedSprite = AssetDatabase.LoadAssetAtPath(p, typeof(Sprite)) as Sprite;
                }
            }

            var currentSprite = EditorGUILayout.ObjectField("拖拽对象来添加->", cachedSprite, typeof(Sprite), false) as Sprite;

            if (currentSprite)
            {
                var path = AssetDatabase.GetAssetPath(currentSprite);
                var ai   = AssetImporter.GetAtPath(path);
                if (string.IsNullOrEmpty(ai.assetBundleName))
                {
                    LogMgr.W("{0}没有标志为一个AssetBundle。", currentSprite);
                    self.assetPath = "";
                    currentSprite  = null;
                }
                else
                {
                    var lastPoint = ai.assetBundleName.LastIndexOf('.');
                    var abName    = ai.assetBundleName.Substring(0, lastPoint);
                    self.assetPath = string.Format("{0}/{1}", abName, currentSprite.name);
                }
            }
            else
            {
                self.assetPath = "";
            }

            if (currentSprite != cachedSprite)
            {
                cachedSprite = currentSprite;
                var img = self.GetComponent <UnityEngine.UI.Image>();
                img.sprite = cachedSprite;
                if (self.nativeSizeOnLoaded)
                {
                    img.SetNativeSize();
                }
                img.SetAllDirty();
            }

            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("nativeSizeOnLoaded"));
            EditorGUILayout.LabelField(string.Format("Asset Path: [{0}]", self.assetPath));
            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 26
0
        private static Object LoadAsset(SerializedProperty assetNameProperty, SerializedProperty bundleNameProperty,
                                        Type assetType)
        {
            string assetPath =
                AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(
                    bundleNameProperty.stringValue, assetNameProperty.stringValue).FirstOrDefault();
            var asset = AssetDatabase.LoadAssetAtPath(assetPath, assetType);

            return(asset);
        }
Exemplo n.º 27
0
        public static UnityEngine.Object LoadResource(string bundleName, string prefab)
        {
#if  UNITY_EDITOR
            string[]           realPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName.ToLower() + ".unity3d", prefab);
            UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath(realPath[0], typeof(GameObject));
            return(resource);
#else
            return(null);
#endif
        }
Exemplo n.º 28
0
 protected override GameObject GetPrefabItem()
 {
     string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleNameProp.stringValue, assetNameProp.stringValue);
     if (paths != null && paths.Length > 0)
     {
         GameObject gopfb = AssetDatabase.LoadAssetAtPath <GameObject>(paths[0]);
         return(gopfb);
     }
     return(null);
 }
        public static IPromise LoadAsset(string bundlePath, string assetName)
        {
#if UNITY_EDITOR
            var assetPath = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundlePath, assetName)[0];
            return(Promise.Resolved(AssetDatabase.LoadAssetAtPath <Object>(assetPath)));
#else
            return(LoadFromFileAsync(bundlePath)
                   .Then <AssetBundle>(b => b.LoadAssetPromise(assetName)));
#endif
        }
Exemplo n.º 30
0
    //~AssetBundleManagerEditor()
    //{
    //    AssetBundleManager.LoadAssetOnEditorInstance = null;
    //    AssetBundleManager.LoadSceneOnEditorInstance = null;
    //    AssetBundleManager.LoadAssetOnEditorFromAbInstance = null;
    //    AssetBundleManager.CheckAssetPatchOnEditorInstance = null;
    //}

    public static UnityEngine.Object[] LoadAssetOnEditorFromAb(string assetBundleName, string assetName, System.Type t)
    {
        string [] patchs = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);

        if (patchs.Length <= 0)
        {
            return(null);
        }
        return(new UnityEngine.Object[] { AssetDatabase.LoadAssetAtPath(patchs[0], t) });
    }