using UnityEditor; using UnityEngine; [CustomEditor(typeof(InstantiateData))] [CanEditMultipleObjects] public class InstantiateDataEditor : Editor { SerializedProperty FloorIdProp; SerializedProperty EquipmentProp; SerializedProperty PowerProp; private void OnEnable() { FloorIdProp = serializedObject.FindProperty("floorId"); EquipmentProp = serializedObject.FindProperty("Equipment"); PowerProp = serializedObject.FindProperty("Power"); } public override void OnInspectorGUI() { InstantiateData Target = (InstantiateData)target; GUILayout.BeginHorizontal("Box"); serializedObject.Update(); EditorGUILayout.PropertyField(FloorIdProp, new GUIContent("FloorID")); if (GUILayout.Button("+")) { FloorIdProp.intValue++; } if (GUILayout.Button("-")) { FloorIdProp.intValue--; } if (GUILayout.Button("Get")) { foreach(GameObject go in Selection.gameObjects) { GetAttrube(go); GetFloorId(go); } } GUILayout.EndHorizontal(); GUILayout.BeginVertical("Box"); EditorGUILayout.PropertyField(EquipmentProp, new GUIContent("Equipment")); EditorGUILayout.PropertyField(PowerProp, new GUIContent("Power")); GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(target); } } private void GetFloorId(GameObject go) { if (go.transform.parent.name.Contains("wai") || go.transform.parent.name.Contains("nei")) { var objName = go.transform.parent.name; go.GetComponent().floorId = int.Parse(objName.Substring(3)); } else if (go.transform.parent.parent.name.Contains("wai") || go.transform.parent.parent.name.Contains("nei")) { var objName = go.transform.parent.parent.name; go.GetComponent().floorId = int.Parse(objName.Substring(3)); } else { go.GetComponent().floorId = 0; } } private void GetAttrube(GameObject go) { if (go.name.Contains("Floor") || go.name.Contains("Roof") || go.name.Contains("Road") || go.name.Contains("Ground") || this.name.Contains("Grass") || this.name.Contains("PuZhuang")) { go.GetComponent().Equipment = true; go.GetComponent().Power = true; } else if (go.name.Contains("Wall") || go.name.Contains("ZhuZi")) { go.GetComponent().Equipment = true; go.GetComponent().Power = false; } else if (go.name.Contains("XHS")) { go.GetComponent().Equipment = false; go.GetComponent().Power = true; } else { go.GetComponent().Equipment = true; go.GetComponent().Power = false; } } }