Пример #1
0
 private void OnPrefabRemovedFromLib(RTPrefabLib prefabLib, RTPrefab prefab)
 {
     if (HasRuntimeUI && prefabLib == ActiveLib)
     {
         _runtimeUI.PrefabScrollView.SyncWithLib(prefabLib);
     }
 }
Пример #2
0
 private void OnPrefabLibCleared(RTPrefabLib prefabLib)
 {
     if (HasRuntimeUI && prefabLib == ActiveLib)
     {
         _runtimeUI.PrefabScrollView.ClearPreviews();
     }
 }
Пример #3
0
        public RTPrefabLib CreateLib(string libName)
        {
            if (string.IsNullOrEmpty(libName))
            {
                return(null);
            }

            string      finalName = UniqueNameGen.Generate(libName, GetAllLibNames());
            RTPrefabLib lib       = new RTPrefabLib();

            lib.Name = finalName;
            _libs.Add(lib);

            if (HasRuntimeUI && Application.isPlaying)
            {
                _runtimeUI.ActiveLibDropDown.SyncWithLibDb();
            }
            if (_activeLibIndex == -1)
            {
                SetActiveLib(0);
            }

            lib.PrefabCreated += OnPrefabCreatedInLib;
            lib.PrefabRemoved += OnPrefabRemovedFromLib;
            lib.Cleared       += OnPrefabLibCleared;

            return(lib);
        }
Пример #4
0
 private void OnPrefabCreatedInLib(RTPrefabLib prefabLib, RTPrefab prefab)
 {
     if (HasRuntimeUI && prefabLib == ActiveLib && Application.isPlaying)
     {
         _runtimeUI.PrefabScrollView.AddPrefabPreview(prefab);
     }
 }
Пример #5
0
        public void Remove(RTPrefabLib lib)
        {
            int libIndex = GetLibIndex(lib);

            if (libIndex >= 0)
            {
                Remove(libIndex);
            }
        }
Пример #6
0
 public void SyncWithLib(RTPrefabLib prefabLib)
 {
     ClearPreviews();
     if (prefabLib != null)
     {
         for (int prefabIndex = 0; prefabIndex < prefabLib.NumPrefabs; ++prefabIndex)
         {
             RTPrefab prefab = prefabLib.GetPrefab(prefabIndex);
             AddPrefabPreview(prefab);
         }
     }
 }
Пример #7
0
        public void SortLibsByName()
        {
            RTPrefabLib activeLib = ActiveLib;

            _libs.Sort(delegate(RTPrefabLib l0, RTPrefabLib l1)
                       { return(l0.Name.CompareTo(l1.Name)); });

            if (activeLib != null)
            {
                SetActiveLib(activeLib);
            }
        }
        protected override void PerformDrop()
        {
            if (PrefabLibDb == null || PrefabLibDb.ActiveLib == null)
            {
                return;
            }

            EditorUndoEx.Record(PrefabLibDb);

            PrefabLibDb.EditorPrefabPreviewGen.BeginGenSession(PrefabLibDb.PrefabPreviewLookAndFeel);
            var objectRefs = DragAndDrop.objectReferences;

            foreach (var objectRef in objectRefs)
            {
                GameObject prefab = objectRef as GameObject;
                if (prefab == null || prefab.IsSceneObject())
                {
                    continue;
                }

                Texture2D prefabPreview = PrefabLibDb.EditorPrefabPreviewGen.Generate(prefab);
                PrefabLibDb.ActiveLib.CreatePrefab(prefab, prefabPreview);
            }

            var paths      = DragAndDrop.paths;
            var allFolders = FileSystem.GetFoldersAndChildFolderPaths(paths);

            RTPrefabLib lastCreatedLib = null;

            for (int folderIndex = 0; folderIndex < allFolders.Count; ++folderIndex)
            {
                string folderPath = allFolders[folderIndex];
                EditorUtility.DisplayProgressBar("Processing dropped folders", "Please wait... (" + folderPath + ")", (float)folderIndex / allFolders.Count);
                RTPrefabLib newPrefabLib = PrefabLibDb.CreateLib(FileSystem.GetLastFolderNameInPath(folderPath));
                lastCreatedLib = newPrefabLib;

                var prefabsInFolder = AssetDatabaseEx.LoadPrefabsInFolder(folderPath, false, false);
                foreach (var prefab in prefabsInFolder)
                {
                    Texture2D prefabPreview = PrefabLibDb.EditorPrefabPreviewGen.Generate(prefab);
                    newPrefabLib.CreatePrefab(prefab, prefabPreview);
                }
            }
            EditorUtility.ClearProgressBar();
            PrefabLibDb.EditorPrefabPreviewGen.EndGenSession();

            if (lastCreatedLib != null)
            {
                PrefabLibDb.SetActiveLib(lastCreatedLib);
            }
        }
Пример #9
0
 public void RefreshEditorPrefabPreviews()
 {
     EditorPrefabPreviewGen.BeginGenSession(PrefabPreviewLookAndFeel);
     for (int libIndex = 0; libIndex < NumLibs; ++libIndex)
     {
         RTPrefabLib lib = _libs[libIndex];
         EditorUtility.DisplayProgressBar("Refreshing previews...", lib.Name, (float)(libIndex + 1) / NumLibs);
         for (int prefabIndex = 0; prefabIndex < lib.NumPrefabs; ++prefabIndex)
         {
             RTPrefab prefab = lib.GetPrefab(prefabIndex);
             if (prefab.PreviewTexture != null)
             {
                 Texture2D.DestroyImmediate(prefab.PreviewTexture);
             }
             prefab.PreviewTexture = EditorPrefabPreviewGen.Generate(prefab.UnityPrefab);
         }
     }
     EditorUtility.ClearProgressBar();
     EditorPrefabPreviewGen.EndGenSession();
 }
Пример #10
0
        public void Remove(int libIndex)
        {
            if (libIndex >= 0 && libIndex < NumLibs)
            {
                RTPrefabLib removedLib = _libs[libIndex];
                RTPrefabLib activeLib  = ActiveLib;

                _libs.RemoveAt(libIndex);
                _activeLibIndex = _libs.IndexOf(activeLib);
                if (_activeLibIndex < 0)
                {
                    _activeLibIndex = 0;
                }

                if (HasRuntimeUI && Application.isPlaying)
                {
                    _runtimeUI.ActiveLibDropDown.SyncWithLibDb();
                }
            }
        }
Пример #11
0
        public bool SetLibName(RTPrefabLib lib, string newLibName)
        {
            if (lib.Name == newLibName || !Contains(lib))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(newLibName))
            {
                return(false);
            }

            string finalName = UniqueNameGen.Generate(newLibName, GetAllLibNames());

            lib.Name = finalName;

            if (HasRuntimeUI && Application.isPlaying)
            {
                _runtimeUI.ActiveLibDropDown.SyncWithLibDb();
            }

            return(true);
        }
Пример #12
0
 public int GetLibIndex(RTPrefabLib lib)
 {
     return(_libs.IndexOf(lib));
 }
Пример #13
0
 public bool Contains(RTPrefabLib lib)
 {
     return(_libs.Contains(lib));
 }
Пример #14
0
        public void SetActiveLib(RTPrefabLib lib)
        {
            int libIndex = GetLibIndex(lib);

            SetActiveLib(libIndex);
        }