WXMC/.svn/pristine/38/38f15658489b70719d5533d9d15f40986cbca4dd.svn-base
2024-12-04 16:18:46 +08:00

128 lines
4.9 KiB
Plaintext

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System;
namespace UI.Tables
{
[CustomEditor(typeof(TableLayout))]
public class TableLayoutEditor : Editor
{
private SerializedObject SO_Target;
private TableLayout tableLayout;
private SerializedProperty Padding;
private SerializedProperty RowBackgroundImage;
private SerializedProperty RowBackgroundColor;
private SerializedProperty UseAlternateRowBackgroundColors;
private SerializedProperty RowBackgroundColorAlternate;
private SerializedProperty CellBackgroundImage;
private SerializedProperty CellBackgroundColor;
private SerializedProperty UseAlternateCellBackgroundColors;
private SerializedProperty CellBackgroundColorAlternate;
private SerializedProperty AutomaticallyAddColumns;
private SerializedProperty AutomaticallyRemoveEmptyColumns;
private SerializedProperty ColumnWidths;
private SerializedProperty UseGlobalCellPadding;
private SerializedProperty CellPadding;
private SerializedProperty CellSpacing;
private SerializedProperty AutoCalculateHeight;
public void OnEnable()
{
SO_Target = new SerializedObject(target);
tableLayout = (TableLayout)target;
Padding = SO_Target.FindProperty("m_Padding");
RowBackgroundImage = SO_Target.FindProperty("RowBackgroundImage");
RowBackgroundColor = SO_Target.FindProperty("RowBackgroundColor");
UseAlternateRowBackgroundColors = SO_Target.FindProperty("UseAlternateRowBackgroundColors");
RowBackgroundColorAlternate = SO_Target.FindProperty("RowBackgroundColorAlternate");
CellBackgroundImage = SO_Target.FindProperty("CellBackgroundImage");
CellBackgroundColor = SO_Target.FindProperty("CellBackgroundColor");
UseAlternateCellBackgroundColors = SO_Target.FindProperty("UseAlternateCellBackroundColors");
CellBackgroundColorAlternate = SO_Target.FindProperty("CellBackgroundColorAlternate");
AutomaticallyAddColumns = SO_Target.FindProperty("AutomaticallyAddColumns");
AutomaticallyRemoveEmptyColumns = SO_Target.FindProperty("AutomaticallyRemoveEmptyColumns");
ColumnWidths = SO_Target.FindProperty("ColumnWidths");
UseGlobalCellPadding = SO_Target.FindProperty("UseGlobalCellPadding");
CellPadding = SO_Target.FindProperty("CellPadding");
CellSpacing = SO_Target.FindProperty("CellSpacing");
AutoCalculateHeight = SO_Target.FindProperty("AutoCalculateHeight");
}
public void OnDisable()
{
}
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
EditorGUILayout.PropertyField(Padding, true);
EditorGUILayout.PropertyField(RowBackgroundImage);
EditorGUILayout.PropertyField(RowBackgroundColor);
EditorGUILayout.PropertyField(UseAlternateRowBackgroundColors);
EditorGUILayout.PropertyField(RowBackgroundColorAlternate);
EditorGUILayout.PropertyField(CellBackgroundImage);
EditorGUILayout.PropertyField(CellBackgroundColor);
EditorGUILayout.PropertyField(UseAlternateCellBackgroundColors);
EditorGUILayout.PropertyField(CellBackgroundColorAlternate);
EditorGUILayout.PropertyField(AutomaticallyAddColumns);
EditorGUILayout.PropertyField(AutomaticallyRemoveEmptyColumns);
EditorGUILayout.PropertyField(ColumnWidths, true);
EditorGUILayout.PropertyField(UseGlobalCellPadding);
if (!UseGlobalCellPadding.boolValue) EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(CellPadding, true);
if (!UseGlobalCellPadding.boolValue) EditorGUI.EndDisabledGroup();
EditorGUILayout.PropertyField(CellSpacing);
EditorGUILayout.PropertyField(AutoCalculateHeight);
GUILayout.Space(16);
if (GUILayout.Button(String.Format("Add row with {0} empty cells", tableLayout.ColumnWidths.Count)))
{
tableLayout.AddRow(tableLayout.ColumnWidths.Count);
}
if (GUILayout.Button("Add Empty Row"))
{
tableLayout.AddRow(0);
}
EditorGUI.BeginDisabledGroup(tableLayout.Rows.Count <= 0);
if (GUILayout.Button("Duplicate Last Row"))
{
var lastRow = tableLayout.Rows.Last();
var newRow = GameObject.Instantiate(lastRow);
newRow.name = lastRow.name;
newRow.transform.SetParent(tableLayout.transform);
newRow.transform.SetAsLastSibling();
}
EditorGUI.EndDisabledGroup();
SO_Target.ApplyModifiedProperties();
}
}
}