暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GridPaletteEditor.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Tilemaps
  4. {
  5. /// <summary>
  6. /// Editor for GridPalette
  7. /// </summary>
  8. [CustomEditor(typeof(GridPalette))]
  9. public class GridPaletteEditor : Editor
  10. {
  11. private static class Styles
  12. {
  13. public static readonly GUIContent cellSizingLabel = EditorGUIUtility.TrTextContent("Cell Sizing", "Determines the sizing of cells based on Tiles in the Palette");
  14. public static readonly GUIContent transparencySortModeLabel = EditorGUIUtility.TrTextContent("Sort Mode", "Determines the transparency sorting mode of renderers in the Palette");
  15. public static readonly GUIContent transparencySortAxisLabel = EditorGUIUtility.TrTextContent("Sort Axis", "Determines the sorting axis if the transparency sort mode is set to Custom Axis Sort");
  16. }
  17. private SerializedProperty m_CellSizing;
  18. private SerializedProperty m_TransparencySortMode;
  19. private SerializedProperty m_TransparencySortAxis;
  20. private int m_CustomAxisIndex;
  21. private void OnEnable()
  22. {
  23. m_CellSizing = serializedObject.FindProperty("cellSizing");
  24. m_TransparencySortMode = serializedObject.FindProperty("m_TransparencySortMode");
  25. m_TransparencySortAxis = serializedObject.FindProperty("m_TransparencySortAxis");
  26. m_CustomAxisIndex = Array.IndexOf(Enum.GetValues(typeof(TransparencySortMode)), TransparencySortMode.CustomAxis);
  27. }
  28. /// <summary>
  29. /// Draws the Inspector GUI for a GridPalette
  30. /// </summary>
  31. public override void OnInspectorGUI()
  32. {
  33. m_SerializedObject.Update();
  34. EditorGUI.BeginChangeCheck();
  35. EditorGUILayout.PropertyField(m_CellSizing, Styles.cellSizingLabel);
  36. EditorGUILayout.PropertyField(m_TransparencySortMode, Styles.transparencySortModeLabel);
  37. using (new EditorGUI.DisabledScope(m_TransparencySortMode.enumValueIndex != m_CustomAxisIndex))
  38. {
  39. EditorGUILayout.PropertyField(m_TransparencySortAxis, Styles.transparencySortAxisLabel);
  40. }
  41. if (EditorGUI.EndChangeCheck())
  42. {
  43. m_SerializedObject.ApplyModifiedProperties();
  44. if (AssetDatabase.GetAssetPath(GridPaintingState.palette) == AssetDatabase.GetAssetPath(target))
  45. {
  46. GridPaintingState.UpdateActiveGridPalette();
  47. GridPaintingState.RepaintGridPaintPaletteWindow();
  48. }
  49. }
  50. }
  51. }
  52. }