Ejemplo n.º 1
0
        private static void TryAssignNewId(SmartNetIdentity identity)
        {
            Init();

            if (IdentityLibrary.Get(identity.AssetId) != identity)
            {
                AssignAssetId(identity, IdentityLibrary.GetNextPrefabId());
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private static string[] OnWillSaveAssets(string[] paths)
        {
            EditorApplication.delayCall += () =>
            {
                foreach (var path in paths)
                {
                    SmartNetIdentityManager.Add(path);
                }

                IdentityLibrary.RemoveNullReferences();
            };

            return(paths);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }