private void DataBind(bool clearItems) { if (m_items == null) { m_listBox.SelectedItems = null; m_listBox.Items = null; } else { if (clearItems) { if (m_listBox == null) { Debug.LogError("ListBox is null"); } m_listBox.Items = null; } m_listBox.SelectedItems = null; List <ProjectItem> itemsList = m_items.ToList(); if (TypeFilter != null) { for (int i = itemsList.Count - 1; i >= 0; i--) { ProjectItem item = itemsList[i]; if (item.IsFolder) { itemsList.Remove(item); } else { AssetItem assetItem = (AssetItem)item; Type type = m_typeMap.ToType(assetItem.TypeGuid); if (type == null) { itemsList.RemoveAt(i); } else if (!TypeFilter.IsAssignableFrom(type)) { itemsList.RemoveAt(i); } } } if (typeof(GameObject) == TypeFilter) { IEnumerable <GameObject> sceneObjects = RuntimeEditorApplication.IsPlaying ? ExposeToEditor.FindAll(ExposeToEditorObjectType.PlayMode) : ExposeToEditor.FindAll(ExposeToEditorObjectType.EditorMode); foreach (GameObject go in sceneObjects) { AssetItem sceneItem = new AssetItem(); sceneItem.ItemID = m_assetDB.ToID(go); sceneItem.Name = go.name; sceneItem.Ext = m_project.GetExt(go); sceneItem.TypeGuid = m_typeMap.ToGuid(typeof(GameObject)); itemsList.Add(sceneItem); } } else if (typeof(Component).IsAssignableFrom(TypeFilter)) { IEnumerable <GameObject> sceneObjects = RuntimeEditorApplication.IsPlaying ? ExposeToEditor.FindAll(ExposeToEditorObjectType.PlayMode) : ExposeToEditor.FindAll(ExposeToEditorObjectType.EditorMode); foreach (GameObject go in sceneObjects) { Component component = go.GetComponent(TypeFilter); Guid typeGuid = m_typeMap.ToGuid(component.GetType()); if (component != null && typeGuid != Guid.Empty) { AssetItem sceneItem = new AssetItem(); sceneItem.ItemID = m_assetDB.ToID(go); sceneItem.Name = go.name; sceneItem.Ext = m_project.GetExt(go); sceneItem.TypeGuid = typeGuid; itemsList.Add(sceneItem); } } } //itemsList.Insert(0, none); m_listBox.Items = itemsList; } else { m_listBox.Items = itemsList; } //if (m_selectedItems != null) //{ // m_listBox.SelectedItems = SelectionToProjectItemObjectPair(m_selectedItems); //} } }
private static void SaveDependencies(GetDepsFromContext context, ITypeMap typeMap, IAssetDB assetDB, string path) { object[] dependencies = context.Dependencies.ToArray(); foreach (UnityObject dep in dependencies) { Type persistentType = typeMap.ToPersistentType(dep.GetType()); if (persistentType != null) { context.Dependencies.Clear(); IPersistentSurrogate persistentObject = (IPersistentSurrogate)Activator.CreateInstance(persistentType); persistentObject.GetDepsFrom(dep, context); SaveDependencies(context, typeMap, assetDB, path); } } foreach (UnityObject dep in dependencies) { if (dep is Component || dep is GameObject || !assetDB.IsDynamicResourceID(assetDB.ToID(dep))) { continue; } string name = dep.name; if (string.IsNullOrWhiteSpace(name)) { name = dep.GetType().Name; } string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(string.Format("{0}/{1}.asset", path, name)); AssetDatabase.CreateAsset(dep, uniqueAssetPath); } }
protected long ToID(UnityObject uo) { return(m_assetDB.ToID(uo)); }
protected virtual TID ToID(UnityObject uo) { return(m_assetDB.ToID(uo)); }
private void OnLoadCompleted(AssetItem rootItem, AssetItem[] assetItems, PersistentObject[] persistentObjects, ProjectEventHandler <UnityObject> callback) { for (int i = 0; i < assetItems.Length; ++i) { AssetItem assetItem = assetItems[i]; if (!m_assetDB.IsMapped(assetItem.ItemID)) { if (m_assetDB.IsStaticResourceID(assetItem.ItemID)) { int ordinal = m_assetDB.ToOrdinal(assetItem.ItemID); if (m_assetDB.IsLibraryRefLoaded(ordinal)) { m_assetDB.RemoveLibrary(ordinal); } if (!m_assetDB.IsLibraryLoaded(ordinal)) { AssetLibraryReferenceInfo reference = m_projectInfo.References.FirstOrDefault(r => r.Ordinal == ordinal); if (reference != null) { m_assetDB.LoadLibrary(reference.AssetLibrary, reference.Ordinal); } } } else if (m_assetDB.IsDynamicResourceID(assetItem.ItemID)) { PersistentObject persistentObject = persistentObjects[i]; if (persistentObject != null) { if (persistentObject is PersistentPrefab) { PersistentPrefab persistentPrefab = (PersistentPrefab)persistentObject; Dictionary <int, UnityObject> idToObj = new Dictionary <int, UnityObject>(); List <GameObject> createdGameObjects = new List <GameObject>(); persistentPrefab.CreateGameObjectWithComponents(m_typeMap, persistentPrefab.Descriptors[0], idToObj, createdGameObjects); m_assetDB.RegisterDynamicResources(idToObj); for (int j = 0; j < createdGameObjects.Count; ++j) { GameObject createdGO = createdGameObjects[i]; createdGO.transform.SetParent(createdGO.transform, false); m_dynamicResources.Add(unchecked ((int)m_assetDB.ToID(createdGO)), createdGO); } } else { Type type = m_typeMap.ToType(assetItem.TypeGuid); UnityObject instance = m_factory.CreateInstance(type); m_assetDB.RegisterDynamicResource(unchecked ((int)assetItem.ItemID), instance); m_dynamicResources.Add(unchecked ((int)assetItem.ItemID), instance); } } } } } for (int i = 0; i < persistentObjects.Length; ++i) { PersistentObject persistentObject = persistentObjects[i]; if (persistentObject != null) { if (m_assetDB.IsSceneID(assetItems[i].ItemID)) { persistentObject.WriteTo(SceneManager.GetActiveScene()); } else { UnityObject obj = m_assetDB.FromID <UnityObject>(assetItems[i].ItemID); Debug.Assert(obj != null); if (obj != null) { persistentObject.WriteTo(obj); } } } } UnityObject result = m_assetDB.FromID <UnityObject>(rootItem.ItemID); callback(new Error(Error.OK), result); }
public long ToID(UnityObject obj) { return(m_assetDB.ToID(obj)); }