public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position.height = EditorGUIUtility.singleLineHeight; EditorGUI.LabelField(position, label); MsgEditorGUIUtility.AdvanceLine(ref position); MsgEditorGUIUtility.BeginIndent(ref position); SerializedProperty targetProp = property.FindPropertyRelative("Target"); MsgEditorGUI.MsgTargetField(position, targetProp, new GUIContent("Target")); MsgEditorGUIUtility.AdvanceLine(ref position); FilteredMsgTypeList list; int targetType = targetProp.FindPropertyRelative("Target").intValue; if (targetType == (int)MsgTarget.Mode.All) { list = FilteredMsgTypeList.Filtered(s_AllAttr); } else if (targetType == (int)MsgTarget.Mode.Other) { GameObject obj = targetProp.FindPropertyRelative("Object").objectReferenceValue as GameObject; if (obj == null) { list = FilteredMsgTypeList.None(); } else { list = FilteredMsgTypeList.Filtered(obj, s_SingleAttr); } } else { Component component = property.serializedObject.targetObject as Component; if (component == null) { list = FilteredMsgTypeList.Filtered(s_SingleAttr); } else { list = FilteredMsgTypeList.Filtered(component.gameObject, s_SingleAttr); } } SerializedProperty callProp = property.FindPropertyRelative("Call"); MsgEditorGUI.MsgCallField(position, callProp, new GUIContent("Message"), list); MsgEditorGUIUtility.EndIndent(ref position); }
static public void MsgCallField(Rect position, SerializedProperty property, GUIContent label, FilteredMsgTypeList msgTypes) { position.height = EditorGUIUtility.singleLineHeight; SerializedProperty msgTypeProp = property.FindPropertyRelative("m_MsgType"); SerializedProperty argTypeProp = property.FindPropertyRelative("m_ArgType"); SerializedProperty sendArgsProp = property.FindPropertyRelative("m_SendArg"); ArgState argState = ArgState.MissingType; MsgCall.ArgType argType = (MsgCall.ArgType)argTypeProp.intValue; MsgType msgType = MsgType.Null; // If a message type has been selected, make sure to assign our argument type int msgTypeValueInt = msgTypeProp.FindPropertyRelative("m_Value").intValue; if (msgTypeValueInt != 0) { msgType = (MsgType)msgTypeValueInt; argType = MsgCallGetArgType(msgType, out argState); } else { argType = MsgCall.ArgType.Null; } // If the argument type changes, clear args if (argTypeProp.intValue != (int)argType) { argTypeProp.intValue = (int)argType; if (argState != ArgState.MissingType) { MsgCallResetArgs(property); } } MsgTypeField(position, msgTypeProp, label, msgTypes); if (argType != MsgCall.ArgType.Null) { MsgEditorGUIUtility.AdvanceLine(ref position); MsgEditorGUIUtility.BeginIndent(ref position); Rect argsRect = position; if (argState == ArgState.Optional) { argsRect.width -= 24; Rect toggleRect = new Rect(position.x + argsRect.width + 4, position.y, 20, position.height); sendArgsProp.boolValue = EditorGUI.Toggle(toggleRect, sendArgsProp.boolValue); } else { sendArgsProp.boolValue = true; } GUI.enabled = sendArgsProp.boolValue; MsgCallArgsField(argsRect, property, msgType, argType); MsgEditorGUIUtility.EndIndent(ref position); GUI.enabled = true; } }
static public void MsgComponent(MessengerImpl inImpl, ref HashSet <MsgType> ioSelectedTypes) { EditorGUILayout.BeginVertical(); { inImpl.Active = EditorGUILayout.Toggle("Active", inImpl.Active); GUILayout.Space(10); EditorGUILayout.LabelField("ID: " + inImpl.ID.ToString(), EditorStyles.boldLabel); if (inImpl.Parent == null) { EditorGUILayout.ObjectField("Parent: ", null, typeof(GameObject), true); } else if (inImpl.Parent.IsRoot) { EditorGUILayout.ObjectField("Parent: ", Manager.Get().Host.gameObject, typeof(GameObject), true); } else { EditorGUILayout.ObjectField("Parent: ", inImpl.Parent.Owner, typeof(GameObject), true); } EditorGUILayout.LabelField("Listening for", inImpl.Handlers.Count.ToString() + (inImpl.Handlers.Count == 1 ? " message type" : " message types")); MsgEditorGUIUtility.BeginIndent(); { foreach (var entry in inImpl.Handlers) { EditorGUILayout.BeginVertical(); { List <Delegate> invokeList = new List <Delegate>(); entry.Value.GetInvokeList(invokeList); GUIContent content = new GUIContent("(" + invokeList.Count.ToString() + ") " + entry.Key.ToString(), Manager.Get().Database.Find(entry.Key).Tooltip); bool bOldFoldout = ioSelectedTypes.Contains(entry.Key); bool bFoldout = EditorGUILayout.Foldout(bOldFoldout, content); if (bFoldout) { if (!bOldFoldout) { ioSelectedTypes.Add(entry.Key); } MsgEditorGUIUtility.BeginIndent(); { foreach (var method in invokeList) { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); string targetName = method.Target == null ? "[Null]" : method.Target.ToString(); string methodName = method.Method.Name; if (method.Target.GetType() == typeof(MessengerImpl) && methodName == "TryDispatch") { GUI.enabled = false; EditorGUILayout.ObjectField(((MessengerImpl)method.Target).Owner, typeof(GameObject), true); GUI.enabled = true; EditorGUILayout.LabelField("(Child Messenger)"); } else if (method.Target is Component) { Component c = (Component)method.Target; GUI.enabled = false; EditorGUILayout.ObjectField(c, typeof(Component), true); GUI.enabled = true; EditorGUILayout.LabelField(methodName); } else { EditorGUILayout.LabelField(targetName + ": " + methodName); } EditorGUILayout.EndHorizontal(); } } MsgEditorGUIUtility.EndIndent(); } else if (bOldFoldout) { ioSelectedTypes.Remove(entry.Key); } } EditorGUILayout.EndVertical(); } } MsgEditorGUIUtility.EndIndent(); } EditorGUILayout.EndVertical(); }