internal static void UpdateEditorTools(BrushToolsAttribute brushToolsAttribute) { if (IsCachedEditorToolsInvalid()) { InstantiateEditorTools(); } EditorTool[] editorTools; if (brushToolsAttribute?.toolList == null || brushToolsAttribute.toolList.Count == 0) { editorTools = s_DefaultTilemapEditorTools; } else { editorTools = new EditorTool[brushToolsAttribute.toolList.Count]; for (int i = 0; i < brushToolsAttribute.toolList.Count; ++i) { var toolType = brushToolsAttribute.toolList[i]; if (!s_TilemapEditorToolsMap.TryGetValue(toolType, out EditorTool editorTool)) { editorTool = (EditorTool)ScriptableObject.CreateInstance(toolType); s_TilemapEditorToolsMap.Add(toolType, editorTool); } editorTools[i] = editorTool; } } GridPaintingState.SetBrushTools(editorTools); }
internal static void FlushCache() { s_RefreshCache = true; if (instance.m_Brushes != null) { instance.m_Brushes.Clear(); GridPaintingState.FlushCache(); } }
private static void InstantiateEditorTools() { s_DefaultTilemapEditorTools = TilemapEditorToolPreferences.CreateDefaultTilePaletteEditorTools(); s_TilemapEditorToolsMap = new Dictionary <Type, EditorTool>(s_DefaultTilemapEditorTools.Length); foreach (var editorTool in s_DefaultTilemapEditorTools) { s_TilemapEditorToolsMap.Add(editorTool.GetType(), editorTool); } GridPaintingState.UpdateBrushToolbar(); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); if (GridPaintingState.activeBrushEditor && GridSelection.active) { GridPaintingState.activeBrushEditor.OnSelectionInspectorGUI(); } if (EditorGUI.EndChangeCheck()) { if (GridPaintingState.IsPartOfActivePalette(GridSelection.target)) { GridPaintingState.UnlockGridPaintPaletteClipboardForEditing(); GridPaintingState.RepaintGridPaintPaletteWindow(); } } }
/// <summary> /// Draws the Inspector GUI for a GridPalette /// </summary> public override void OnInspectorGUI() { m_SerializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_CellSizing, Styles.cellSizingLabel); EditorGUILayout.PropertyField(m_TransparencySortMode, Styles.transparencySortModeLabel); using (new EditorGUI.DisabledScope(m_TransparencySortMode.enumValueIndex != m_CustomAxisIndex)) { EditorGUILayout.PropertyField(m_TransparencySortAxis, Styles.transparencySortAxisLabel); } if (EditorGUI.EndChangeCheck()) { m_SerializedObject.ApplyModifiedProperties(); if (AssetDatabase.GetAssetPath(GridPaintingState.palette) == AssetDatabase.GetAssetPath(target)) { GridPaintingState.UpdateActiveGridPalette(); GridPaintingState.RepaintGridPaintPaletteWindow(); } } }
internal static void PreferencesGUI() { using (new SettingsWindow.GUIScope()) { if (s_SortingNames == null) { var sortingTypeFullName = EditorPrefs.GetString(targetSortingModeEditorPref, defaultSortingMode); var sortingMethodNames = sortingTypeFullName.Split('.'); s_SortingNames = new string[1 + GridPaintSortingAttribute.sortingMethods.Count + GridPaintSortingAttribute.sortingTypes.Count]; int count = 0; s_SortingNames[count++] = defaultSortingMode; foreach (var sortingMethod in GridPaintSortingAttribute.sortingMethods) { if (CompareMethodName(sortingMethodNames, sortingMethod)) { s_SortingSelectionIndex = count; } s_SortingNames[count++] = sortingMethod.Name; } foreach (var sortingType in GridPaintSortingAttribute.sortingTypes) { if (CompareTypeName(sortingTypeFullName, sortingType)) { s_SortingSelectionIndex = count; } s_SortingNames[count++] = sortingType.Name; } } if (s_CreateTileNames == null) { var createTileFullName = EditorPrefs.GetString(createTileFromPaletteEditorPref, defaultSortingMode); var createTileMethodNames = createTileFullName.Split('.'); int count = 0; s_CreateTileNames = new string[CreateTileFromPaletteAttribute.createTileFromPaletteMethods.Count]; foreach (var createTileMethod in CreateTileFromPaletteAttribute.createTileFromPaletteMethods) { if (CompareMethodName(createTileMethodNames, createTileMethod)) { s_CreateTileIndex = count; } s_CreateTileNames[count++] = createTileMethod.Name; } } EditorGUI.BeginChangeCheck(); var sortingSelection = EditorGUILayout.Popup(targetSortingModeLabel, s_SortingSelectionIndex, s_SortingNames); if (EditorGUI.EndChangeCheck()) { s_SortingSelectionIndex = sortingSelection; var sortingTypeFullName = defaultSortingMode; if (s_SortingSelectionIndex > 0 && s_SortingSelectionIndex <= GridPaintSortingAttribute.sortingMethods.Count) { var sortingMethod = GridPaintSortingAttribute.sortingMethods[s_SortingSelectionIndex - 1]; sortingTypeFullName = String.Format("{0}.{1}", sortingMethod.ReflectedType.Name, sortingMethod.Name); } else { var idx = s_SortingSelectionIndex - GridPaintSortingAttribute.sortingMethods.Count - 1; if (idx >= 0 && idx < GridPaintSortingAttribute.sortingTypes.Count) { var sortingType = GridPaintSortingAttribute.sortingTypes[idx]; sortingTypeFullName = sortingType.FullName; } } EditorPrefs.SetString(targetSortingModeEditorPref, sortingTypeFullName); GridPaintingState.FlushCache(); } EditorGUI.BeginChangeCheck(); var editModeSelection = EditorGUILayout.Toggle(targetRestoreEditModeSelectionLabel, restoreEditModeSelection); if (EditorGUI.EndChangeCheck()) { restoreEditModeSelection = editModeSelection; } EditorGUI.BeginChangeCheck(); var createTileSelection = EditorGUILayout.Popup(createTileFromPaletteLabel, s_CreateTileIndex, s_CreateTileNames); if (EditorGUI.EndChangeCheck()) { var createTileFullName = defaultSortingMode; s_CreateTileIndex = createTileSelection; if (s_CreateTileIndex < CreateTileFromPaletteAttribute.createTileFromPaletteMethods.Count) { var createTileMethod = CreateTileFromPaletteAttribute.createTileFromPaletteMethods[s_CreateTileIndex]; createTileFullName = String.Format("{0}.{1}", createTileMethod.ReflectedType.Name, createTileMethod.Name); } EditorPrefs.SetString(createTileFromPaletteEditorPref, createTileFullName); } } }
private void DoPreferencesGUI() { if (m_DefaultTypes == null) { LoadDefaultEditorToolTypes(); } EditorGUILayout.LabelField(TilemapEditorToolProperties.defaultToolsLabel); EditorGUILayout.BeginHorizontal(); m_DefaultTypes.DoLayoutList(); EditorGUILayout.BeginVertical(); if (GUILayout.Button(TilemapEditorToolProperties.addLabel)) { var otherIndex = m_OtherTypes.index; if (0 <= otherIndex && otherIndex < m_OtherTilemapEditorToolTypes.Count) { var otherType = m_OtherTilemapEditorToolTypes[otherIndex]; var defaultIndex = m_DefaultTypes.index; m_DefaultTilemapEditorToolTypes.Insert(defaultIndex + 1, otherType); m_OtherTilemapEditorToolTypes.RemoveAt(otherIndex); m_DefaultTypes.index = defaultIndex + 1; m_OtherTypes.index = -1; m_Changed = true; } } if (GUILayout.Button(TilemapEditorToolProperties.removeLabel)) { var defaultIndex = m_DefaultTypes.index; if (0 <= defaultIndex && defaultIndex < m_DefaultTilemapEditorToolTypes.Count) { var defaultType = m_DefaultTilemapEditorToolTypes[defaultIndex]; if (defaultType.tilemapEditorToolType != null) { var otherIndex = m_OtherTypes.index; m_OtherTilemapEditorToolTypes.Insert(otherIndex + 1, defaultType); m_OtherTypes.index = otherIndex + 1; } m_DefaultTilemapEditorToolTypes.RemoveAt(defaultIndex); m_DefaultTypes.index = -1; m_Changed = true; } } EditorGUILayout.EndVertical(); m_OtherTypes.DoLayoutList(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); using (new EditorGUI.DisabledScope(!m_Changed)) { if (GUILayout.Button(TilemapEditorToolProperties.saveLabel)) { SaveTilemapEditorToolPreferences(m_DefaultTilemapEditorToolTypes); m_Changed = false; GridPaintingState.RepaintGridPaintPaletteWindow(); } if (GUILayout.Button(TilemapEditorToolProperties.revertLabel)) { LoadDefaultEditorToolTypes(); m_DefaultTypes.index = -1; m_OtherTypes.index = -1; m_Changed = false; } } if (GUILayout.Button(TilemapEditorToolProperties.resetLabel)) { ResetTilemapEditorToolPreferences(); m_DefaultTypes.index = -1; m_OtherTypes.index = -1; m_Changed = false; GridPaintingState.RepaintGridPaintPaletteWindow(); } EditorGUILayout.EndHorizontal(); }