Exemplo n.º 1
0
        static private MsgCall.ArgType MsgCallGetArgType(MsgType inType, out ArgState outOptional)
        {
            Metadata meta = Manager.Get().Database.Find(inType);

            if (meta == null || meta.ArgType == null)
            {
                outOptional = meta == null ? ArgState.MissingType : ArgState.Optional;
                return(MsgCall.ArgType.Null);
            }

            outOptional = meta.HasFlags(MsgFlags.OptionalArgs) ? ArgState.Optional : ArgState.Required;

            if (meta.ArgType == typeof(int))
            {
                return(MsgCall.ArgType.Int);
            }
            if (meta.ArgType == typeof(float))
            {
                return(MsgCall.ArgType.Float);
            }
            if (meta.ArgType == typeof(bool))
            {
                return(MsgCall.ArgType.Bool);
            }
            if (meta.ArgType == typeof(string))
            {
                return(MsgCall.ArgType.String);
            }
            if (meta.ArgType.IsEnum)
            {
                return(MsgCall.ArgType.Enum);
            }
            if (typeof(UnityEngine.Object).IsAssignableFrom(meta.ArgType))
            {
                return(MsgCall.ArgType.UnityObject);
            }

            Debug.LogError("No inspector type available for message of type '" + meta.Name + "'!");
            return(MsgCall.ArgType.Null);
        }
Exemplo n.º 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;
            }
        }