private void OnPrefabPreviewHoverExit(RTPrefab prefab) { if (PrefabPreviewHoverExit != null) { PrefabPreviewHoverExit(prefab); } }
private void OnPrefabPreviewHoverEnter(RTPrefab prefab) { if (PrefabPreviewHoverEnter != null) { PrefabPreviewHoverEnter(prefab); } }
public void AddPrefabPreview(RTPrefab prefab) { GameObject previewButton = _previewButtonPool.GetPooledObject(); previewButton.name = "Preview_" + prefab.UnityPrefab.name; Image image = previewButton.GetComponent <Image>(); if (image != null) { image.sprite = prefab.PreviewSprite; } RTPrefabPreviewButton previewBtnScript = previewButton.GetComponent <RTPrefabPreviewButton>(); previewBtnScript.Prefab = prefab; previewBtnScript.Text = prefab.UnityPrefab.name; previewBtnScript.HoverEnter -= OnPrefabPreviewHoverEnter; previewBtnScript.HoverEnter += OnPrefabPreviewHoverEnter; previewBtnScript.HoverExit -= OnPrefabPreviewHoverExit; previewBtnScript.HoverExit += OnPrefabPreviewHoverExit; Button button = previewButton.GetComponent <Button>(); if (button != null) { button.onClick.RemoveListener(OnPreviewButtonClicked); button.onClick.AddListener(OnPreviewButtonClicked); } }
private void OnPrefabRemovedFromLib(RTPrefabLib prefabLib, RTPrefab prefab) { if (HasRuntimeUI && prefabLib == ActiveLib) { _runtimeUI.PrefabScrollView.SyncWithLib(prefabLib); } }
private void OnPrefabCreatedInLib(RTPrefabLib prefabLib, RTPrefab prefab) { if (HasRuntimeUI && prefabLib == ActiveLib && Application.isPlaying) { _runtimeUI.PrefabScrollView.AddPrefabPreview(prefab); } }
public List <RTPrefab> CreatePrefabsFromSceneObjects(List <GameObject> sceneObjects) { RTPrefabLibDb.Get.EditorPrefabPreviewGen.BeginGenSession(RTPrefabLibDb.Get.PrefabPreviewLookAndFeel); var createdPrefabs = new List <RTPrefab>(); foreach (var sceneObject in sceneObjects) { GameObject unityPrefab = GameObject.Instantiate(sceneObject); Texture2D prefabPreview = RTPrefabLibDb.Get.EditorPrefabPreviewGen.Generate(unityPrefab); unityPrefab.SetActive(false); var prefab = new RTPrefab(); prefab.UnityPrefab = unityPrefab; prefab.PreviewTexture = prefabPreview; _prefabs.Add(prefab); createdPrefabs.Add(prefab); if (PrefabCreated != null) { PrefabCreated(this, prefab); } } RTPrefabLibDb.Get.EditorPrefabPreviewGen.EndGenSession(); return(createdPrefabs); }
public void Remove(RTPrefab prefab) { int prefabIndex = GetPrefabIndex(prefab); if (prefabIndex >= 0) { Remove(prefabIndex); } }
public void SyncWithLib(RTPrefabLib prefabLib) { ClearPreviews(); if (prefabLib != null) { for (int prefabIndex = 0; prefabIndex < prefabLib.NumPrefabs; ++prefabIndex) { RTPrefab prefab = prefabLib.GetPrefab(prefabIndex); AddPrefabPreview(prefab); } } }
public void Remove(int prefabIndex) { if (prefabIndex >= 0 && prefabIndex < NumPrefabs) { RTPrefab removedPrefab = _prefabs[prefabIndex]; _prefabs.RemoveAt(prefabIndex); if (PrefabRemoved != null) { PrefabRemoved(this, removedPrefab); } } }
private void OnPrefabPreviewButtonClicked(RTPrefab prefab) { if (Settings.SpawnPrefabOnPreviewClick) { GameObject spawnedObject = ObjectSpawnUtil.SpawnInFrontOfCamera(prefab.UnityPrefab, RTFocusCamera.Get.TargetCamera, ObjectSpawnUtil.DefaultConfig); PostObjectSpawnAction action = new PostObjectSpawnAction(new List <GameObject>() { spawnedObject }); action.Execute(); if (PrefabSpawned != null) { PrefabSpawned(prefab, spawnedObject); } } }
public RTPrefab CreatePrefab(GameObject unityPrefab, Texture2D prefabPreview) { if (Contains(unityPrefab) || unityPrefab == null) { return(null); } var prefab = new RTPrefab(); prefab.UnityPrefab = unityPrefab; prefab.PreviewTexture = prefabPreview; _prefabs.Add(prefab); if (PrefabCreated != null) { PrefabCreated(this, prefab); } return(prefab); }
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(); }
public RTPrefab CreatePrefabFromSceneObject(GameObject sceneObject) { GameObject unityPrefab = GameObject.Instantiate(sceneObject); RTPrefabLibDb.Get.EditorPrefabPreviewGen.BeginGenSession(RTPrefabLibDb.Get.PrefabPreviewLookAndFeel); Texture2D prefabPreview = RTPrefabLibDb.Get.EditorPrefabPreviewGen.Generate(unityPrefab); RTPrefabLibDb.Get.EditorPrefabPreviewGen.EndGenSession(); unityPrefab.SetActive(false); var prefab = new RTPrefab(); prefab.UnityPrefab = unityPrefab; prefab.PreviewTexture = prefabPreview; _prefabs.Add(prefab); if (PrefabCreated != null) { PrefabCreated(this, prefab); } return(prefab); }
private void OnPrefabPreviewHoverEnter(RTPrefab prefab) { HoveredPrefabNameLabel.PrefabName = prefab.UnityPrefab != null ? prefab.UnityPrefab.name : string.Empty; }
private void OnPrefabPreviewHoverExit(RTPrefab prefab) { HoveredPrefabNameLabel.PrefabName = string.Empty; }
public int GetPrefabIndex(RTPrefab prefab) { return(_prefabs.IndexOf(prefab)); }
public bool Contains(RTPrefab prefab) { return(_prefabs.Contains(prefab)); }
/// <summary> /// Called when a prefab is spawned in the scene after clicking on one of /// the prefab previews in the prefab lib UI. /// </summary> /// <param name="prefab"> /// The prefab that was spawned. /// </param> /// <param name="spawnedObject"> /// The game object that was spawned from the prefab. /// </param> private void OnPrefabSpawned(RTPrefab prefab, GameObject spawnedObject) { // Begin the snap session BeginSnapSession(spawnedObject); }
public override void OnInspectorGUI() { const float createBtnWidth = 95.0f; int newInt; string newString; var content = new GUIContent(); if (!_libDb.HasRuntimeUI) { EditorGUILayout.HelpBox("No runtime UI is associated with the lib database. You can use the \'Create RT UI\' button to create a UI or connect to an already existing one.", MessageType.Info); } // Create runtime UI EditorGUILayout.BeginHorizontal(); content.text = "Create RT UI"; content.tooltip = "Creates a UI canvas which allows you to interact with the prefab library DB at runtime. If a UI already exists in the scene, that will be used instead."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth))) { _libDb.CreateRuntimeUI(); } // Refresh previews content.text = "Refresh previews"; content.tooltip = "Regenerates ALL prefab previews in ALL prefab libraries."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth + 20.0f))) { _libDb.RefreshEditorPrefabPreviews(); } EditorGUILayout.EndHorizontal(); // Create lib content.text = "Create lib"; content.tooltip = "Creates a new prefab library with the specified name. Note: If a library with the same name already exists, a number suffix will be added."; EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(content, GUILayout.Width(createBtnWidth))) { EditorUndoEx.Record(_libDb); _libDb.SetActiveLib(_libDb.CreateLib(_libDb.NewLibName)); } newString = EditorGUILayout.TextField(_libDb.NewLibName); if (newString != _libDb.NewLibName) { EditorUndoEx.Record(_libDb); _libDb.NewLibName = newString; } EditorGUILayout.EndHorizontal(); // Remove ### EditorGUILayout.BeginHorizontal(); content.text = "Remove active"; content.tooltip = "Removes the active library."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth))) { if (_libDb.ActiveLib != null) { EditorUndoEx.Record(_libDb); _libDb.Remove(_libDb.ActiveLibIndex); } } content.text = "Remove all"; content.tooltip = "Removes all libraries."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth))) { EditorUndoEx.Record(_libDb); _libDb.Clear(); } content.text = "Remove empty"; content.tooltip = "Removes all empty libraries."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth + 10.0f))) { EditorUndoEx.Record(_libDb); _libDb.RemoveEmptyLibs(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); if (_libDb.NumLibs == 0) { EditorGUILayout.HelpBox("There are no libraries currently available. Use the \'Create lib\' button to create a new prefab library.", MessageType.Info); } else { // Active lib selection var libNames = _libDb.GetAllLibNames(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Active library", GUILayout.Width(createBtnWidth)); newInt = EditorGUILayout.Popup(_libDb.ActiveLibIndex, libNames.ToArray()); EditorGUILayout.EndHorizontal(); if (newInt != _libDb.ActiveLibIndex) { EditorUndoEx.Record(_libDb); _libDb.SetActiveLib(newInt); } // Active lib name EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Name", GUILayout.Width(createBtnWidth)); newString = EditorGUILayout.DelayedTextField(_libDb.ActiveLib.Name); EditorGUILayout.EndHorizontal(); if (newString != _libDb.ActiveLib.Name) { EditorUndoEx.Record(_libDb); _libDb.SetLibName(_libDb.ActiveLib, newString); } // Active lib scroll view if (_libDb.ActiveLib != null) { float previewWidth = _libDb.PrefabPreviewLookAndFeel.PreviewWidth; float previewHeight = _libDb.PrefabPreviewLookAndFeel.PreviewHeight; var prefabPreviewContent = new GUIContent(); prefabPreviewContent.text = ""; content.text = "Remove"; content.tooltip = "Remove this prefab from the library."; _libDb.PrefabScrollPos = EditorGUILayout.BeginScrollView(_libDb.PrefabScrollPos, "Box", GUILayout.Height(350.0f)); EditorGUILayout.BeginHorizontal(); for (int prefabIndex = 0; prefabIndex < _libDb.ActiveLib.NumPrefabs; ++prefabIndex) { RTPrefab prefab = _libDb.ActiveLib.GetPrefab(prefabIndex); prefabPreviewContent.tooltip = prefab.UnityPrefab.name; prefabPreviewContent.image = prefab.PreviewTexture; EditorGUILayout.BeginVertical(GUILayout.Width(previewWidth)); GUILayout.Button(prefabPreviewContent, "Box", GUILayout.Width(previewWidth), GUILayout.Height(previewHeight)); if (GUILayout.Button(content, GUILayout.Width(previewWidth))) { EditorUndoEx.Record(_libDb); _libDb.ActiveLib.Remove(prefabIndex); } EditorGUILayout.EndVertical(); if (prefabIndex != 0 && ((prefabIndex + 1) % _libDb.NumPrefabsPerRow == 0)) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); _prefabDropHandler.Handle(Event.current, GUILayoutUtility.GetLastRect()); content.text = "Clear lib"; content.tooltip = "Removes all the prefabs from the active library."; if (GUILayout.Button(content, GUILayout.Width(createBtnWidth))) { EditorUndoEx.Record(_libDb); _libDb.ActiveLib.Clear(); } _libDb.PrefabPreviewLookAndFeel.RenderEditorGUI(_libDb); } } }