public bool LoadLibrary(string assetLibrary, int ordinal) { if (m_ordinalToLib.ContainsKey(ordinal)) { Debug.LogWarningFormat("Asset Library {0} with this same ordinal {1} already loaded", m_ordinalToLib[ordinal].name, ordinal); return(false); } AssetLibraryAsset assetLib = Resources.Load <AssetLibraryAsset>(assetLibrary); if (assetLib == null) { Debug.LogWarningFormat("Asset Library not found", assetLibrary); return(false); } return(AddLibrary(assetLib, ordinal)); }
public ProjectAsyncOperation <ProjectItem> LoadAssetLibrary(int index, ProjectEventHandler <ProjectItem> callback = null) { ProjectAsyncOperation <ProjectItem> pao = new ProjectAsyncOperation <ProjectItem>(); ResourceRequest request = Resources.LoadAsync <AssetLibraryAsset>(AssetLibraries[index]); Action <AsyncOperation> completed = null; completed = ao => { request.completed -= completed; ProjectItem result = new ProjectItem(); AssetLibraryAsset asset = (AssetLibraryAsset)request.asset; Error error = new Error(Error.OK); if (asset == null) { error.ErrorCode = Error.E_NotFound; error.ErrorText = "Asset Library " + AssetLibraries[index] + " does not exist"; if (callback != null) { callback(error, result); } pao.Result = null; pao.IsCompleted = true; return; } TreeModel <AssetFolderInfo> model = new TreeModel <AssetFolderInfo>(asset.AssetLibrary.Folders); BuildTree(result, (AssetFolderInfo)model.root.children[0], index); if (callback != null) { callback(error, result); } pao.Result = result; pao.IsCompleted = true; }; request.completed += completed; return(pao); }
private void MergeAssetLibrary(AssetLibraryAsset asset, int ordinal) { if (!asset.KeepRuntimeProjectInSync) { return; } AssetLibraryInfo assetLibrary = asset.AssetLibrary; if (assetLibrary == null) { return; } assetLibrary.BuildTree(); AssetFolderInfo rootFolder = assetLibrary.Folders.Where(folder => folder.depth == 0).First(); MergeFolders(rootFolder, m_root, ordinal); }
public bool AddLibrary(AssetLibraryAsset assetLib, int ordinal) { if (m_ordinalToLib.ContainsKey(ordinal)) { Debug.LogWarningFormat("Asset Library with ordinal {0} already loadeded", assetLib.Ordinal); return(false); } if (m_loadedLibraries.Contains(assetLib)) { Debug.LogWarning("Asset Library already added"); return(false); } assetLib.Ordinal = ordinal; m_loadedLibraries.Add(assetLib); m_ordinalToLib.Add(ordinal, assetLib); LoadMapping(ordinal, true, true); return(true); }
private static void SaveAssetLibrary(AssetLibraryAsset asset, Scene scene, int index) { string dir = BHPath.Root + "/RTSaveLoad2"; string dataPath = Application.dataPath + "/"; if (!Directory.Exists(dataPath + dir + "/Resources_Auto")) { AssetDatabase.CreateFolder("Assets/" + dir, "Resources_Auto"); } dir = dir + "/Resources_Auto"; if (!Directory.Exists(dataPath + dir + "/Resources")) { AssetDatabase.CreateFolder("Assets/" + dir, "Resources"); } dir = dir + "/Resources"; if (!Directory.Exists(dataPath + dir + "/" + scene.name)) { AssetDatabase.CreateFolder("Assets/" + dir, scene.name); } dir = dir + "/" + scene.name; if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(asset))) { if (index == 0) { AssetDatabase.CreateAsset(asset, "Assets/" + dir + "/AssetLibrary.asset"); } else { AssetDatabase.CreateAsset(asset, "Assets/" + dir + "/AssetLibrary" + (index + 1) + ".asset"); } } EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); }
public void LoadLibrary(string assetLibrary, int ordinal, bool loadIIDtoPID, bool loadPIDtoObj, Action <bool> callback) { if (m_ordinalToLib.ContainsKey(ordinal)) { Debug.LogWarningFormat("Asset Library {0} with this same ordinal {1} already loaded", m_ordinalToLib[ordinal].name, ordinal); callback(false); return; } ResourceRequest request = Resources.LoadAsync <AssetLibraryAsset>(assetLibrary); Action <AsyncOperation> completed = null; completed = ao => { AssetLibraryAsset assetLib = (AssetLibraryAsset)request.asset; if (assetLib == null) { if (IsSceneLibrary(ordinal)) { if (ordinal - AssetLibraryInfo.SCENELIB_FIRST == 0) { Debug.LogWarningFormat("Asset Library not found : {0}", assetLibrary); } } else { Debug.LogWarningFormat("Asset Library not found : {0}", assetLibrary); } callback(false); return; } AddLibrary(assetLib, ordinal, loadIIDtoPID, loadPIDtoObj); callback(true); request.completed -= completed; }; request.completed += completed; }
public void SetTreeAsset(AssetLibraryAsset asset) { m_asset = asset; m_Initialized = false; }
private static void CreateAssetLibraryFromScene(Scene scene, int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs) { TypeMap typeMap = new TypeMap(); AssetDB assetDB = new AssetDB(); IOC.Register <ITypeMap>(typeMap); IOC.Register <IAssetDB>(assetDB); PersistentRuntimeScene rtScene = new PersistentRuntimeScene(); GetDepsFromContext ctx = new GetDepsFromContext(); rtScene.GetDepsFrom(scene, ctx); IOC.Unregister <ITypeMap>(typeMap); IOC.Unregister <IAssetDB>(assetDB); int identity = asset.AssetLibrary.Identity; foreach (UnityObject obj in ctx.Dependencies) { if (hs.Contains(obj)) { continue; } if (obj is GameObject) { GameObject go = (GameObject)obj; if (go.IsPrefab()) { AssetInfo assetInfo = new AssetInfo(go.name, 0, identity); assetInfo.Object = go; identity++; List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>(); AssetLibraryAssetsGUI.CreatePefabParts(go, ref identity, prefabParts); if (prefabParts.Count >= AssetLibraryInfo.MAX_ASSETS - AssetLibraryInfo.INITIAL_ID) { EditorUtility.DisplayDialog("Unable Create AssetLibrary", string.Format("Max 'Indentity' value reached. 'Identity' == {0}", AssetLibraryInfo.MAX_ASSETS), "OK"); return; } if (identity >= AssetLibraryInfo.MAX_ASSETS) { SaveAssetLibrary(asset, scene, index); index++; asset = ScriptableObject.CreateInstance <AssetLibraryAsset>(); folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First(); identity = asset.AssetLibrary.Identity; } assetInfo.PrefabParts = prefabParts; asset.AssetLibrary.Identity = identity; folder.Assets.Add(assetInfo); } } else { AssetInfo assetInfo = new AssetInfo(obj.name, 0, identity); assetInfo.Object = obj; identity++; if (identity >= AssetLibraryInfo.MAX_ASSETS) { SaveAssetLibrary(asset, scene, index); index++; asset = ScriptableObject.CreateInstance <AssetLibraryAsset>(); folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First(); identity = asset.AssetLibrary.Identity; } asset.AssetLibrary.Identity = identity; folder.Assets.Add(assetInfo); } } SaveAssetLibrary(asset, scene, index); index++; Selection.activeObject = asset; EditorGUIUtility.PingObject(asset); }
private static HashSet <UnityObject> ReadFromAssetLibraries(Scene scene, out int index, out AssetLibraryAsset asset, out AssetFolderInfo folder) { HashSet <UnityObject> hs = new HashSet <UnityObject>(); string[] guids = AssetDatabase.FindAssets("", new[] { "Assets/" + BHPath.Root + "/RTSaveLoad2/Resources_Auto/Resources/" + scene.name }); List <AssetLibraryAsset> assetLibraries = new List <AssetLibraryAsset>(); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); AssetLibraryAsset assetLibrary = AssetDatabase.LoadAssetAtPath <AssetLibraryAsset>(path); if (assetLibrary != null) { assetLibrary.Foreach(assetInfo => { if (assetInfo.Object != null) { if (!hs.Contains(assetInfo.Object)) { hs.Add(assetInfo.Object); } if (assetInfo.PrefabParts != null) { foreach (PrefabPartInfo prefabPart in assetInfo.PrefabParts) { if (prefabPart.Object != null) { if (!hs.Contains(prefabPart.Object)) { hs.Add(prefabPart.Object); } } } } } return(true); }); assetLibraries.Add(assetLibrary); } } if (assetLibraries.Count == 0) { asset = ScriptableObject.CreateInstance <AssetLibraryAsset>(); index = 0; } else { asset = assetLibraries.OrderBy(a => a.AssetLibrary.Identity).FirstOrDefault(); index = assetLibraries.Count - 1; } folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First(); if (folder.Assets == null) { folder.Assets = new List <AssetInfo>(); } return(hs); }