示例#1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        serializedObject.Update();

        PowerUp pwrUp = (PowerUp)target;

        //Undo.RecordObject(target, "PowerUp change");
        selected = pwrUp.selected;
        FunctionsMenu(pwrUp);
        pwrUp.AddProperties(pwrUp);


        System.Type type;
        string      name = "";

        if (pwrUp.parameters[selected].Length != 0)     //the function has atleast one parameter
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            type = pwrUp.parameters[selected][0].ParameterType;
            name = pwrUp.parameters[selected][0].Name;

            foreach (System.Reflection.ParameterInfo parameter in pwrUp.parameters[selected])
            {
                SerializedProperty property = null;
                type = parameter.ParameterType;
                name = parameter.Name;
                int propertyIndex = pwrUp.GetPropertyIndex(type, pwrUp.GetUniqueElements(pwrUp.types));

                if (type == typeof(int))
                {
                    property = serializedObject.FindProperty("intList");
                    property = property.GetArrayElementAtIndex(propertyIndex);      //need to figure out a way to index the parameters.
                    EditorGUILayout.PropertyField(property, new GUIContent(name));
                }
                else if (type == typeof(float))
                {
                    property = serializedObject.FindProperty("value_f");
                    EditorGUILayout.PropertyField(property, new GUIContent(name));
                }
                else if (type == typeof(Vector2))
                {
                    property = serializedObject.FindProperty("value_v3");
                    EditorGUILayout.PropertyField(property, new GUIContent(name));
                }
                else if (type == typeof(System.Action))
                {
                    //property = serializedObject.FindProperty("actionList");

                    //property = property.GetArrayElementAtIndex(0);
                    ActionsMenu(pwrUp);
                }
            }

            EditorGUI.indentLevel = 0;  //Reset indent for next function

            //GUILayout.EndArea();
            EditorGUILayout.EndVertical();
        }

        if (GUI.changed)
        {
            pwrUp.OnChange();
        }
        serializedObject.ApplyModifiedProperties(); ///asdasdasd
    }