private void ChangeStateName(SerializedProperty property, string actionType)
        {
            Animator animator = m_controller.GetComponent <Animator>();
            var      states   = AnimatorUtil.GetStateMachineChildren.GetChildren(animator, actionType);

            var menu = new GenericMenu();

            for (int i = 0; i < states.Count; i++)
            {
                var state = states[i];
                menu.AddItem(new GUIContent(state), false, () =>
                {
                    property.stringValue = state;
                    serializedObject.Update();
                });
            }
            menu.ShowAsContext();
        }
 private void DestroyAllAbilities(RigidbodyCharacterController controller)
 {
     DestroyImmediate(controller.GetComponent <RTSDamageVisualization>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Fall>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Jump>(), true);
     //DestroyImmediate(controller.GetComponent<SpeedChange>(), true);
     DestroyImmediate(controller.GetComponent <RTSHeightChange>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Die>(), true);
     DestroyImmediate(controller.GetComponent <RTSAreaEffectAbility>(), true);
     DestroyImmediate(controller.GetComponent <RTSSelfHealAbility>(), true);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// The ReordableList add button has been pressed. Show the menu listing all of the possible abilities.
        /// </summary>
        private void OnAbilityListAdd(ReorderableList list)
        {
            m_AddMenu = new GenericMenu();
            for (int i = 0; i < m_AbilityTypes.Count; ++i)
            {
                if (m_Controller.GetComponent(m_AbilityTypes[i]) != null && IsUniqueAbility(m_AbilityTypes[i]))
                {
                    continue;
                }

                m_AddMenu.AddItem(new GUIContent(SplitCamelCase(m_AbilityTypes[i].Name)), false, AddAbility, m_AbilityTypes[i]);
            }

            m_AddMenu.ShowAsContext();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            m_Controller = target as RigidbodyCharacterController;
            if (m_Controller == null || serializedObject == null)
            {
                return; // How'd this happen?
            }
            base.OnInspectorGUI();

            // Show all of the fields.
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            // Ensure the correct multiplayer symbol is defined.
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0)
            var hasNetworkIdentity = (target as MonoBehaviour).GetComponent <UnityEngine.Networking.NetworkIdentity>() != null;
            var showNetworkToggle  = false;
            var removeSymbol       = false;
#if ENABLE_MULTIPLAYER
            if (!hasNetworkIdentity)
            {
                EditorGUILayout.HelpBox("ENABLE_MULTIPLAYER is defined but no NetworkIdentity can be found. This symbol needs to be removed.", MessageType.Error);
                showNetworkToggle = true;
                removeSymbol      = true;
            }
#else
            if (hasNetworkIdentity)
            {
                EditorGUILayout.HelpBox("A NetworkIdentity was found but ENABLE_MULTIPLAYER is not defined. This symbol needs to be defined.", MessageType.Error);
                showNetworkToggle = true;
            }
#endif
            if (!EditorApplication.isCompiling && showNetworkToggle && GUILayout.Button((removeSymbol ? "Remove" : "Add") + " Multiplayer Symbol"))
            {
                ToggleMultiplayerSymbol();
            }
#endif

            EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MovementType"));
            if ((m_MovementFoldout = EditorGUILayout.Foldout(m_MovementFoldout, "Movement Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                var useRootMotion = PropertyFromName(serializedObject, "m_UseRootMotion");
                EditorGUILayout.PropertyField(useRootMotion);
                if (!useRootMotion.boolValue)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundSpeed"));
                }
                else
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RootMotionSpeedMultiplier"));
                }
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundDampening"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirSpeed"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirDampening"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_RotationSpeed"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AimRotationSpeed"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_TorsoLookThreshold"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LocalCoopCharacter"));
                if (m_Controller.Movement == RigidbodyCharacterController.MovementType.Pseudo3D || m_Controller.Movement == RigidbodyCharacterController.MovementType.TopDown)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LookInMoveDirection"));
                }
                var alignToGround = PropertyFromName(serializedObject, "m_AlignToGround");
                EditorGUILayout.PropertyField(alignToGround);
                if (alignToGround.boolValue)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AlignToGroundRotationSpeed"));
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AlignToGroundDepthOffset"));
                }
                EditorGUI.indentLevel--;
            }

            if ((m_CollisionFoldout = EditorGUILayout.Foldout(m_CollisionFoldout, "Collision Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxStepHeight"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepOffset"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepSpeed"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SlopeLimit"));
                EditorGUI.indentLevel--;
            }

            if ((m_PhysicsFoldout = EditorGUILayout.Foldout(m_PhysicsFoldout, "Physics Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SkinWidth"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MovingPlatformSkinWidth"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundStickiness"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CollisionPointLayerIgnore"));
                if (m_Controller.GetComponent <CapsuleCollider>() == null)
                {
                    var capsuleCollider = PropertyFromName(serializedObject, "m_CapsuleCollider");
                    EditorGUILayout.PropertyField(capsuleCollider);
                    if (capsuleCollider.objectReferenceValue == null)
                    {
                        EditorGUILayout.HelpBox("This field is required if no CapsuleColliders exist on the base character object.", MessageType.Error);
                    }
                }
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_LinkedColliders"), true);
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundedIdleFrictionMaterial"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_GroundedMovingFrictionMaterial"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_StepFrictionMaterial"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_SlopeFrictionMaterial"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_AirFrictionMaterial"));
                EditorGUI.indentLevel--;
            }

            if ((m_RestrictionsFoldout = EditorGUILayout.Foldout(m_RestrictionsFoldout, "Constraint Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                var movementRestriction = PropertyFromName(serializedObject, "m_MovementConstraint");
                EditorGUILayout.PropertyField(movementRestriction);
                if ((RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictX ||
                    (RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictXZ)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MinXPosition"));
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxXPosition"));
                }
                if ((RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictZ ||
                    (RigidbodyCharacterController.MovementConstraint)movementRestriction.enumValueIndex == RigidbodyCharacterController.MovementConstraint.RestrictXZ)
                {
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MinZPosition"));
                    EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_MaxZPosition"));
                }
                EditorGUI.indentLevel--;
            }

            if ((m_ItemFoldout = EditorGUILayout.Foldout(m_ItemFoldout, "Item Options", InspectorUtility.BoldFoldout)))
            {
                EditorGUI.indentLevel++;
                // Explicitly update always aim so the property updates the Animator Monitor.
                var alwaysAim = EditorGUILayout.Toggle("Always Aim", m_Controller.AlwaysAim);
                if (m_Controller.AlwaysAim != alwaysAim)
                {
                    m_Controller.AlwaysAim = alwaysAim;
                }
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_CombatMovementOnAim"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemUseRotationThreshold"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_ItemForciblyUseDuration"));
                EditorGUILayout.PropertyField(PropertyFromName(serializedObject, "m_DualWieldItemForciblyUseDuration"));
                EditorGUI.indentLevel--;
            }

            if ((m_AbilityFoldout = EditorGUILayout.Foldout(m_AbilityFoldout, "Abilities", InspectorUtility.BoldFoldout)))
            {
                if (m_ReorderableAbilityList == null)
                {
                    m_Abilities = PropertyFromName(serializedObject, "m_Abilities");
                    m_ReorderableAbilityList = new ReorderableList(serializedObject, m_Abilities, true, true, true, true);
                    m_ReorderableAbilityList.drawElementCallback = OnAbilityListDraw;
                    m_ReorderableAbilityList.drawHeaderCallback  = OnAbilityListDrawHeader;
                    m_ReorderableAbilityList.onReorderCallback   = OnAbilityListReorder;
                    m_ReorderableAbilityList.onAddCallback       = OnAbilityListAdd;
                    m_ReorderableAbilityList.onRemoveCallback    = OnAbilityListRemove;
                    m_ReorderableAbilityList.onSelectCallback    = OnAbilityListSelect;
                    if (m_Controller.SelectedAbility != -1)
                    {
                        m_ReorderableAbilityList.index = m_Controller.SelectedAbility;
                    }
                }
                m_ReorderableAbilityList.DoLayoutList();
                if (m_ReorderableAbilityList.index != -1)
                {
                    if (m_ReorderableAbilityList.index < m_Abilities.arraySize)
                    {
                        DrawSelectedAbility(m_Abilities.GetArrayElementAtIndex(m_ReorderableAbilityList.index).objectReferenceValue as Ability);
                    }
                    else
                    {
                        m_ReorderableAbilityList.index = m_Controller.SelectedAbility = -1;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_Controller, "Inspector");
                serializedObject.ApplyModifiedProperties();
                InspectorUtility.SetObjectDirty(m_Controller);
            }
        }