/************************************************************************************************************************/ #region Enum /************************************************************************************************************************/ private static void DoEnumGUI(Rect area, SerializedProperty argumentProperty, GUIContent label) { var enumType = SerializedPropertyAccessor.GetValue<PersistentArgument>(argumentProperty).SystemType; if (enumType == null) { DoErrorMessageGUI(area, argumentProperty, label, "Error: enum type not set"); return; } var i = argumentProperty.FindPropertyRelative(Names.PersistentArgument.Int); label = EditorGUI.BeginProperty(area, label, argumentProperty); EditorGUI.BeginChangeCheck(); int value; if (enumType.IsDefined(typeof(FlagsAttribute), true)) { value = DrawEnumMaskField(area, label, i.intValue, enumType); } else { value = Convert.ToInt32(EditorGUI.EnumPopup(area, label, (Enum)Enum.ToObject(enumType, i.intValue))); } if (EditorGUI.EndChangeCheck()) { i.intValue = value; } EditorGUI.EndProperty(); }
/************************************************************************************************************************/ private static void DoObjectGUI(Rect area, SerializedProperty argumentProperty, GUIContent label) { var o = argumentProperty.FindPropertyRelative(Names.PersistentArgument.Object); label = EditorGUI.BeginProperty(area, label, o); EditorGUI.BeginChangeCheck(); var type = SerializedPropertyAccessor.GetValue<PersistentArgument>(argumentProperty).SystemType ?? typeof(UnityEngine.Object); var value = EditorGUI.ObjectField(area, label, o.objectReferenceValue, type, true); if (EditorGUI.EndChangeCheck()) { o.objectReferenceValue = value; } EditorGUI.EndProperty(); }
/// <summary>Stores the details of the call contained in the specified property.</summary> public static void CopyCall(SerializedPropertyAccessor accessor, Object target) { var call = (PersistentCall)accessor.GetValue(target); CopyCall(call); }
/// <summary>Stores the details of the event contained in the specified property.</summary> public static void CopyEvent(SerializedPropertyAccessor accessor, Object target) { var e = (UltEventBase)accessor.GetValue(target); CopyEvent(e); }
/************************************************************************************************************************/ /// <summary>Caches the event from the specified property.</summary> public void BeginEvent(SerializedProperty eventProperty) { EventProperty = eventProperty; Event = SerializedPropertyAccessor.GetValue <UltEventBase>(eventProperty); }
/// <summary>Returns the call encapsulated by the specified property.</summary> public static PersistentCall GetCall(SerializedProperty callProperty) { return(SerializedPropertyAccessor.GetValue <PersistentCall>(callProperty)); }
/************************************************************************************************************************/ private static void DoLinkedValueGUI(Rect area, SerializedProperty argumentProperty, GUIContent label) { var color = GUI.color; label = EditorGUI.BeginProperty(area, label, argumentProperty); EditorGUI.PrefixLabel(area, label); area.xMin += EditorGUIUtility.labelWidth; var argument = SerializedPropertyAccessor.GetValue<PersistentArgument>(argumentProperty); var callIndex = argument._Int; var argumentType = argument.SystemType; if (argumentType == null) { GUI.color = PersistentCallDrawer.ErrorFieldColor; GUI.Label(area, "Unable to determine argument type"); } else if (DrawerState.Current.Event != null) { switch (argument.Type) { case PersistentArgumentType.Parameter: label.text = "Parameter " + callIndex; var parameterTypes = DrawerState.Current.Event.ParameterTypes; var parameters = DrawerState.Current.Event.Parameters; if (callIndex < 0 || callIndex >= parameterTypes.Length) { GUI.color = PersistentCallDrawer.ErrorFieldColor; label.tooltip = "Parameter link index out of range"; } else { var parameterType = parameterTypes[callIndex]; label.text += " (" + parameterType.GetNameCS(false); if (parameters != null) label.text += " " + parameters[callIndex].Name; label.text += ")"; if (!argumentType.IsAssignableFrom(parameterType)) { GUI.color = PersistentCallDrawer.ErrorFieldColor; label.tooltip = "Incompatible parameter type"; } } break; case PersistentArgumentType.ReturnValue: label.text = "Return Value " + callIndex + ": "; var linkedMethod = DrawerState.Current.GetLinkedMethod(callIndex); if (linkedMethod == null) { label.text += "(no method set)"; GUI.color = PersistentCallDrawer.ErrorFieldColor; } else { label.text += MethodSelectionMenu.GetMethodSignature(linkedMethod, true); if (DrawerState.Current.callIndex >= 0 && DrawerState.Current.callIndex <= callIndex) { GUI.color = PersistentCallDrawer.ErrorFieldColor; label.tooltip = "The linked method must be called before this argument can retrieve its return value"; } else if (!argumentType.IsAssignableFrom(linkedMethod.GetReturnType())) { GUI.color = PersistentCallDrawer.ErrorFieldColor; label.tooltip = "Return type is incompatible with argument type"; } } break; } if (GUI.Button(area, label, PersistentCallDrawer.PopupButtonStyle)) { if (Event.current.button == 0) ShowLinkMenu(area, argumentProperty, argumentType, callIndex, argument.Type); } } EditorGUI.EndProperty(); GUI.color = color; }