private void HandleSpritePreviewCycle(Rect rect) { if (!isSelectedIndexValid) { return; } Debug.Assert(m_AngleRangeSpriteList != null); var spriteIndex = GetPreviewSpriteIndex(selectedIndex); var sprites = angleRanges[selectedIndex].sprites; var ev = Event.current; if (ev.type == EventType.MouseDown && ev.button == 0 && HandleUtility.nearestControl == 0 && ContainsPosition(rect, ev.mousePosition, m_PreviewAngle) && spriteIndex != kInvalidMinimum && sprites.Count > 0) { spriteIndex = Mathf.RoundToInt(Mathf.Repeat(spriteIndex + 1f, sprites.Count)); SetPreviewSpriteIndex(selectedIndex, spriteIndex); m_AngleRangeSpriteList.GrabKeyboardFocus(); m_AngleRangeSpriteList.index = spriteIndex; ev.Use(); } }
public static void EditElement(this ReorderableList list, int index, string guiElementControlName) { list.GrabKeyboardFocus(); EditorGUI.FocusTextInControl(guiElementControlName); list.SelectElement(index); }
public static void AddElement(this ReorderableList list, bool grabKeyboardFocus) { int index = list.count; list.serializedProperty.InsertArrayElementAtIndex(index); if (grabKeyboardFocus) { list.GrabKeyboardFocus(); } }
private void RemoveFrameListItem(ReorderableList list) { Undo.RecordObject(animation, "Remove Frame"); int i = list.index; animation.animFrames.RemoveAt(i); frameList.list.RemoveAt(i); frameListSelectedIndex = frameList.index; if (i >= animation.FramesCount) { frameList.index -= 1; frameListSelectedIndex -= 1; currentFrame = frameListSelectedIndex; frameList.GrabKeyboardFocus(); } EditorUtility.SetDirty(animation); Repaint(); }
private void RemoveEventListItem(ReorderableList list) { Undo.RecordObject(animation, "Remove Event"); int i = list.index; animation.Events.RemoveAt(i); eventList.list.RemoveAt(i); eventListSelectedIndex = eventList.index; if (i >= animation.Events.Count) { eventList.index -= 1; eventListSelectedIndex -= 1; currentEvent = eventListSelectedIndex; eventList.GrabKeyboardFocus(); } EditorUtility.SetDirty(animation); Repaint(); }
private void RemoveFrameListItem(ReorderableList list) { Undo.RecordObject(selectedAnimation, "Remove Frame"); int i = list.index; selectedAnimation.Frames.RemoveAt(i); selectedAnimation.FramesDuration.RemoveAt(i); frameList.list.RemoveAt(i); frameListSelectedIndex = frameList.index; if (i >= selectedAnimation.FramesCount) { frameList.index -= 1; frameListSelectedIndex -= 1; spritePreview.CurrentFrame = frameListSelectedIndex; frameList.GrabKeyboardFocus(); } Repaint(); SaveFile(true); }
public override void OnEnable() { base.OnEnable(); m_brush = (RandomBrush)target; if (m_brush.Tileset != null) { m_brush.Tileset.OnTileSelected += OnTileSelected; m_brush.Tileset.OnBrushSelected += OnBrushSelected; } m_randTileList = new ReorderableList(serializedObject, serializedObject.FindProperty("RandomTileList"), true, true, true, true); m_randTileList.drawHeaderCallback += (Rect rect) => { EditorGUI.LabelField(rect, "Random Tiles", EditorStyles.boldLabel); }; m_randTileList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { Rect rTile = rect; rTile.width = rTile.height = m_brush.Tileset.VisualTileSize.y; uint tileData = m_brush.RandomTileList[index].tileData; int tileId = (int)(tileData & Tileset.k_TileDataMask_TileId); int brushId = Tileset.GetBrushIdFromTileData(tileData); TilesetBrush brush = m_brush.Tileset.FindBrush(brushId); if (brush) { GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset, brush.GetAnimUV()); } else if (tileId != Tileset.k_TileId_Empty) { GUI.Box(new Rect(rTile.position - Vector2.one, rTile.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rTile, tileData, m_brush.Tileset); } Rect rTileId = rect; rTileId.x += rTile.width + 10; rTileId.width -= rTile.width + 20; rTileId.height = rect.height / 2; if (brush) { GUI.Label(rTileId, "Brush Id(" + brushId + ")"); } else { GUI.Label(rTileId, "Id(" + tileId + ")"); } SerializedProperty randomTileDataProperty = m_randTileList.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty probabilityFactorProperty = randomTileDataProperty.FindPropertyRelative("probabilityFactor"); Rect rProbabilityField = new Rect(rect.x + rTile.width + 10f, rect.y + EditorGUIUtility.singleLineHeight * 2.5f, rect.width - rTile.width - 10f, EditorGUIUtility.singleLineHeight); Rect rProbabilityLabel = new Rect(rProbabilityField.x, rProbabilityField.y - EditorGUIUtility.singleLineHeight, rProbabilityField.width, rProbabilityField.height); float sumProbabilityFactor = m_brush.GetSumProbabilityFactor(); float probability = sumProbabilityFactor >= 0 ? probabilityFactorProperty.floatValue * 100f / sumProbabilityFactor : 100f; EditorGUI.PrefixLabel(rProbabilityLabel, new GUIContent("Probability (" + Mathf.RoundToInt(probability) + "%)")); EditorGUI.PropertyField(rProbabilityField, probabilityFactorProperty, GUIContent.none); if (probabilityFactorProperty.floatValue == 0f) { serializedObject.ApplyModifiedProperties(); sumProbabilityFactor = m_brush.GetSumProbabilityFactor(); if (sumProbabilityFactor <= 0f) { probabilityFactorProperty.floatValue = 0.01f; } } if (GUI.Button(new Rect(rect.x + rect.width - 50f, rect.y, 50f, EditorGUIUtility.singleLineHeight), "Clear")) { m_brush.RandomTileList[index].tileData = Tileset.k_TileData_Empty; } }; m_randTileList.onSelectCallback += (ReorderableList list) => { TileSelectionWindow.Show(m_brush.Tileset); TileSelectionWindow.Instance.Ping(); }; m_randTileList.onAddCallback += (ReorderableList list) => { if (list.index >= 0) { list.serializedProperty.InsertArrayElementAtIndex(list.index); } else { list.serializedProperty.InsertArrayElementAtIndex(0); } list.index = Mathf.Max(0, list.index + 1); list.serializedProperty.serializedObject.ApplyModifiedProperties(); m_brush.RandomTileList[list.index].probabilityFactor = 1f; if (m_brush.Tileset.SelectedTile != null) { m_randTileList.GrabKeyboardFocus(); OnTileSelected(m_brush.Tileset, -1, m_brush.Tileset.SelectedTileId); } }; }
public void GrabKeyboardFocus() { reorderableList.GrabKeyboardFocus(); }
private void DoReorderableList(IList list, Type listType) { if (mReorderableList == null) { mReorderableList = new ReorderableList(list, listType, true, false, false, false); mReorderableList.headerHeight = 0; mReorderableList.showDefaultBackground = false; mReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var elem = (AbstractXcodeConfig)list[index]; GUI.Label(rect, elem.SaveName); rect.x = rect.xMax - 15; elem.Enabled = GUI.Toggle(rect, elem.Enabled, string.Empty); }; } QuickEditorGUIStaticAPI.Space(); using (new QuickEditorGUILayout.HorizontalBlock()) { QuickEditorGUIStaticAPI.Space(); if (GUILayout.Button(EditorGUIUtility.FindTexture("d_Toolbar Plus"), GUIStyle.none, GUILayout.Width(16))) { list.Add(Activator.CreateInstance(listType)); mReorderableList.index = list.Count - 1; mReorderableList.GrabKeyboardFocus(); mSettingsScrollPosition.y = float.MaxValue; } QuickEditorGUIStaticAPI.Space(); if (GUILayout.Button(EditorGUIUtility.FindTexture("d_Toolbar Minus"), GUIStyle.none, GUILayout.Width(16))) { if (mReorderableList.index >= 0 && mReorderableList.index <= list.Count - 1) { Undo.RecordObject(XcodeProjectSetting.Current, "Removed Import Preset"); list.RemoveAt(mReorderableList.index); mReorderableList.index = Mathf.Max(0, mReorderableList.index - 1); mReorderableList.GrabKeyboardFocus(); } } QuickEditorGUIStaticAPI.FlexibleSpace(); QuickEditorGUIStaticAPI.Button("Disable.All", EditorStyles.miniButtonLeft, () => { for (int i = 0; i < list.Count; i++) { ((AbstractXcodeConfig)list[i]).Enabled = false; } }); QuickEditorGUIStaticAPI.Button("Enable.All", EditorStyles.miniButtonRight, () => { for (int i = 0; i < list.Count; i++) { ((AbstractXcodeConfig)list[i]).Enabled = true; } }); } QuickEditorGUIStaticAPI.Space(); QuickEditorGUIStaticAPI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11); using (var scroll = new EditorGUILayout.ScrollViewScope(mReorderableScrollPosition)) { mReorderableScrollPosition = scroll.scrollPosition; mReorderableList.DoLayoutList(); } }
private void DrawPresetsList(List <ImportConfig> importConfigList) { if (presetOrderableList == null) { // Init preset Reorderable list. presetOrderableList = new ReorderableList(importConfigList, typeof(ImportConfig), true, false, false, false); presetOrderableList.headerHeight = 0; presetOrderableList.elementHeight = 26; presetOrderableList.showDefaultBackground = false; presetOrderableList.drawNoneElementCallback = (Rect rect) => { GUI.Label(rect, "No Presets"); }; presetOrderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { Rect topRect = new Rect(rect); var elem = importConfigList[index]; GUI.Label(topRect, elem.saveName); topRect.x = topRect.xMax - 15; elem.isEnabled = GUI.Toggle(topRect, elem.isEnabled, string.Empty); if (importConfigList[index].targetPreset != null) { Rect bottomRect = new Rect(rect) { y = rect.y + 10, height = 16 }; GUIStyle style = new GUIStyle(ImportPresetsResources.MiniLabelStyle); if (!isActive) { style.normal.textColor = Color.gray; } GUI.Label(bottomRect, importConfigList[index].targetPreset.GetTargetTypeName().Replace("Importer", string.Empty), style); } }; } using (new GUILayout.HorizontalScope()) { GUILayout.Space(4); if (GUILayout.Button(ImportPresetsResources.MinusIcon, GUIStyle.none, GUILayout.Width(16))) { if (presetOrderableList.index >= 0 && (importConfigList.Count - 1) >= presetOrderableList.index) { Undo.RecordObject(ImportPresetsResources.DataAsset, "Removed Import Preset"); importConfigList.RemoveAt(presetOrderableList.index); presetOrderableList.index = Mathf.Max(0, presetOrderableList.index - 1); presetOrderableList.GrabKeyboardFocus(); } } GUILayout.Space(4); if (GUILayout.Button(ImportPresetsResources.PlusIcon, GUIStyle.none, GUILayout.Width(16))) { Undo.RecordObject(ImportPresetsResources.DataAsset, "Added Import Preset"); importConfigList.Add(new ImportConfig()); presetOrderableList.index = importConfigList.Count - 1; orderableListScroll.y = float.MaxValue; presetOrderableList.GrabKeyboardFocus(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("All On", EditorStyles.miniButtonLeft)) { for (int i = 0; i < importConfigList.Count; i++) { ((ImportConfig)importConfigList[i]).isEnabled = false; } } if (GUILayout.Button("Flip", EditorStyles.miniButtonMid)) { for (int i = 0; i < importConfigList.Count; i++) { var item = ((ImportConfig)importConfigList[i]); item.isEnabled = !item.isEnabled; } } if (GUILayout.Button("All Off", EditorStyles.miniButtonRight)) { for (int i = 0; i < importConfigList.Count; i++) { ((ImportConfig)importConfigList[i]).isEnabled = true; } } } GUILayout.Space(4); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), ImportPresetsResources.HeaderSeparatorColor); using (var scroll = new EditorGUILayout.ScrollViewScope(orderableListScroll)) { orderableListScroll = scroll.scrollPosition; presetOrderableList.DoLayoutList(); } }
public void OnGUI(ObjectPainterWindow window) { //EditorGUIUtility.wideMode = true; EditorGUIUtility.labelWidth = 60; using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("General - " + brushName, EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), ObjectPainterResources.HeaderSeparatorColor); GUILayout.Space(4); brushName = EditorGUILayout.TextField("Name ", brushName); brushRadius = Mathf.Abs(EditorGUILayout.FloatField(radiusContent, brushRadius)); brushRate = Mathf.Clamp(EditorGUILayout.FloatField(rateContent, brushRate), 1, 10000); } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("Colliders", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), ObjectPainterResources.HeaderSeparatorColor); GUILayout.Space(4); layerMask = LayerMaskField(layersContent, layerMask); colliderStrict = EditorGUILayout.ToggleLeft(colliderStrictContent, colliderStrict); } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField(cullingContent, EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), ObjectPainterResources.HeaderSeparatorColor); GUILayout.Space(4); cullEnabled = EditorGUILayout.ToggleLeft(cullContent, cullEnabled); if (cullEnabled) { EditorGUIUtility.labelWidth = 80; cullAngle = EditorGUILayout.Slider(cullAngleContent, cullAngle, 0f, 90f); cullInvert = EditorGUILayout.ToggleLeft(cullInvertContent, cullInvert); cullRef = EditorGUILayout.Vector3Field(cullRefContent, cullRef); } } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { EditorGUILayout.LabelField("Prefabs", EditorStyles.boldLabel); EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), ObjectPainterResources.HeaderSeparatorColor); GUILayout.Space(4); // Create reorderable prefab list if (prefabsList == null) { prefabsList = new ReorderableList(prefabs, typeof(BrushPrefabSettings), false, true, true, true); prefabsList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Prefab list"); rect.x = rect.xMax - 64; rect.width = 16; if (GUI.Button(rect, "▼", EditorStyles.label)) { for (int i = 0; i < prefabs.Count; i++) { prefabs[i].isExpanded = true; } } rect.x += 16; if (GUI.Button(rect, "▲", EditorStyles.label)) { for (int i = 0; i < prefabs.Count; i++) { prefabs[i].isExpanded = false; } } rect.x += 16; if (GUI.Button(rect, EditorGUIUtility.FindTexture("d_Toolbar Plus"), GUIStyle.none)) { prefabs.Add(new BrushPrefabSettings()); prefabsList.index = prefabs.Count - 1; prefabsList.GrabKeyboardFocus(); scrollPos.y = float.MaxValue; } rect.x += 16; using (new EditorGUI.DisabledGroupScope(prefabsList.index < 0)) { if (GUI.Button(rect, EditorGUIUtility.FindTexture("d_Toolbar Minus"), GUIStyle.none)) { if (prefabsList.index >= 0 && prefabsList.index <= prefabs.Count - 1) { Undo.RecordObject(window.SavedBrushes, "Removed Brush Preset"); prefabs.RemoveAt(prefabsList.index); prefabsList.index = prefabsList.index - 1; prefabsList.GrabKeyboardFocus(); } } } }; prefabsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { prefabs[index].OnGUI(index, rect); }; prefabsList.elementHeightCallback = (int index) => { return(prefabs[index].GetHeight()); }; prefabsList.elementHeight = 100; } // Per-object settings. using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPos)) { scrollPos = scroll.scrollPosition; prefabsList.DoLayoutList(); } } }