Example #1
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;
            }
        }
Example #2
0
        static public void MsgCallArgsField(Rect position, SerializedProperty property, MsgType inMsgType, MsgCall.ArgType inArgType)
        {
            Metadata meta        = Manager.Get().Database.Find(inMsgType);
            Type     realArgType = meta.ArgType;

            SerializedProperty intProp    = property.FindPropertyRelative("m_IntArg");
            SerializedProperty floatProp  = property.FindPropertyRelative("m_FloatArg");
            SerializedProperty stringProp = property.FindPropertyRelative("m_StringArg");
            SerializedProperty objProp    = property.FindPropertyRelative("m_ObjectArg");

            EditorGUI.BeginChangeCheck();

            switch (inArgType)
            {
            case MsgCall.ArgType.Int:
            {
                int newVal = EditorGUI.IntField(position, "Arg", intProp.intValue);
                if (EditorGUI.EndChangeCheck())
                {
                    intProp.intValue = newVal;
                }
                break;
            }

            case MsgCall.ArgType.Float:
            {
                float newVal = EditorGUI.FloatField(position, "Arg", floatProp.floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    floatProp.floatValue = newVal;
                }
                break;
            }

            case MsgCall.ArgType.Bool:
            {
                int newVal = EditorGUI.Toggle(position, "Arg", intProp.intValue > 0) ? 1 : 0;
                if (EditorGUI.EndChangeCheck())
                {
                    intProp.intValue = newVal;
                }
                break;
            }

            case MsgCall.ArgType.String:
            {
                string newVal = EditorGUI.TextField(position, "Arg", stringProp.stringValue);;
                if (EditorGUI.EndChangeCheck())
                {
                    stringProp.stringValue = newVal;
                }
                break;
            }

            case MsgCall.ArgType.UnityObject:
            {
                if (GUI.enabled && objProp.objectReferenceValue == null)
                {
                    GUI.color = MsgEditorGUIUtility.ErrorColor;
                }
                UnityEngine.Object newVal = EditorGUI.ObjectField(position, "Arg", objProp.objectReferenceValue, realArgType, true);
                if (EditorGUI.EndChangeCheck())
                {
                    objProp.objectReferenceValue = newVal;
                }
                GUI.color = Color.white;
                break;
            }

            case MsgCall.ArgType.Enum:
            {
                Enum e        = (Enum)Enum.ToObject(realArgType, intProp.intValue);
                Enum newValue = EditorGUI.EnumPopup(position, "Arg", e);
                if (EditorGUI.EndChangeCheck())
                {
                    intProp.intValue = Convert.ToInt32(Convert.ChangeType(newValue, realArgType));
                }
                break;
            }
            }
        }