public override void OnInspectorGUI() { if (NotFoundWarning == null) { Texture warningIcon = EditorUtils.LoadImage("NotFound.png"); NotFoundWarning = new GUIContent("Parameter Not Found", warningIcon); } EditorGUILayout.PropertyField(trigger, new GUIContent("Trigger")); if (trigger.enumValueIndex >= (int)EmitterGameEvent.TriggerEnter && trigger.enumValueIndex <= (int)EmitterGameEvent.TriggerExit2D) { tag.stringValue = EditorGUILayout.TagField("Collision Tag", tag.stringValue); } EditorGUILayout.PropertyField(param, new GUIContent("Parameter")); if (param.stringValue != currentPath) { currentPath = param.stringValue; if (string.IsNullOrEmpty(param.stringValue)) { editorParamRef = null; } else { editorParamRef = EventManager.ParamFromPath(param.stringValue); value.floatValue = Mathf.Clamp(value.floatValue, editorParamRef.Min, editorParamRef.Max); } } if (editorParamRef != null) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel("Override Value"); value.floatValue = EditorUtils.DrawParameterValueLayout(value.floatValue, editorParamRef); } } else { Rect rect = EditorGUILayout.GetControlRect(); rect.xMin += EditorGUIUtility.labelWidth; GUI.Label(rect, NotFoundWarning); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { var newTargetEmitter = EditorGUILayout.ObjectField("Target", targetEmitter, typeof(StudioEventEmitter), true) as StudioEventEmitter; if (newTargetEmitter != targetEmitter) { emitters.ClearArray(); targetEmitter = newTargetEmitter; if (targetEmitter == null) { serializedObject.ApplyModifiedProperties(); return; } List <StudioEventEmitter> newEmitters = new List <StudioEventEmitter>(); targetEmitter.GetComponents(newEmitters); expanded = new bool[newEmitters.Count]; foreach (var emitter in newEmitters) { emitters.InsertArrayElementAtIndex(0); emitters.GetArrayElementAtIndex(0).FindPropertyRelative("Target").objectReferenceValue = emitter; } } if (targetEmitter == null) { return; } EditorGUILayout.PropertyField(trigger, new GUIContent("Trigger")); if (trigger.enumValueIndex >= (int)EmitterGameEvent.TriggerEnter && trigger.enumValueIndex <= (int)EmitterGameEvent.TriggerExit2D) { tag.stringValue = EditorGUILayout.TagField("Collision Tag", tag.stringValue); } var localEmitters = new List <StudioEventEmitter>(); targetEmitter.GetComponents(localEmitters); int emitterIndex = 0; foreach (var emitter in localEmitters) { SerializedProperty emitterProperty = null; for (int i = 0; i < emitters.arraySize; i++) { if (emitters.GetArrayElementAtIndex(i).FindPropertyRelative("Target").objectReferenceValue == emitter) { emitterProperty = emitters.GetArrayElementAtIndex(i); break; } } // New emitter component added to game object since we last looked if (emitterProperty == null) { emitters.InsertArrayElementAtIndex(0); emitterProperty = emitters.GetArrayElementAtIndex(0); emitterProperty.FindPropertyRelative("Target").objectReferenceValue = emitter; } if (!emitter.EventReference.IsNull) { expanded[emitterIndex] = EditorGUILayout.Foldout(expanded[emitterIndex], emitter.EventReference.Path); if (expanded[emitterIndex]) { var eventRef = EventManager.EventFromGUID(emitter.EventReference.Guid); foreach (var paramRef in eventRef.LocalParameters) { bool set = false; int index = -1; for (int i = 0; i < emitterProperty.FindPropertyRelative("Params").arraySize; i++) { if (emitterProperty.FindPropertyRelative("Params").GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue == paramRef.Name) { index = i; set = true; break; } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(paramRef.Name); bool newSet = GUILayout.Toggle(set, ""); if (!set && newSet) { index = 0; emitterProperty.FindPropertyRelative("Params").InsertArrayElementAtIndex(0); emitterProperty.FindPropertyRelative("Params").GetArrayElementAtIndex(0).FindPropertyRelative("Name").stringValue = paramRef.Name; emitterProperty.FindPropertyRelative("Params").GetArrayElementAtIndex(0).FindPropertyRelative("Value").floatValue = 0; } if (set && !newSet) { emitterProperty.FindPropertyRelative("Params").DeleteArrayElementAtIndex(index); } set = newSet; if (set) { var valueProperty = emitterProperty.FindPropertyRelative("Params") .GetArrayElementAtIndex(index).FindPropertyRelative("Value"); valueProperty.floatValue = EditorUtils.DrawParameterValueLayout(valueProperty.floatValue, paramRef); } else { using (new EditorGUI.DisabledScope(true)) { EditorUtils.DrawParameterValueLayout(0, paramRef); } } EditorGUILayout.EndHorizontal(); } } } emitterIndex++; } serializedObject.ApplyModifiedProperties(); }