//The window draw method void OnGUI() { //Initialize Styles InitStyles(); //Draw the Toolbar for the Character editor Toolbar(new Rect(0f, 0f, position.width, 18f)); //Draw the Character Sheet editor when a sheet is available if (sheet != null) { scrollView = GUI.BeginScrollView(new Rect(0f, 18f, position.width, position.height - 18f), scrollView, new Rect(8f, 8f, position.width - 16f, 272f), false, true); CharacterSheet(new Rect(16f, 16f, position.width, position.height)); GUI.EndScrollView(); } //Check for Events if (Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == 10) { sheet.profile = (Texture2D)EditorGUIUtility.GetObjectPickerObject(); Repaint(); } } }
private void HandleObjectPicker(int controlID) { switch (Event.current.commandName) { case "ObjectSelectorUpdated": if (EditorGUIUtility.GetObjectPickerControlID() != controlID) { return; } var selectedScene = (SceneAsset)EditorGUIUtility.GetObjectPickerObject(); var elementProperty = _property.GetArrayElementAtIndex(_property.arraySize - 1); if (selectedScene) { elementProperty.objectReferenceValue = SceneReferenceAsset.FindOrCreate(selectedScene); } else { elementProperty.objectReferenceValue = null; } break; case "ObjectSelectorClosed": RemoveNull(_reorderableList); break; } }
private void UpdateObjectPicker() { if (Event.current.commandName == "ObjectSelectorClosed") { switch (EditorGUIUtility.GetObjectPickerControlID()) { case (int)EditorCommons.WindowCommands.AddConcept: { Concept concept = (Concept)EditorGUIUtility.GetObjectPickerObject(); if (concept == null) { return; } if (!target.ContainsConcept(concept)) { target.AddConcept(concept); displayer = new EditorConditionDisplay(target) { DisplayConcepts = true }; EditorUtility.SetDirty(target); EditorUtility.SetDirty(target.gameObject); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } } break; } } }
private void OnGUI() { Workspace?.OnGUI(); // Handle object selection if (Event.current.commandName == "ObjectSelectorUpdated") { if (EditorGUIUtility.GetObjectPickerControlID() == _openFileControlId) { var target = EditorGUIUtility.GetObjectPickerObject() as PixelArt; if (target != null) { OpenFile(target); } else { CloseFile(); } } } else if (Event.current.commandName == "ObjectSelectorClosed") { _openFileControlId = -1; } }
void WritePickedObject() { if (Event.current.commandName != "ObjectSelectorClosed" || Event.current.type != EventType.ExecuteCommand) { return; } var id = EditorGUIUtility.GetObjectPickerControlID(); if (id != SortableListDefinitions.PICKER_CONTROL_ID) { return; } var obj = EditorGUIUtility.GetObjectPickerObject(); if (obj == null || !(obj is StatDefinitionBase)) { return; } var def = (StatDefinitionBase)obj; if (Target.definitions.Contains(def)) { return; } _propDefinitions.arraySize += 1; _propDefinitions.GetArrayElementAtIndex(_propDefinitions.arraySize - 1).objectReferenceValue = def; }
public override bool DrawLayout() { m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition); try { if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == s_ObjectPickerId) { var @object = EditorGUIUtility.GetObjectPickerObject(); if (null != @object) { m_MainModule.Dereference(m_Registry).AddAsset(@object); m_TreeView.SetDirty(); } } var selections = m_TreeView.GetSelection(); m_AssetPreviewControl.SetAssets(selections.Select(s => m_TreeView.Model.Find(s)).NotNull()); return(base.DrawLayout()); } finally { EditorGUILayout.EndScrollView(); } }
protected override void updateHeaderControl4(Rect position) { Transform actor = (TrackGroup.Behaviour as ActorTrackGroup).Actor; Color temp = GUI.color; GUI.color = (actor == null) ? Color.red : Color.green; int controlID = GUIUtility.GetControlID("ActorTrackGroupControl".GetHashCode(), FocusType.Passive, position); GUI.enabled = !state.IsInPreviewMode; if (GUI.Button(position, string.Empty, styles.pickerStyle)) { EditorGUIUtility.ShowObjectPicker <Transform>(actor, true, string.Empty, controlID); } GUI.enabled = true; if (Event.current.commandName == "ObjectSelectorUpdated") { if (EditorGUIUtility.GetObjectPickerControlID() == controlID) { GameObject pickedObject = EditorGUIUtility.GetObjectPickerObject() as GameObject; if (pickedObject != null) { ActorTrackGroup atg = (TrackGroup.Behaviour as ActorTrackGroup); Undo.RecordObject(atg, string.Format("Changed {0}", atg.name)); atg.Actor = pickedObject.transform; } } } GUI.color = temp; }
/// <summary> /// UI to add a new image marker to the marker library /// </summary> /// <param name="markerLibrary">The marker library currently being edited</param> static void DrawAddImageMarkerButton(MarsMarkerLibrary markerLibrary) { const int pickerID = 0xC0FFEE; const string objectSelectorClosed = "ObjectSelectorClosed"; if (GUILayout.Button(styles.AddImageMarkerButton, MarsEditorGUI.InternalEditorStyles.FooterButtonStyle, GUILayout.Width(Styles.AddRemoveButtonSize), GUILayout.Height(Styles.AddRemoveButtonSize))) { EditorGUIUtility.ShowObjectPicker <Texture2D>(null, false, "", pickerID); s_FlagSelectingMarker = true; } if (Event.current.commandName == objectSelectorClosed && EditorGUIUtility.GetObjectPickerControlID() == pickerID && s_FlagSelectingMarker) { var selectedTexture = EditorGUIUtility.GetObjectPickerObject() as Texture2D; const string addEmptyImage = "Add an empty image marker"; Undo.RecordObject(markerLibrary, addEmptyImage); markerLibrary.CreateAndAdd(); markerLibrary.SetGuid(markerLibrary.Count - 1, Guid.NewGuid()); markerLibrary.SetTexture(markerLibrary.Count - 1, selectedTexture); EditorUtility.SetDirty(markerLibrary); markerLibrary.SaveMarkerLibrary(); s_FlagSelectingMarker = false; } }
public static T DrawProObjectField <T>(T obj, params GUILayoutOption[] options) where T : UnityEngine.Object { int pickerID = "ShurikenObjectField".GetHashCode(); var rect = EditorGUILayout.GetControlRect(false, Styles.shurikenLineHeight, Styles.ShurikenValue, options); var btnRect = rect; btnRect.width = 20; rect.xMax -= btnRect.width; btnRect.x += rect.width; GUI.Label(rect, TCP2_GUI.TempContent(obj != null ? obj.name : "None (" + typeof(T).ToString() + ")"), Styles.ShurikenValue); if (GUI.Button(btnRect, "...", "MiniToolbarButton")) { EditorGUIUtility.ShowObjectPicker <T>(obj, false, "", pickerID); } if (Event.current.commandName == "ObjectSelectorUpdated") { if (EditorGUIUtility.GetObjectPickerControlID() == pickerID) { obj = EditorGUIUtility.GetObjectPickerObject() as T; } } return(obj); }
/// <summary> /// Retrieves the selected picker object, if available. /// </summary> /// <param name="name">The event name.</param> /// <returns> /// The newly selected object, or null if a selection hasn't been made, or /// if the picker window isn't open. /// </returns> public Object PickerObject(string name) { if (!pickerWindows.ContainsKey(name)) { return(null); } int pickerWindow = pickerWindows[name]; if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == pickerWindow) { pickerObjects[name] = EditorGUIUtility.GetObjectPickerObject(); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == pickerWindow) { pickerWindows.Remove(name); Object obj = null; if (pickerObjects.ContainsKey(name)) { obj = pickerObjects[name]; pickerObjects.Remove(name); } return(obj); } return(null); }
static void WaitForObjectPicker() { var objectPickerId = EditorGUIUtility.GetObjectPickerControlID(); if (objectPickerId == 0x51309) { selected = EditorGUIUtility.GetObjectPickerObject(); } else { EditorApplication.update -= WaitForObjectPicker; if (objectPickerId == 0 && selected != null) { var path = AssetDatabase.GetAssetPath(selected); if (path.StartsWith("Assets/", System.StringComparison.InvariantCultureIgnoreCase)) { var guid = AssetDatabase.AssetPathToGUID(path); FGCodeWindow.OpenAssetInTab(guid); } } selected = null; var pickerType = typeof(Editor).Assembly.GetType("UnityEditor.ObjectSelector", false, false); if (pickerType != null) { var pickers = Resources.FindObjectsOfTypeAll(pickerType); foreach (var picker in pickers) { Object.DestroyImmediate(picker); } } } }
// Drop area for compatible Races private void CompatibleRacesDropArea(Rect dropArea, List <string> compatibleRaces) { Event evt = Event.current; //make the box clickable so that the user can select raceData assets from the asset selection window if (evt.type == EventType.MouseUp) { if (dropArea.Contains(evt.mousePosition)) { compatibleRacePickerID = EditorGUIUtility.GetControlID(new GUIContent("crfObjectPicker"), FocusType.Passive); EditorGUIUtility.ShowObjectPicker <RaceData>(null, false, "", compatibleRacePickerID); Event.current.Use(); //stops the Mismatched LayoutGroup errors return; } } if (evt.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == compatibleRacePickerID) { RaceData tempRaceDataAsset = EditorGUIUtility.GetObjectPickerObject() as RaceData; if (tempRaceDataAsset) { AddRaceDataAsset(tempRaceDataAsset, compatibleRaces); } Event.current.Use(); //stops the Mismatched LayoutGroup errors return; } if (evt.type == EventType.DragUpdated) { if (dropArea.Contains(evt.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } } if (evt.type == EventType.DragPerform) { if (dropArea.Contains(evt.mousePosition)) { DragAndDrop.AcceptDrag(); UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences as UnityEngine.Object[]; for (int i = 0; i < draggedObjects.Length; i++) { if (draggedObjects[i]) { RaceData tempRaceDataAsset = draggedObjects[i] as RaceData; if (tempRaceDataAsset) { AddRaceDataAsset(tempRaceDataAsset, compatibleRaces); continue; } var path = AssetDatabase.GetAssetPath(draggedObjects[i]); if (System.IO.Directory.Exists(path)) { RecursiveScanFoldersForAssets(path, compatibleRaces); } } } } } }
void WritePickedObject() { if (Event.current.commandName != "ObjectSelectorClosed" || Event.current.type != EventType.ExecuteCommand) { return; } var id = EditorGUIUtility.GetObjectPickerControlID(); if (id != SortableListModifierGroup.PICKER_CONTROL_ID) { return; } var obj = EditorGUIUtility.GetObjectPickerObject(); if (obj == null || !(obj is StatDefinition)) { return; } _propAdjustments.arraySize += 1; var element = _propAdjustments.GetArrayElementAtIndex(_propAdjustments.arraySize - 1); var def = (StatDefinition)obj; var propDef = element.FindPropertyRelative("definition"); propDef.objectReferenceValue = def; }
public static T ScreenField <T>(T data, bool allowSceneObjects, GUIStyle style) where T : WindowBase { var id = GUIUtility.GetControlID(FocusType.Passive) + 1; var title = data == null ? "None" : data.name; GUILayout.Label(title, style); var rect = GUILayoutUtility.GetLastRect(); var leftRect = rect; leftRect.width -= style.border.right; var rightRect = rect; rightRect.x += leftRect.width; rightRect.width = style.border.right; if (Event.current.clickCount == 1 && leftRect.Contains(Event.current.mousePosition) == true) { Selection.activeObject = data; Event.current.Use(); } if (Event.current.clickCount == 1 && rightRect.Contains(Event.current.mousePosition) == true) { EditorGUIUtility.ShowObjectPicker <T>(data, allowSceneObjects, "t:" + (typeof(T).Name), id); Event.current.Use(); } if (EditorGUIUtility.GetObjectPickerControlID() == id && id > 0) { data = EditorGUIUtility.GetObjectPickerObject() as T; } return(data); }
private void HandleGUICommand() { if (Event.current != null && Event.current.type == EventType.ExecuteCommand) { if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == libraryObjectPickerControlId) { toAddPrefab = EditorGUIUtility.GetObjectPickerObject() as GameObject; } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == libraryObjectPickerControlId) { if (toAddPrefab != null) { instance.EnvironmentalPainterSettings.AddPrefab(toAddPrefab); instance.EnvironmentalPainter.UpdatePreviewer(); toAddPrefab = null; } } } if (Event.current != null && Event.current.type == EventType.MouseMove) { if (currentTab != TAB_TERRAIN) { SceneView.RepaintAll(); } } }
private void DrawTopBar() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); if (GUILayout.Button("Load Graph", EditorStyles.toolbarButton, GUILayout.Width(100))) { controlID = GUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <ScriptableObject> ((ScriptableObject)targetGraph, false, "", controlID); } string commandName = currentEvent.commandName; if (commandName == "ObjectSelectorUpdated") { Repaint(); } else if (commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == controlID) { IBehaviourGraph nextGraph = EditorGUIUtility.GetObjectPickerObject() as IBehaviourGraph; if (nextGraph == null) { // CloseGraph (); } else { if (targetGraph != nextGraph) { OpenGraph(((UnityEngine.Object)nextGraph).GetInstanceID(), 0); } } return; } } GUILayout.Space(5.0f); EditorGUI.BeginDisabledGroup(targetGraph == null); if (GUILayout.Button("Goto Asset", EditorStyles.toolbarButton, GUILayout.Width(100))) { EditorUtility.FocusProjectWindow(); EditorGUIUtility.PingObject((UnityEngine.Object)targetGraph); } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Screenshot", EditorStyles.toolbarButton, GUILayout.Width(100))) { screenshot_TakeScreenshot = true; Repaint(); EditorApplication.delayCall += Repaint; } EditorGUILayout.EndHorizontal(); }
protected SceneAsset ShowAdvancedObjectFieldSceneAsset <T>(SceneAsset aValue, System.Type aObjType, GUIStyle aStyle, bool aAllowSceneObjects, int aIdPicker, int aNbOfStage) where T : UnityEngine.Object { float reduceSize = 206.0f + (aNbOfStage * 10.0f); GUILayout.Space(10f); SceneAsset tObj = aValue; aStyle.imagePosition = ImagePosition.ImageLeft; EditorGUILayout.BeginHorizontal(); if (tObj != null) { EditorGUILayout.LabelField(new GUIContent(" " + tObj.name, m_SceneIcon), aStyle, GUILayout.Width(ScreenWidth - reduceSize)); } else { if (SceneAutoLoader.IsUsingEnglish) { EditorGUILayout.LabelField(new GUIContent(" No <i>" + aObjType.Name + "</i> selected", m_WarningIcon, "You need to select a(n) " + aObjType.Name), aStyle, GUILayout.Width(ScreenWidth - reduceSize)); } else { EditorGUILayout.LabelField(new GUIContent(" Aucun <i>" + aObjType.Name + "</i> sélectionné", m_WarningIcon, "Vous devez sélectionnez un(n) " + aObjType.Name), aStyle, GUILayout.Width(ScreenWidth - reduceSize)); } } EditorGUILayout.LabelField("<size=10>[" + GetColorText("Drag & Drop", true) + "]</size>", m_LabelTxtStyleCenter, GUILayout.Width(85.0f)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); aValue = (SceneAsset)EditorGUILayout.ObjectField(tObj, aObjType, false, GUILayout.Width(ScreenWidth - reduceSize + +103f)); if (GUILayout.Button("Select", m_ButtonStyle, GUILayout.Width(70f))) { EditorGUIUtility.ShowObjectPicker <T>(tObj, aAllowSceneObjects, "", aIdPicker); } EditorGUILayout.EndHorizontal(); if (Event.current.commandName == "ObjectSelectorUpdated") { if (EditorGUIUtility.GetObjectPickerControlID() == aIdPicker) { if (EditorGUIUtility.GetObjectPickerObject() != null) { tObj = (SceneAsset)EditorGUIUtility.GetObjectPickerObject(); } else { tObj = null; } aValue = tObj; } } GUILayout.Space(10f); return(aValue); }
/// <summary> /// Display level description GUI. /// </summary> private void LevelDescriptionGUI() { if (myState == MyState.LevelDescription && mySubState.Contains(MySubState.LevelDescription)) { GUILayout.Space(guiSpace); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Set level icon button if (GUILayout.Button(contents.levelIcon, GUILayout.MaxWidth(100f), GUILayout.MaxHeight(100f)) == true) { ShowPicker(PickerState.LevelIcon, Lables.levelIcon); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // Header GUILayout.Label("Header"); inspectors.levelDescription.header.text = EditorGUILayout.TextField(inspectors.levelDescription.header.text); // Description GUILayout.Label("Description"); inspectors.levelDescription.description.text = EditorGUILayout.TextArea(inspectors.levelDescription.description.text, GUILayout.MaxHeight(80f)); // Attention GUILayout.Label("Attention"); inspectors.levelDescription.attention.text = EditorGUILayout.TextArea(inspectors.levelDescription.attention.text, GUILayout.MaxHeight(40f)); // New object selected in picker window if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { pickedGameObject = EditorGUIUtility.GetObjectPickerObject() as GameObject; if (pickedGameObject != null) { SpriteRenderer spriteRenderer = pickedGameObject.GetComponent <SpriteRenderer>(); if (spriteRenderer != null) { // Set icon in level description inspectors.levelDescription.icon.sprite = spriteRenderer.sprite; EditorUtility.SetDirty(inspectors.levelDescription.gameObject); contents.levelIcon = new GUIContent(inspectors.levelDescription.icon.sprite.texture, "Choose icon for this level"); } } } // Picker window closed if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { pickedGameObject = null; pickerState = PickerState.None; } if (GUI.changed == true) { EditorUtility.SetDirty(inspectors.levelDescription.gameObject); } } }
protected override void DoWindow(int windowID) { Rect imageRect = new Rect(padding, dragableTopHeight, WindowRect.width - padding * 2, WindowRect.height - bottomRowHeight - dragableTopHeight - padding * 2); if (showTexture) { EditorGUI.DrawPreviewTexture(imageRect, showTexture, showImageMat, ScaleMode.ScaleToFit); } else { EditorGUI.DrawPreviewTexture(imageRect, EditorGUIUtility.whiteTexture, showImageMat); } //texture picker EditorGUI.BeginDisabledGroup(!enableButtons); var currentPickerWindow = EditorGUIUtility.GetControlID(FocusType.Passive) + 100; if (GUI.Button(new Rect(padding, WindowRect.height - bottomRowHeight - padding, bottomButtonWidth, bottomRowHeight), "Texture")) { EditorGUIUtility.ShowObjectPicker <Texture2D>(null, true, "", currentPickerWindow); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { if (showTexture != null) { GameObject.DestroyImmediate(showTexture); } var newTex = (Texture2D)EditorGUIUtility.GetObjectPickerObject(); if (newTex != null) { showTexture = Images.GetReadableTextureFromUnreadable(newTex);//always switch it to readable texture first } else { showTexture = null; } currentPickerWindow = -1; } //use whitenoise if (GUI.Button(new Rect(padding * 2 + bottomButtonWidth, WindowRect.height - bottomRowHeight - padding, bottomButtonWidth, bottomRowHeight), "Whitenoise")) { GenerateWhiteNoiseTexture(); } EditorGUI.EndDisabledGroup(); //show original dimension string imageInfo = showTexture != null ? "size:" + showTexture.width + "x" + showTexture.height : ""; EditorGUI.LabelField(new Rect(padding * 3 + bottomButtonWidth * 2, WindowRect.height - bottomRowHeight - padding, bottomButtonWidth * 1.5f, bottomRowHeight), imageInfo); base.DoWindow(windowID); }
//Make a drop area for wardrobe recipes private void DropAreaGUI(Rect dropArea, SerializedProperty thisRecipesProp) { var evt = Event.current; //make the box clickable so that the user can select raceData assets from the asset selection window if (evt.type == EventType.MouseUp) { if (dropArea.Contains(evt.mousePosition)) { wardrobeRecipePickerID = EditorGUIUtility.GetControlID(new GUIContent("wrObjectPicker"), FocusType.Passive); EditorGUIUtility.ShowObjectPicker <UMAWardrobeRecipe>(null, false, "", wardrobeRecipePickerID); Event.current.Use(); //stops the Mismatched LayoutGroup errors return; } } if (evt.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == wardrobeRecipePickerID) { UMAWardrobeRecipe uwr = EditorGUIUtility.GetObjectPickerObject() as UMAWardrobeRecipe; recipesIndexed = false; if (AddRecipe(thisRecipesProp, uwr)) { if (recipesIndexed) { recipesIndexed = false; UMAContextBase.Instance.ValidateDictionaries(); } } if (evt.type != EventType.Layout) { Event.current.Use(); //stops the Mismatched LayoutGroup errors } return; } if (evt.type == EventType.DragUpdated) { if (dropArea.Contains(evt.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } } if (evt.type == EventType.DragPerform) { if (dropArea.Contains(evt.mousePosition)) { DragAndDrop.AcceptDrag(); UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences as UnityEngine.Object[]; ProcessDropeedRecipes(thisRecipesProp, draggedObjects); } } }
/// <summary> /// Draws the menu bar. /// </summary> private void DrawMenuBar() { var menuBar = new Rect(0, 0, position.width, 20); GUILayout.BeginArea(menuBar, EditorStyles.toolbar); GUILayout.BeginHorizontal(); if (LevelGraph != null) { GUILayout.Label($"Selected graph: {LevelGraph.name}"); } else { GUILayout.Label($"No graph selected"); } snapToGrid = GUILayout.Toggle(snapToGrid, "Snap to grid", GUILayout.Width(120)); if (GUILayout.Button(new GUIContent("Select in inspector"), EditorStyles.toolbarButton, GUILayout.Width(150))) { if (LevelGraph != null) { Selection.activeObject = LevelGraph; } } if (GUILayout.Button(new GUIContent("Select level graph"), EditorStyles.toolbarButton, GUILayout.Width(150))) { // Create a window picker control ID currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive) + 100; // Use the ID you just created EditorGUIUtility.ShowObjectPicker <LevelGraph>(null, false, string.Empty, currentPickerWindow); } if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { currentPickerWindow = -1; var levelGraph = EditorGUIUtility.GetObjectPickerObject() as LevelGraph; if (levelGraph != null) { Initialize(levelGraph); } else { ClearWindow(); } } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
private void HandleAddRenderer(Rect position, Rect listArea, SerializedProperty renderersProperty) { if (GUI.Button(position, addRendererButtonContent)) { EditorGUIUtility.ShowObjectPicker <Renderer>(null, true, string.Empty, ObjectPickerControlID); GUIUtility.ExitGUI(); } var current = Event.current; var currentEvent = current.type; if (currentEvent == EventType.DragUpdated || currentEvent == EventType.DragPerform) { if (listArea.Contains(current.mousePosition)) { var dragObjects = DragAndDrop.objectReferences; if (dragObjects != null && dragObjects.Length > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (currentEvent == EventType.DragPerform) { var draggedGameObjects = from go in dragObjects where go as GameObject != null select go as GameObject; var draggedRenderers = from renderer in dragObjects where renderer as Renderer != null select renderer as Renderer; var gameObjectRenderers = GetRenderers(draggedGameObjects, true); AddRenderers(renderersProperty, draggedRenderers, true); AddRenderers(renderersProperty, gameObjectRenderers, true); DragAndDrop.AcceptDrag(); } } current.Use(); } } else if (currentEvent == EventType.ExecuteCommand) { string commandName = current.commandName; if (string.Equals(commandName, "ObjectSelectorClosed") && EditorGUIUtility.GetObjectPickerControlID() == ObjectPickerControlID) { var gameObject = EditorGUIUtility.GetObjectPickerObject() as GameObject; if (gameObject != null) { var gameObjectRenderers = GetRenderers(new GameObject[] { gameObject }, true); AddRenderers(renderersProperty, gameObjectRenderers, true); } current.Use(); GUIUtility.ExitGUI(); } } }
void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused) { rect.y += 2; Rect indexRect = new Rect(rect.x, rect.y, 14, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(indexRect, index.ToString()); Rect objRect = new Rect(rect.x + indexRect.width, rect.y, rect.width - 134, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.ObjectField(objRect, m_RendererDataProp.GetArrayElementAtIndex(index), GUIContent.none); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(target); } Rect defaultButton = new Rect(rect.width - 75, rect.y, 86, EditorGUIUtility.singleLineHeight); var defaultRenderer = m_DefaultRendererProp.intValue; GUI.enabled = index != defaultRenderer; if (GUI.Button(defaultButton, !GUI.enabled ? Styles.rendererDefaultText : Styles.rendererSetDefaultText)) { m_DefaultRendererProp.intValue = index; EditorUtility.SetDirty(target); } GUI.enabled = true; Rect selectRect = new Rect(rect.x + rect.width - 24, rect.y, 24, EditorGUIUtility.singleLineHeight); UniversalRenderPipelineAsset asset = target as UniversalRenderPipelineAsset; if (asset.ValidateRendererData(index)) { if (GUI.Button(selectRect, Styles.rendererSettingsText)) { Selection.SetActiveObjectWithContext(m_RendererDataProp.GetArrayElementAtIndex(index).objectReferenceValue, null); } } else // Missing ScriptableRendererData { if (GUI.Button(selectRect, index == defaultRenderer ? Styles.rendererDefaultMissingText : Styles.rendererMissingText)) { EditorGUIUtility.ShowObjectPicker <ScriptableRendererData>(null, false, null, index); } } // If object selector chose an object, assign it to the correct ScriptableRendererData slot. if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == index) { m_RendererDataProp.GetArrayElementAtIndex(index).objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); } }
public void drawGUI() { if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == instanceID) { Object selection = EditorGUIUtility.GetObjectPickerObject(); if (selection as GameObject != null) { AssetPreview.SetPreviewTextureCacheSize(1000); libraryItemList.Add(new LibraryItem(selection as GameObject, this)); instanceID = -1; } } GUILayout.Label("Library", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add prefab to library")) { instanceID = window.GetInstanceID(); EditorGUIUtility.ShowObjectPicker <GameObject>(null, false, "", instanceID); } EditorGUILayout.EndHorizontal(); GUILayout.Label("Scale: "); iconSize = EditorGUILayout.Slider(iconSize, 48, 128); float windowWidth = EditorGUIUtility.currentViewWidth; int maxInWidth = (int)Mathf.Floor(windowWidth / iconSize); int maxInHeight = (int)Mathf.Ceil(((float)libraryItemList.Count) / maxInWidth); libraryScrollPos = EditorGUILayout.BeginScrollView(libraryScrollPos, false, false, GUILayout.Width(windowWidth), GUILayout.Height(iconSize * maxInHeight), GUILayout.MaxHeight(400)); EditorGUILayout.BeginVertical(); for (int i = 0; i < maxInHeight; i++) { EditorGUILayout.BeginHorizontal(); for (int j = i * maxInWidth; j < i * maxInWidth + maxInWidth; j++) { if (j < libraryItemList.Count) { libraryItemList[j].Draw(new Vector2(iconSize, iconSize)); } else { GUILayout.Button("", GUIStyle.none, GUILayout.Width(iconSize), GUILayout.Height(iconSize)); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }
public bool HandlePickerObjectSelection() { if (!Application.isPlaying && Event.current.type == EventType.ExecuteCommand && _manager.pickerControlID > 0 && Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == _manager.pickerControlID) { _manager.AddPickerObject(EditorGUIUtility.GetObjectPickerObject()); } _manager.pickerControlID = -1; return(true); } return(false); }
private void PrefabPickingActions() { //New specifics (initial prefab) if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == newTreeprefabPickerWindowID) { GameObject pickedPrefab = (GameObject)EditorGUIUtility.GetObjectPickerObject(); newTreeprefabPickerWindowID = -1; //if (pickedPrefab == null) return; VegetationSpawner.TreeType tree = SpawnerBase.TreeType.New(pickedPrefab); spawner.treeTypes.Add(tree); //Auto select new selectedTreeID = spawner.treeTypes.Count - 1; if (spawner.autoRespawnTrees) { spawner.SpawnTree(tree); } EditorUtility.SetDirty(target); } //Specifies prefabs if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == prefabPickerWindowID) { GameObject pickedPrefab = (GameObject)EditorGUIUtility.GetObjectPickerObject(); prefabPickerWindowID = -1; //if (pickedPrefab == null) return; TreeType tree = spawner.treeTypes[selectedTreeID]; TreePrefab treePrefab = new TreePrefab(); treePrefab.probability = 100; treePrefab.prefab = pickedPrefab; tree.prefabs.Add(treePrefab); spawner.RefreshTreePrefabs(); if (spawner.autoRespawnTrees) { spawner.SpawnTree(tree); } EditorUtility.SetDirty(target); } }
public static UnityEngine.Object CustomObjectField(Rect area, UnityEngine.Object item, System.Type allowedType, GUISkin windowSkin, Texture2D materialTex, Action onObjectPicked, Action onDragPerformed) { System.Type type = allowedType; int pickerID = 489136168; string itemName; if (item) { itemName = item.name; } else { itemName = "None"; } GUI.Box(area, "", windowSkin.GetStyle("objectfield")); if (GUI.Button(new Rect(area.x, area.y, area.width - 17f, area.height), " " + itemName, windowSkin.GetStyle("transparent"))) { EditorGUIUtility.PingObject(item); } GUI.DrawTexture(new Rect(area.x, area.y, area.height, area.height), materialTex); UnityEngine.Object[] draggedObjects = DragAndDropObjects(area, onDragPerformed); if (draggedObjects.Length > 0 && draggedObjects[0].GetType() == allowedType) { item = draggedObjects[0]; } if (GUI.Button(new Rect(area.width - area.height, area.y, area.height, area.height), "", windowSkin.GetStyle("objectpicker"))) { EditorGUIUtility.ShowObjectPicker <Material>(item, false, "", pickerID); } if (Event.current.commandName == "ObjectSelectorUpdated") { if (EditorGUIUtility.GetObjectPickerControlID() == 489136168) { item = EditorGUIUtility.GetObjectPickerObject(); onObjectPicked(); } } if (item) { return(item); } else { return(null); } }
public bool HandlePickerObjectSelection() { if (!Application.isPlaying && Event.current.type == EventType.ExecuteCommand && pickerControlID > 0 && Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == pickerControlID) { AddPickerObject(EditorGUIUtility.GetObjectPickerObject(), _pickerOverride); prototypeContents = null; } pickerControlID = -1; return(true); } return(false); }
public override void OnInspectorGUI() { onAwakeLoadingList.DoLayoutList(); GUILayout.Space(10); onStartLoadingList.DoLayoutList(); GUILayout.Space(10); if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == pickerWindowId) { var selectedObject = (GameObject)EditorGUIUtility.GetObjectPickerObject(); pickerWindowId = -1; pickerList.Add(selectedObject); } }
void DrawToolbar(Rect rect) { var commandName = Event.current.commandName; var controlId = GUIUtility.GetControlID(FocusType.Passive); var fieldPos = EditorGUI.PrefixLabel(rect, GUIContent.none); var selection = (ToolBarChoices)GUI.Toolbar(fieldPos, -1, Styles.toolbarButtons); switch (selection) { case ToolBarChoices.LocaleGeneratorWindow: LocaleGeneratorWindow.ShowWindow(); break; case ToolBarChoices.RemoveSelected: { var selectedLocales = ListView.GetSelection(); for (int i = selectedLocales.Count - 1; i >= 0; --i) { var item = ListView.GetRows()[selectedLocales[i]] as SerializedLocaleItem; LocalizationEditorSettings.RemoveLocale(item.SerializedObject.targetObject as Locale, true); } ListView.SetSelection(new int[0]); ListView.Reload(); } break; case ToolBarChoices.AddAsset: EditorGUIUtility.ShowObjectPicker <Locale>(null, false, string.Empty, controlId); break; case ToolBarChoices.AddAllAssets: { var assets = AssetDatabase.FindAssets("t:Locale"); for (int i = 0; i < assets.Length; ++i) { LocalizationEditorSettings.AddLocale(AssetDatabase.LoadAssetAtPath <Locale>(AssetDatabase.GUIDToAssetPath(assets[i])), true); } ListView.Reload(); } break; } if (commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == controlId && EditorGUIUtility.GetObjectPickerObject() != null) { LocalizationEditorSettings.AddLocale(EditorGUIUtility.GetObjectPickerObject() as Locale, true); ListView.Reload(); } }