internal static ReferenceHandle Register(MessengerImpl messenger, object target, bool weakreference) { var attrs = MessageHandleUtil.GetAttributes(target.GetType()); var handles = new ReferenceHandle[attrs.Length]; for (int i = 0; i < attrs.Length; i++) { var attr = attrs[i]; handles[i] = attr.m_Register(messenger, target, attr, weakreference); } return(new ReferenceHandle(handles)); }
public override void OnInspectorGUI() { MessengerComponent component = ((MessengerComponent)target); MessengerImpl m = component.Messenger; if (m == null) { EditorGUILayout.HelpBox("Runtime only", MessageType.Info); return; } MsgEditorGUI.MsgComponent(m, ref m_SelectedTypes); }
// Internal constructor internal Messenger(MessengerImpl inImpl) { m_Impl = inImpl; }
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(); }
/// <summary> /// Gets or creates a Messenger for the given GameObject. /// </summary> static public Messenger Require(GameObject inGameObject) { MessengerImpl impl = Manager.Get().Require(inGameObject); return(impl == null ? null : impl.Interface); }
/// <summary> /// Finds the Messenger for the given Component's GameObject. /// </summary> static public Messenger Find(Component inComponent) { MessengerImpl impl = Manager.Get().Find(inComponent.gameObject); return(impl == null ? null : impl.Interface); }