private static void TryAssignNewId(SmartNetIdentity identity) { Init(); if (IdentityLibrary.Get(identity.AssetId) != identity) { AssignAssetId(identity, IdentityLibrary.GetNextPrefabId()); } }
private static void Init() { LastKnownPath = EditorPrefs.GetString(LastKnownPathKey, EditorUtility.DefaultIdentityLibraryFilePath); bool create; IdentityLibrary library; if (!IdentityLibrary.Exists()) { library = AssetDatabase.LoadAssetAtPath <IdentityLibrary>(LastKnownPath); create = false; if (library == null) { library = SearchProjectForLibrary(); if (library != null) { LastKnownPath = AssetDatabase.GetAssetPath(library); } } if (library == null) { LastKnownPath = EditorUtility.DefaultIdentityLibraryFilePath; library = ScriptableObject.CreateInstance <IdentityLibrary>(); create = true; } } else { library = IdentityLibrary.Ins; LastKnownPath = AssetDatabase.GetAssetPath(IdentityLibrary.Ins); create = string.IsNullOrEmpty(LastKnownPath); if (create) { LastKnownPath = EditorUtility.DefaultIdentityLibraryFilePath; } } if (create) { Debug.Log($"Creating new IdentityLibrary at {LastKnownPath}."); AssetDatabase.CreateAsset(library, LastKnownPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } SetLastKnownPath(LastKnownPath); }
private static string[] OnWillSaveAssets(string[] paths) { EditorApplication.delayCall += () => { foreach (var path in paths) { SmartNetIdentityManager.Add(path); } IdentityLibrary.RemoveNullReferences(); }; return(paths); }
public static bool Remove(SmartNetIdentity identity) { Init(); if (identity == null) { return(false); } IdentityLibrary.RemoveNullReferences(); if (IdentityLibrary.Remove(identity)) { UnityEditor.EditorUtility.SetDirty(IdentityLibrary.Ins); return(true); } return(false); }
public static bool Add(string file) { Init(); var identity = GetIdentity(file); if (identity == null) { return(false); } TryAssignNewId(identity); IdentityLibrary.RemoveNullReferences(); if (IdentityLibrary.Add(identity)) { UnityEditor.EditorUtility.SetDirty(IdentityLibrary.Ins); return(true); } return(false); }