/// <summary>
        /// change existing axis by name ( first found )
        /// </summary>
        /// <param name="axis"></param>
        public static void ChangeAxisByName(InputAxis axis)
        {
            SerializedObject   serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
            SerializedProperty axesProperty     = serializedObject.FindProperty("m_Axes");

            int index = getIndexOfPropertyByName(axesProperty, axis.name);

            if (index < 0 || index >= axesProperty.arraySize)
            {
                Debug.LogWarning("Change Axis failed. Index out of range.");
                return;
            }
            SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(index);

            GetChildProperty(axisProperty, "m_Name").stringValue                  = axis.name;
            GetChildProperty(axisProperty, "descriptiveName").stringValue         = axis.descriptiveName;
            GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName;
            GetChildProperty(axisProperty, "negativeButton").stringValue          = axis.negativeButton;
            GetChildProperty(axisProperty, "positiveButton").stringValue          = axis.positiveButton;
            GetChildProperty(axisProperty, "altNegativeButton").stringValue       = axis.altNegativeButton;
            GetChildProperty(axisProperty, "altPositiveButton").stringValue       = axis.altPositiveButton;
            GetChildProperty(axisProperty, "gravity").floatValue                  = axis.gravity;
            GetChildProperty(axisProperty, "dead").floatValue        = axis.dead;
            GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity;
            GetChildProperty(axisProperty, "snap").boolValue         = axis.snap;
            GetChildProperty(axisProperty, "invert").boolValue       = axis.invert;
            GetChildProperty(axisProperty, "type").intValue          = (int)axis.type;
            GetChildProperty(axisProperty, "axis").intValue          = axis.axis - 1;
            GetChildProperty(axisProperty, "joyNum").intValue        = axis.joyNum;

            serializedObject.ApplyModifiedProperties();

            Debug.Log("axis ' " + axis.name + "' changed by name.");
        }
        /// <summary>
        /// change parameter of existing axis if has the same name of input axis
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="parameter"></param>
        /// <param name="parameterValue"></param>
        public static void ChangeAxisParameter(InputAxis axis, string parameter, string parameterValue)
        {
            SerializedObject   serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
            SerializedProperty axesProperty     = serializedObject.FindProperty("m_Axes");

            int[] indices = getAllIndicesByName(axesProperty, axis.name);
            for (int i = 0; i < indices.Length; i++)
            {
                int index = indices[i];
                if (index < 0 || index >= axesProperty.arraySize)
                {
                    Debug.LogWarning("Change Axis failed. Index out of range.");
                    continue;
                }
                SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(index);
                if (GetChildProperty(axisProperty, "m_Name").stringValue != axis.name)
                {
                    continue;
                }


                GetChildProperty(axisProperty, parameter).stringValue = parameterValue;
                serializedObject.ApplyModifiedProperties();

                Debug.Log("axis ' " + axis.name + "' changed by name.");
            }
        }
        /// <summary>
        /// add input axis
        /// </summary>
        /// <param name="axis"></param>
        public static void AddAxis(InputAxis axis)
        {
            if (AxisDefined(axis.name))
            {
#if EDITOR_UTILS_INFO
                Debug.Log("axis '" + axis.name + "' already defined.");
#endif
                return;
            }

            SerializedObject   serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
            SerializedProperty axesProperty     = serializedObject.FindProperty("m_Axes");

            axesProperty.arraySize++;
            serializedObject.ApplyModifiedProperties();

            SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1);

            GetChildProperty(axisProperty, "m_Name").stringValue                  = axis.name;
            GetChildProperty(axisProperty, "descriptiveName").stringValue         = axis.descriptiveName;
            GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName;
            GetChildProperty(axisProperty, "negativeButton").stringValue          = axis.negativeButton;
            GetChildProperty(axisProperty, "positiveButton").stringValue          = axis.positiveButton;
            GetChildProperty(axisProperty, "altNegativeButton").stringValue       = axis.altNegativeButton;
            GetChildProperty(axisProperty, "altPositiveButton").stringValue       = axis.altPositiveButton;
            GetChildProperty(axisProperty, "gravity").floatValue                  = axis.gravity;
            GetChildProperty(axisProperty, "dead").floatValue        = axis.dead;
            GetChildProperty(axisProperty, "sensitivity").floatValue = axis.sensitivity;
            GetChildProperty(axisProperty, "snap").boolValue         = axis.snap;
            GetChildProperty(axisProperty, "invert").boolValue       = axis.invert;
            GetChildProperty(axisProperty, "type").intValue          = (int)axis.type;
            GetChildProperty(axisProperty, "axis").intValue          = axis.axis - 1;
            GetChildProperty(axisProperty, "joyNum").intValue        = axis.joyNum;

            serializedObject.ApplyModifiedProperties();

            Debug.Log("axis ' " + axis.name + "' added.");
        }
Example #4
0
        static void ProjectRequrements()
        {
            EditorUtils.SetDefine("DEBUG_INFO");

            EditorUtils.AddTag("Trigger");
            EditorUtils.AddTag("Collider");
            EditorUtils.AddTag("NPC");

            const int COLLIDERLAYER         = 8;
            const int COLLIDERINACTIVELAYER = 9;
            const int TRIGGERLAYER          = 10;
            const int PLAYERLAYER           = 11;
            const int NPCLAYER        = 12;
            const int PROJECTILELAYER = 13;
            const int DEFAULTNOCAM    = 14;
            const int DEFAULTSLOPE    = 15;
            const int WALKABLE        = 16;
            const int ITEM            = 17;

            EditorUtils.AddLayer("ColliderLayer", COLLIDERLAYER);
            EditorUtils.AddLayer("ColliderInactiveLayer", COLLIDERINACTIVELAYER);
            EditorUtils.AddLayer("TriggerLayer", TRIGGERLAYER);
            EditorUtils.AddLayer("PlayerLayer", PLAYERLAYER);
            EditorUtils.AddLayer("NPCLayer", NPCLAYER);
            EditorUtils.AddLayer("ProjectileLayer", PROJECTILELAYER);
            EditorUtils.AddLayer("DefaultNoCam", DEFAULTNOCAM);
            EditorUtils.AddLayer("DefaultSlope", DEFAULTSLOPE);
            EditorUtils.AddLayer("Walkable", WALKABLE);
            EditorUtils.AddLayer("Item", ITEM);


            // trigger ignores all layers except npc and player for this case
            for (int i = 0; i < 32; i++)
            {
                Physics.IgnoreLayerCollision(TRIGGERLAYER, i, true);
                Physics.IgnoreLayerCollision(COLLIDERINACTIVELAYER, i, true);
                Physics.IgnoreLayerCollision(COLLIDERLAYER, i, true);
                Physics.IgnoreLayerCollision(PLAYERLAYER, i, true);
                Physics.IgnoreLayerCollision(NPCLAYER, i, true);
                Physics.IgnoreLayerCollision(PROJECTILELAYER, i, true);
            }
            Physics.IgnoreLayerCollision(TRIGGERLAYER, NPCLAYER, false);
            Physics.IgnoreLayerCollision(TRIGGERLAYER, PLAYERLAYER, false);

            Physics.IgnoreLayerCollision(COLLIDERLAYER, 0, false); // default
            Physics.IgnoreLayerCollision(COLLIDERLAYER, PLAYERLAYER, false);
            Physics.IgnoreLayerCollision(COLLIDERLAYER, NPCLAYER, false);
            Physics.IgnoreLayerCollision(COLLIDERLAYER, DEFAULTNOCAM, false);
            Physics.IgnoreLayerCollision(COLLIDERLAYER, DEFAULTSLOPE, false);

            Physics.IgnoreLayerCollision(PLAYERLAYER, 0, false); // default
            Physics.IgnoreLayerCollision(NPCLAYER, 0, false);    // default
            Physics.IgnoreLayerCollision(PLAYERLAYER, COLLIDERLAYER, false);
            Physics.IgnoreLayerCollision(NPCLAYER, COLLIDERLAYER, false);
            Physics.IgnoreLayerCollision(NPCLAYER, NPCLAYER, false);
            Physics.IgnoreLayerCollision(PLAYERLAYER, DEFAULTNOCAM, false);
            Physics.IgnoreLayerCollision(PLAYERLAYER, DEFAULTSLOPE, false);
            Physics.IgnoreLayerCollision(NPCLAYER, DEFAULTNOCAM, false);
            Physics.IgnoreLayerCollision(NPCLAYER, DEFAULTSLOPE, false);
            Physics.IgnoreLayerCollision(PLAYERLAYER, NPCLAYER, false);


            Physics.IgnoreLayerCollision(PROJECTILELAYER, 0, false); // default
            Physics.IgnoreLayerCollision(PROJECTILELAYER, DEFAULTNOCAM, false);
            Physics.IgnoreLayerCollision(PROJECTILELAYER, DEFAULTSLOPE, false);

            Physics.IgnoreLayerCollision(WALKABLE, 0, false); // default
            Physics.IgnoreLayerCollision(WALKABLE, DEFAULTNOCAM, false);
            Physics.IgnoreLayerCollision(WALKABLE, DEFAULTSLOPE, false);
            Physics.IgnoreLayerCollision(WALKABLE, PLAYERLAYER, false);
            Physics.IgnoreLayerCollision(WALKABLE, NPCLAYER, false);
            Physics.IgnoreLayerCollision(WALKABLE, COLLIDERLAYER, false);

            Physics.IgnoreLayerCollision(ITEM, PLAYERLAYER, false);

            InputAxis jumpAxis = new InputAxis();

            jumpAxis.name            = "Jump";
            jumpAxis.positiveButton  = "q";
            jumpAxis.descriptiveName = "Jump";
            EditorUtils.ChangeAxisByName(jumpAxis);

            InputAxis submitAxis = new InputAxis();

            submitAxis.name              = "Submit";
            submitAxis.positiveButton    = "return";
            submitAxis.altPositiveButton = "";
            submitAxis.descriptiveName   = "Submit";
            EditorUtils.ChangeAxisParameter(submitAxis, "altPositiveButton", submitAxis.altPositiveButton);

            InputAxis crouchAxis = new InputAxis();

            crouchAxis.name            = "Crouch";
            crouchAxis.positiveButton  = "c";
            crouchAxis.descriptiveName = "Crouch";
            EditorUtils.AddAxis(crouchAxis);


            InputAxis walkToggleAxis = new InputAxis();

            walkToggleAxis.name            = "WalkToggle";
            walkToggleAxis.positiveButton  = "left shift";
            walkToggleAxis.descriptiveName = "Toggle Walk";
            EditorUtils.AddAxis(walkToggleAxis);

            InputAxis diveRollAxis = new InputAxis();

            diveRollAxis.name            = "DiveRoll";
            diveRollAxis.positiveButton  = "space";
            diveRollAxis.descriptiveName = "Dive Roll";
            EditorUtils.AddAxis(diveRollAxis);

            InputAxis useAxis = new InputAxis();

            useAxis.name            = "Use";
            useAxis.positiveButton  = "e";
            useAxis.descriptiveName = "Use";
            EditorUtils.AddAxis(useAxis);

            InputAxis secondaryUse = new InputAxis();

            secondaryUse.name            = "SecondaryUse";
            secondaryUse.positiveButton  = "r";
            secondaryUse.descriptiveName = "Secondary Use Button";
            EditorUtils.AddAxis(secondaryUse);

            InputAxis pauseAxis = new InputAxis();

            pauseAxis.name            = "Pause";
            pauseAxis.positiveButton  = "p";
            pauseAxis.descriptiveName = "Pause game";
            EditorUtils.AddAxis(pauseAxis);

            InputAxis blockAxis = new InputAxis();

            blockAxis.name            = "Block";
            blockAxis.positiveButton  = "f";
            blockAxis.descriptiveName = "Block incoming attacks";
            EditorUtils.AddAxis(blockAxis);

            InputAxis dropAxis = new InputAxis();

            dropAxis.name            = "Drop";
            dropAxis.positiveButton  = "x";
            dropAxis.descriptiveName = "Drop equipment";
            EditorUtils.AddAxis(dropAxis);

            InputAxis toggleWeaponAxis = new InputAxis();

            toggleWeaponAxis.name            = "ToggleWeapon";
            toggleWeaponAxis.positiveButton  = "g";
            toggleWeaponAxis.descriptiveName = "Toggle current weapon/s";
            EditorUtils.AddAxis(toggleWeaponAxis);

            InputAxis drawWeaponAxis = new InputAxis();

            drawWeaponAxis.name            = "DrawWeapon";
            drawWeaponAxis.positiveButton  = "v";
            drawWeaponAxis.descriptiveName = "Draw current weapon/s";
            EditorUtils.AddAxis(drawWeaponAxis);

            InputAxis sheatheWeaponAxis = new InputAxis();

            sheatheWeaponAxis.name            = "SheatheWeapon";
            sheatheWeaponAxis.positiveButton  = "b";
            sheatheWeaponAxis.descriptiveName = "Sheathe current weapon/s";
            EditorUtils.AddAxis(sheatheWeaponAxis);

            InputAxis weapnShieldModeAxis = new InputAxis();

            weapnShieldModeAxis.name            = "WeaponShieldMode";
            weapnShieldModeAxis.positiveButton  = "1";
            weapnShieldModeAxis.descriptiveName = "Use weapon and shield combat mode";
            EditorUtils.AddAxis(weapnShieldModeAxis);

            InputAxis weapon2HMode = new InputAxis();

            weapon2HMode.name            = "Weapon2HMode";
            weapon2HMode.positiveButton  = "2";
            weapon2HMode.descriptiveName = "Use two handed weapon combat mode";
            EditorUtils.AddAxis(weapon2HMode);

            InputAxis bowMode = new InputAxis();

            bowMode.name            = "BowMode";
            bowMode.positiveButton  = "3";
            bowMode.descriptiveName = "Use bow combat mode";
            EditorUtils.AddAxis(bowMode);

            InputAxis dualWieldMode = new InputAxis();

            dualWieldMode.name            = "DualWieldMode";
            dualWieldMode.positiveButton  = "4";
            dualWieldMode.descriptiveName = "Use dual wield combat mode";
            EditorUtils.AddAxis(dualWieldMode);
        }