示例#1
0
    void DrawActionController(ActionsController actionControler)
    {
        GUILayout.BeginVertical("Actions", "window");

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        showWindow = GUILayout.Toggle(showWindow, showWindow ? "Close Actions" : "Open Actions", "button", GUILayout.ExpandWidth(true));
        if (showWindow)
        {
            EditorGUILayout.HelpBox("The Input has being mapped using the 360 Gamepad layout, to modify a keyboard button open the Input Manager and change the Alt Positive Button. For Mobile Input, check the Mobile DemoScene and the MobileControls prefab.", MessageType.Info);
            EditorGUILayout.Space();

            var         type              = actionControler.GetType();
            FieldInfo[] types             = type.GetFields();
            var         _actionController = serializedObject.FindProperty("actionsController");

            foreach (FieldInfo info in types)
            {
                var         childType  = info.FieldType;
                FieldInfo[] childTypes = childType.GetFields();
                GUILayout.BeginVertical("box");
                var prop      = _actionController.FindPropertyRelative(info.Name);
                var useAction = prop.FindPropertyRelative("use");
                var options   = prop.FindPropertyRelative("options");
                var input     = prop.FindPropertyRelative("input");

                GUILayout.BeginHorizontal();
                useAction.boolValue = GUILayout.Toggle(useAction.boolValue, "");
                GUILayout.Label(info.Name, GUILayout.Width(80));
                if (useAction.boolValue)
                {
                    //GUILayout.FlexibleSpace();
                    GUILayout.Label("Input");
                    //EditorGUILayout.Space();
                    EditorGUILayout.PropertyField(input, new GUIContent(""));
                }
                GUILayout.EndHorizontal();

                if (childTypes.Length > 3)
                {
                    if (useAction.boolValue)
                    {
                        options.boolValue = EditorGUILayout.Foldout(options.boolValue, "...");
                    }
                    else
                    {
                        options.boolValue = false;
                    }

                    if (options.boolValue == true)
                    {
                        foreach (FieldInfo childInfo in childTypes)
                        {
                            if (!childInfo.Name.Equals("use") && !childInfo.Name.Equals("options") && !childInfo.Name.Equals("input"))
                            {
                                var childProp = prop.FindPropertyRelative(childInfo.Name);
                                EditorGUILayout.PropertyField(childProp, true);
                            }
                        }
                    }
                }
                //EditorGUILayout.Space();
                GUILayout.EndVertical();
            }

            EditorGUILayout.HelpBox("The LT and RT buttons are Axis, make sure to change the condition from Input.GetButton to Input.GetAxis on the method of you action", MessageType.Info);
        }
        GUILayout.EndVertical();

        if (GUI.changed)
        {
            serializedObject.ApplyModifiedProperties();
        }
    }