Beispiel #1
0
        protected override bool ValidatePinned(Object[] items)
        {
            if (Application.isPlaying)
            {
                return(false);
            }

            foreach (var item in items)
            {
                var localIdentifierInFile = UnityEditorUtility.GetLocalIdentifierInFile(item);

                // Sceneに保存されていないGameObjectは登録不可.
                if (localIdentifierInFile <= 0)
                {
                    return(false);
                }

                // Hierarchyのオブジェクト以外が登録不可.
                if (EditorUtility.IsPersistent(item))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
            //----- method -----

            internal TargetAssetInfo(Object target, string path, string fullPath)
            {
                this.guid = GetGuid(fullPath);
                this.AssetReferenceInfo = new AssetReferenceInfo(path, target);

                // DLLでMonoScriptだったらDLLの中のコンポーネントなのでfileIDを取り出す.
                if (path.EndsWith(".dll") && target is MonoScript)
                {
                    fileId = UnityEditorUtility.GetLocalIdentifierInFile(target).ToString();
                }
            }
Beispiel #3
0
        protected override void Load()
        {
            pinning = new List <PinnedItem>();

            var prefsKey = GetPinnedPrefsKey();

            var saveData = ProjectPrefs.Get <List <SaveData> >(prefsKey, null);

            if (saveData == null)
            {
                return;
            }

            if (saveData.Any())
            {
                // Hierarchy上のGameObjectを検索して取得.
                var hierarchyObjects = UnityEditorUtility.FindAllObjectsInHierarchy();

                foreach (var data in saveData)
                {
                    if (data.localIdentifierInFile == -1)
                    {
                        continue;
                    }

                    var targetObject = hierarchyObjects.FirstOrDefault(y => UnityEditorUtility.GetLocalIdentifierInFile(y) == data.localIdentifierInFile) as Object;

                    if (targetObject == null)
                    {
                        continue;
                    }

                    var item = new PinnedItem()
                    {
                        target  = targetObject,
                        comment = data.comment,
                    };

                    pinning.Add(item);
                }
            }
        }
Beispiel #4
0
        protected override void Save()
        {
            var prefsKey = GetPinnedPrefsKey();

            var saveData = new List <SaveData>();

            foreach (var item in pinning)
            {
                if (item == null || item.target == null)
                {
                    continue;
                }

                var localIdentifierInFile = UnityEditorUtility.GetLocalIdentifierInFile(item.target);

                if (localIdentifierInFile == -1)
                {
                    continue;
                }

                var data = new SaveData()
                {
                    localIdentifierInFile = localIdentifierInFile,
                    comment = item.comment,
                };

                saveData.Add(data);
            }

            if (saveData.Any())
            {
                ProjectPrefs.Set(prefsKey, saveData);
            }
            else
            {
                if (ProjectPrefs.HasKey(prefsKey))
                {
                    ProjectPrefs.DeleteKey(prefsKey);
                }
            }
        }