public override void OnInspectorGUI() { EditorGUILayout.LabelField("Cue"); EditorGUI.BeginChangeCheck(); var cueTarget = (GameObject)EditorGUILayout.ObjectField("Target", stageGimmickBase.target, typeof(GameObject), true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(stageGimmickBase, "Change Cue Target"); stageGimmickBase.target = cueTarget; cueEventList = cueTarget.GetComponents <CueEventBase>(); } EditorGUI.BeginChangeCheck(); string cueEventID = ""; string param = ""; Object paramObject = null; if (cueEventList != null) { if (cueEventList.Length != 0) { cueEventID = cueEventList [EditorGUILayout.Popup(CueDrawer.getIndexFromID(cueEventList, stageGimmickBase.cueEventID), CueDrawer.getCueEventsStrings(cueEventList))].EventID; EditorGUILayout.LabelField("", ""); CueEventBase cueEvent = cueEventList[CueDrawer.getIndexFromID(cueEventList, stageGimmickBase.cueEventID)]; param = CueDrawer.CueEventParamGUI(GUILayoutUtility.GetLastRect(), stageGimmickBase.parameter, cueEvent.ParamType); if (cueEvent.ParamType.IsSubclassOf(typeof(Object))) { paramObject = (Object)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(param), typeof(Object)); } } } if (EditorGUI.EndChangeCheck()) { //変更前に Undo に登録 Undo.RecordObject(stageGimmickBase, "Change Cue"); stageGimmickBase.cueEventID = cueEventID; stageGimmickBase.parameter = param; stageGimmickBase.paramObject = paramObject; //Debug.Log ("cueEventID"+cueEventID); } EditorGUILayout.Space(); base.OnInspectorGUI(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //base.OnGUI (position, property, label); using (new EditorGUI.PropertyScope(position, label, property)) { //各パーツの領域を指定 var timeLabelRect = new Rect(position) { width = 56, height = 16, x = position.x + 2, y = position.y + 2, }; var timeFieldRect = new Rect(position) { width = 56, height = 16, x = position.x + 2, y = position.y + 19, }; var gameObjectRect = new Rect(position) { width = 156, height = 16, x = position.x + 64, y = position.y + 2 }; var cueEventPopupRect = new Rect(position) { width = 160, height = 16, x = position.x + 224, y = position.y + 2 }; var cueEventParamRect = new Rect(position) { width = 320, height = 16, x = position.x + 64, y = position.y + 19 }; //各プロパティーの SerializedProperty を求める var timeFieldProperty = property.FindPropertyRelative("time"); var gameObjectNameProperty = property.FindPropertyRelative("gameObjectName"); var cueEventIDProperty = property.FindPropertyRelative("cueEventID"); var cueEventParamProperty = property.FindPropertyRelative("parameter"); var cueEventParamObjectProperty = property.FindPropertyRelative("paramObject"); //GUIを配置 EditorGUI.LabelField(timeLabelRect, "Duration"); timeFieldProperty.floatValue = EditorGUI.FloatField(timeFieldRect, timeFieldProperty.floatValue); GameObject go = (GameObject)EditorGUI.ObjectField(gameObjectRect, GameObject.Find(gameObjectNameProperty.stringValue), typeof(GameObject), true); try { if (gameObjectNameProperty.stringValue != GetHierarchyPath(go.transform)) { gameObjectNameProperty.stringValue = GetHierarchyPath(go.transform); } cueEventList = go.GetComponents <CueEventBase>(); } catch { gameObjectNameProperty.stringValue = ""; cueEventList = null; } if (cueEventList != null) { if (cueEventList.Length != 0) { cueEventIDProperty.stringValue = cueEventList [EditorGUI.Popup(cueEventPopupRect, getIndexFromID(cueEventList, cueEventIDProperty.stringValue), getCueEventsStrings(cueEventList))].EventID; CueEventBase cueEvent = cueEventList [getIndexFromID(cueEventList, cueEventIDProperty.stringValue)]; string param = CueEventParamGUI(cueEventParamRect, cueEventParamProperty.stringValue, cueEvent.ParamType); if (cueEvent.ParamType.IsSubclassOf(typeof(Object))) { cueEventParamObjectProperty.objectReferenceValue = (Object)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(param), typeof(Object)); } /*if(cueEventList[getIndexFromID (cueEventList, cueEventIDProperty.stringValue)].ParamType.IsSubclassOf(typeof(Object))){ * if (param != cueEventParamProperty.stringValue) { * cueEventParamObjectProperty.objectReferenceValue = EditorUtility.InstanceIDToObject (int.Parse (param)); * } * }*/ cueEventParamProperty.stringValue = param; } } } }