Script(C#):
Editor Script Script(C#):
結果圖:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Biochemical_Multitude : ObjectClass { // 物件模式 public enum SelectObj { roteObj, moveObj, } public SelectObj objsType; // 物件行為方向 public enum Direction { forward, up, down, left, right, } public Direction selectDrection; public List----------------------------roteObjs = new List (); public float roteSpeed; public List moveObjs = new List (); public float moveSpeed; void Update() { switch (objsType) { case SelectObj.moveObj: foreach (Transform tra in moveObjs) Move(tra, driectionFunction(selectDrection), moveSpeed); break; case SelectObj.roteObj: foreach (Transform tra in roteObjs) Rote(tra, driectionFunction(selectDrection), roteSpeed); break; } } /// /// 方向 /// /// ///Vector3 driectionFunction(Direction direction) { Vector3 vector3 = Vector3.zero; switch (direction) { case Direction.forward: vector3 = Vector3.forward; break; case Direction.up: vector3 = Vector3.up; break; case Direction.down: vector3 = Vector3.down; break; case Direction.left: vector3 = Vector3.left; break; case Direction.right: vector3 = Vector3.right; break; } return vector3; } }
Editor Script Script(C#):
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; [CustomEditor(typeof(Biochemical_Multitude))] public class Biochemical_MultitudeEditor : Editor { public override void OnInspectorGUI() { serializedObject.Update(); var script = target as Biochemical_Multitude; SerializedProperty tps = serializedObject.FindProperty("roteObjs"); // 路徑 EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(tps, new GUIContent("roteObjs"), true); if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties(); } }-------------
結果圖: