using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using BF; namespace BFEditor { [CustomEditor(typeof(BFGridLayout))] public class BFGridLayoutInspector : Editor { BFGridLayout layout; private bool isDirty = false; private float tmpFloat = 0.0f; private TextAnchor tmpTextAnchor = TextAnchor.UpperLeft; private bool tmpBool = false; private BFGridLayout.Corner tmpCorner = BFGridLayout.Corner.UpperLeft; private Vector2 hundred = new Vector2(100, 100); private Vector2 tmpVector2 = Vector2.zero; private BFGridLayout.Constraint tmpConstraint = BFGridLayout.Constraint.Flexible; private int tmpInt = 0; void OnEnable() { layout = target as BFGridLayout; } public override void OnInspectorGUI() { EditorGUILayout.BeginVertical(); tmpFloat = EditorGUILayout.FloatField("Left", layout.Left); if (layout.Left != tmpFloat) { isDirty = true; layout.Left = tmpFloat; } tmpFloat = EditorGUILayout.FloatField("Right", layout.Right); if (layout.Right != tmpFloat) { isDirty = true; layout.Right = tmpFloat; } tmpFloat = EditorGUILayout.FloatField("Top", layout.Top); if (layout.Top != tmpFloat) { isDirty = true; layout.Top = tmpFloat; } tmpFloat = EditorGUILayout.FloatField("Bottom", layout.Bottom); if (layout.Bottom != tmpFloat) { isDirty = true; layout.Bottom = tmpFloat; } tmpTextAnchor = (TextAnchor)EditorGUILayout.Popup("Child Alignment", (int)layout.ChildAlignment, new string[] { "UpperLeft", "UpperCenter", "UpperRight", "MiddleLeft", "MiddleCenter", "MiddleRight", "LowerLeft", "LowerCenter", "LowerRight", }); if (layout.ChildAlignment != tmpTextAnchor) { isDirty = true; layout.ChildAlignment = tmpTextAnchor; } tmpCorner = (BFGridLayout.Corner) EditorGUILayout.Popup("StartCorner", (int) layout.StartCorner, new string[] { "UpperLeft", "UpperRight", "LowerLeft", "LowerRight", }); if (tmpCorner != layout.StartCorner) { isDirty = true; layout.StartCorner = tmpCorner; } tmpVector2 = EditorGUILayout.Vector2Field("CellSize", layout.CellSize); if (layout.CellSize != tmpVector2) { if (layout.CellSize.x <= 0 || layout.CellSize.y <= 0) { layout.CellSize = hundred; isDirty = true; layout.CellSize = tmpVector2; } } tmpVector2 = EditorGUILayout.Vector2Field("Spaceing", layout.Spaceing); if (layout.Spaceing != tmpVector2) { isDirty = true; layout.Spaceing = tmpVector2; } tmpConstraint = (BFGridLayout.Constraint)EditorGUILayout.Popup("ConstraintType", (int) layout.ConstraintType, new string[] { "Flexible", "FixedColumnCount", "FixedRowCount" }); if (tmpConstraint != layout.ConstraintType) { isDirty = true; layout.ConstraintType = tmpConstraint; } if (layout.ConstraintType == BFGridLayout.Constraint.Flexible) { } else if(layout.ConstraintType == BFGridLayout.Constraint.FixedColumnCount) { tmpInt = EditorGUILayout.IntField("ConstraintCount", layout.ConstraintCount); if (tmpInt != layout.ConstraintCount) { isDirty = true; layout.ConstraintCount = tmpInt; } } else if(layout.ConstraintType == BFGridLayout.Constraint.FixedRowCount) { tmpInt = EditorGUILayout.IntField("ConstraintCount", layout.ConstraintCount); if (tmpInt != layout.ConstraintCount) { isDirty = true; layout.ConstraintCount = tmpInt; } } if (GUILayout.Button("孩子变化的时候手动刷新")) { layout.RefreshLayout(); } if (isDirty) { EditorUtility.SetDirty(target); AssetDatabase.SaveAssets(); } EditorGUILayout.EndVertical(); } } }