/// <summary> /// オブジェクトをユニークIDに変換 /// </summary> public static AssetUniqueID ConvertObjectToUniqueID(Object obj) { var assetPath = AssetDatabase.GetAssetPath(obj); var guid = AssetDatabase.AssetPathToGUID(assetPath); var result = new AssetUniqueID(guid); bool hasFileID; var linkerType = GetLinkerType(assetPath); switch (linkerType) { case GetLinkerTypeReturn.Home: case GetLinkerTypeReturn.MetaHome: case GetLinkerTypeReturn.Script: hasFileID = false; break; case GetLinkerTypeReturn.Importer: hasFileID = AssetDatabase.IsSubAsset(obj); break; default: hasFileID = true; break; } if (hasFileID) { var instanceID = obj.GetInstanceID(); var fileID = Unsupported.GetLocalIdentifierInFile(instanceID); result.fileID = fileID; } return(result); }
public void Set(Object newObject) { #if UNITY_EDITOR if (newObject != m_CachedObject) { if (newObject == null) { m_FileId = 0; m_GUID = ""; m_CachedObject = null; } else { m_FileId = Unsupported.GetLocalIdentifierInFile(newObject.GetInstanceID()); XDebug.Assert(m_FileId > 0, "EditorOnlyObjectReference: object not in file. Can only hold saved asset references in EditorOnlyObjectReference"); if (m_FileId > 0) { m_CachedObject = newObject; m_GUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(newObject)); } } } #else #endif }
public Object EditorResolveSlow(bool bLoadScene) { var scene = this.scene.scene; if (!scene.IsValid()) { return(null); } if (!scene.isLoaded) { if (!bLoadScene) { return(null); } EditorSceneManager.LoadScene(scene.path); } AmsDebug.LogError(null, "Performing EditorResolveSlow but it was never tested"); // Find the object (this is potentially very slow). Object[] allObjs = EditorUtility.CollectDeepHierarchy(scene.GetRootGameObjects()); foreach (var obj in allObjs) { if (editorLocalId == Unsupported.GetLocalIdentifierInFile(obj.GetInstanceID())) { return(obj); } } return(null); }
private static Object GetObjectFromGUIDAndFileID(string guid, int fileid) { string path = AssetDatabase.GUIDToAssetPath(guid); Object[] loadedObjects = AssetDatabase.LoadAllAssetsAtPath(path); for (int i = 0; i < loadedObjects.Length; ++i) { int localFileID = Unsupported.GetLocalIdentifierInFile(loadedObjects[i].GetInstanceID()); if (localFileID == fileid) { return(loadedObjects[i]); } } return(null); }
bool CheckAssetMatch(List <Object> asset1, List <Object> asset2) { if (asset1.Count != asset2.Count) { return(false); } for (int i = 0; i < asset1.Count; i++) { if (Unsupported.GetLocalIdentifierInFile(asset1[i].GetInstanceID()) != Unsupported.GetLocalIdentifierInFile(asset2[i].GetInstanceID())) { return(false); } } return(true); }
public static void ObjectLabelField(Rect position, string guid, int fileID, GUIStyle style) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); Object value; if (fileID != 0) { value = CustomGUIDetail.LoadAllAssetsAtPath(assetPath) .Where(x => Unsupported.GetLocalIdentifierInFile(x.GetInstanceID()) == fileID) .FirstOrDefault(); } else { value = AssetDatabase.LoadMainAssetAtPath(assetPath); } ObjectLabelField(position, value, style); }
static MonoScript FindEvolvePrefabScriptAsset(out string fileID, out string guid, out string path) { var paths = AssetDatabase.GetAllAssetPaths().Where(assetPath => assetPath.EndsWith(".dll") || assetPath.EndsWith(".cs")).ToArray(); fileID = guid = path = ""; foreach (var assetPath in paths) { var result = AssetDatabase.LoadAllAssetsAtPath(assetPath).OfType <MonoScript>().FirstOrDefault(script => script.GetClass() == typeof(EvolvePrefab)); if (result == null) { continue; } path = assetPath; guid = AssetDatabase.AssetPathToGUID(assetPath); fileID = Unsupported.GetLocalIdentifierInFile(result.GetInstanceID()).ToString(); return(result); } return(null); }
public static void SetSerializedPropertyWithObject(SerializedProperty serializedProperty, Object referencedObject) { SerializedProperty fileId = serializedProperty.FindPropertyRelative("m_FileId"); SerializedProperty guid = serializedProperty.FindPropertyRelative("m_GUID"); if ((fileId != null) && (guid != null)) { if (referencedObject == null) { fileId.intValue = 0; guid.stringValue = ""; } else { int localFileId = Unsupported.GetLocalIdentifierInFile(referencedObject.GetInstanceID()); fileId.intValue = localFileId; if (localFileId > 0) { guid.stringValue = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(referencedObject)); ; } } } }
public static int GetLocalID(int instanceID) { return(Unsupported.GetLocalIdentifierInFile(instanceID)); }
protected virtual void OnGUI() { if (this.GUIDs[this.GUIDs.Count - 1] != string.Empty) { this.GUIDs.Add(string.Empty); this.entries.Add(new Entry()); } this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition); { using (LabelWidthRestorer.Get(50F)) { for (int i = 0; i < this.GUIDs.Count; i++) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { EditorGUI.BeginChangeCheck(); this.GUIDs[i] = EditorGUILayout.TextField("GUID", this.GUIDs[i]); if (EditorGUI.EndChangeCheck() == true) { if (string.IsNullOrEmpty(this.GUIDs[i]) == false) { if (this.entries[i].lastGUID != this.GUIDs[i]) { this.entries[i].lastGUID = this.GUIDs[i]; this.ProcessGUID(i); } } else { this.entries[i].lastGUID = string.Empty; this.entries[i].assetPath = string.Empty; this.entries[i].assetObject = null; this.entries[i].assetPreview = null; } } if (string.IsNullOrEmpty(this.GUIDs[i]) == true) { for (int j = i + 1; j < this.GUIDs.Count;) { if (string.IsNullOrEmpty(this.GUIDs[j]) == true) { this.GUIDs.RemoveAt(j); this.entries.RemoveAt(j); this.Repaint(); } else { break; } } } EditorGUI.BeginChangeCheck(); Object asset = EditorGUILayout.ObjectField("Asset", this.entries[i].assetObject, typeof(Object), false); if (EditorGUI.EndChangeCheck() == true) { this.entries[i].assetObject = asset; if (asset != null) { this.GUIDs[i] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset)); } else { this.GUIDs[i] = string.Empty; } } if (this.entries[i].assetObject != null) { int fileIdentifier = Unsupported.GetLocalIdentifierInFile(this.entries[i].assetObject.GetInstanceID()); EditorGUILayout.TextField("FileId", fileIdentifier.ToString()); } } EditorGUILayout.EndVertical(); if (this.entries[i].assetPreview != null) { EditorGUI.DrawTextureTransparent(GUILayoutUtility.GetRect(0F, 0F, GUILayoutOptionPool.Width(32F), GUILayoutOptionPool.Height(32F)), this.entries[i].assetPreview, ScaleMode.ScaleToFit); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(10F); } } } EditorGUILayout.EndScrollView(); }