Exemple #1
0
    public static DelegateMessage EventField(string label, DelegateMessage evt, GameObject dynParamSource)
    {
        EditorGUILayout.BeginVertical();

        if (label != null)
        {
            EditorGUILayout.PrefixLabel(label);
        }

        EditorGUILayout.BeginHorizontal();

        DelegateMessage newEvt = (DelegateMessage)evt.Clone();

        EventField_ContextPicker(newEvt);


        // SELECT EVENT TYPES
        GameObject target = (evt.targetId == -1) ? evt.overrideTarget:dynParamSource;

        DelegateDescriptor[] eventTypes = EditorDelegateUtil.FindEventsForObject(target);


        // SELECT EVENT & PARAMS
        DelegateDescriptor ed = EventField_EventDescriptorPopup(eventTypes, newEvt);

        EditorGUILayout.EndHorizontal();
        EventField_Parameters(ed, newEvt, dynParamSource);
        EditorGUILayout.EndVertical();

        return(newEvt);
    }
Exemple #2
0
    private static DelegateDescriptor EventField_EventDescriptorPopup(string label, DelegateDescriptor[] eventTypes, DelegateMessage oldEvent)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(label);
        DelegateDescriptor ed = EventField_EventDescriptorPopup(eventTypes, oldEvent);

        EditorGUILayout.EndHorizontal();
        return(ed);
    }
Exemple #3
0
    private static void EventField_Parameters(DelegateDescriptor ed, DelegateMessage newEvt, GameObject dynParamSource)
    {
        if (ed == null)
        {
            newEvt.name = "";
            if (newEvt.parameter != null)
            {
                newEvt.parameter.SetVoid();
            }
            return;
        }

        newEvt.name = ed.signature.methodName;

        if (ed.signature.parameterType == typeof(void))
        {
            newEvt.parameter.SetVoid();
        }
        else
        {
            EventField_ParameterField(ed, newEvt, dynParamSource);
        }
    }
Exemple #4
0
    private static void EventField_ParameterField(DelegateDescriptor ed, DelegateMessage newEvt, GameObject dynamicParamSource)
    {
        EditorGUILayout.BeginHorizontal();

        GUILayout.Label(ed.signature.parameterName, "box", GUILayout.Width(80));

        // FIND DYNAMIC PARAMS
        List <string> dynParamNames = new List <string>(new string[] { "value...", "" });
        List <string> memberNames   = new List <string>(new string[] { "", "" });
        List <Object> objects       = new List <Object>(new Object[] { null, null });
        bool          prevFoundOne  = false;

        foreach (Component comp in dynamicParamSource.GetComponents <Component>())
        {
            if (prevFoundOne)
            {
                dynParamNames.Add("");
                memberNames.Add("");
                objects.Add(null);
            }
            prevFoundOne = false;

            foreach (MemberInfo item in comp.GetType().GetMembers())
            {
                if (item.MemberType != MemberTypes.Field && item.MemberType != MemberTypes.Property)
                {
                    continue;
                }

                if (item.DeclaringType.IsAssignableFrom(typeof(Component)))
                {
                    continue;
                }

                System.Type itemType = null;

                if (item.MemberType == MemberTypes.Field)
                {
                    itemType = (item as FieldInfo).FieldType;
                }
                else if (item.MemberType == MemberTypes.Property)
                {
                    itemType = (item as PropertyInfo).PropertyType;
                }

                if (!ed.signature.parameterType.IsAssignableFrom(itemType))
                {
                    continue;
                }

                prevFoundOne = true;
                dynParamNames.Add(comp.GetType().Name + "." + item.Name);
                memberNames.Add(item.Name);
                objects.Add(comp);
            }
        }

        int dynParamId = memberNames.IndexOf(newEvt.parameter.objectMemberName);

        if (dynParamId == -1)
        {
            dynParamId = 0;
        }

        if (dynParamNames.Count > 1)
        {
            dynParamId = EditorGUILayout.Popup(dynParamId, dynParamNames.ToArray(), "popup", GUILayout.MinWidth(60));
        }

        if (dynParamId > 1 && dynParamNames.Count > 1)
        {
            newEvt.parameter.SetDynamicValue(objects[dynParamId], memberNames[dynParamId], ed.signature.parameterType);
        }
        else
        {
            if (ed.signature.parameterType == typeof(string))
            {
                newEvt.parameter.SetValue(EditorGUILayout.TextField(newEvt.parameter.stringParam), ed.signature.parameterType);
            }

            if (ed.signature.parameterType == typeof(int))
            {
                newEvt.parameter.SetValue(EditorGUILayout.IntField(newEvt.parameter.intParam), ed.signature.parameterType);
            }

            if (ed.signature.parameterType == typeof(float))
            {
                newEvt.parameter.SetValue(EditorGUILayout.FloatField(newEvt.parameter.floatParam), ed.signature.parameterType);
            }

            if (ed.signature.parameterType == typeof(Vector3))
            {
                newEvt.parameter.SetValue(EditorGUILayout.Vector3Field("", newEvt.parameter.vectorParam), ed.signature.parameterType);
            }

            if (ed.signature.parameterType == typeof(bool))
            {
                newEvt.parameter.SetValue(EditorGUILayout.Toggle(newEvt.parameter.boolParam), ed.signature.parameterType);
            }

            if (typeof(UnityEngine.Object).IsAssignableFrom(ed.signature.parameterType))
            {
                newEvt.parameter.SetValue(EditorGUILayout.ObjectField(newEvt.parameter.objectParam, ed.signature.parameterType, true), ed.signature.parameterType);
            }
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(4);
    }