예제 #1
0
        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);
        }
예제 #2
0
        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;
            }
        }