You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.2 KiB
101 lines
3.2 KiB
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<InstantiateData>().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<InstantiateData>().floorId = int.Parse(objName.Substring(3)); |
|
} |
|
else |
|
{ |
|
go.GetComponent<InstantiateData>().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<InstantiateData>().Equipment = true; |
|
go.GetComponent<InstantiateData>().Power = true; |
|
} |
|
else if (go.name.Contains("Wall") || go.name.Contains("ZhuZi")) |
|
{ |
|
go.GetComponent<InstantiateData>().Equipment = true; |
|
go.GetComponent<InstantiateData>().Power = false; |
|
} |
|
else if (go.name.Contains("XHS")) |
|
{ |
|
go.GetComponent<InstantiateData>().Equipment = false; |
|
go.GetComponent<InstantiateData>().Power = true; |
|
} |
|
else |
|
{ |
|
go.GetComponent<InstantiateData>().Equipment = true; |
|
go.GetComponent<InstantiateData>().Power = false; |
|
} |
|
} |
|
}
|
|
|