Esempio n. 1
0
        private void AddAbilities()
        {
            CameraData defaultCamera  = AssetDatabase.LoadAssetAtPath <CameraData>("Assets/Dias Games/Third Person System/Camera Data/Default.asset");
            CameraData climbingCamera = AssetDatabase.LoadAssetAtPath <CameraData>("Assets/Dias Games/Climbing System/Camera Data/ClimbingCamera.asset");
            CameraData ladderCamera   = AssetDatabase.LoadAssetAtPath <CameraData>("Assets/Dias Games/Climbing System/Camera Data/LadderCamera.asset");

            if (character.GetComponent <DiasGames.ThirdPersonSystem.AnimatorManager>() == null)
            {
                character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.AnimatorManager>();
            }

            if (character.GetComponent <DiasGames.ThirdPersonSystem.UnityInputManager>() == null)
            {
                character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.UnityInputManager>();
            }

            DiasGames.ThirdPersonSystem.Locomotion m_Locomotion = character.GetComponent <DiasGames.ThirdPersonSystem.Locomotion>();
            if (m_Locomotion == null)
            {
                m_Locomotion = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.Locomotion>();

                m_Locomotion.AbilityPhysicMaterial = zeroFriction;
                m_Locomotion.CameraData            = defaultCamera;
            }

            DiasGames.ThirdPersonSystem.JumpAbility m_Jump = character.GetComponent <DiasGames.ThirdPersonSystem.JumpAbility>();
            if (m_Jump == null)
            {
                m_Jump = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.JumpAbility>();
                m_Jump.AbilityPhysicMaterial = zeroFriction;
            }

            DiasGames.ThirdPersonSystem.FallAbility m_Fall = character.GetComponent <DiasGames.ThirdPersonSystem.FallAbility>();
            if (m_Fall == null)
            {
                m_Fall = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.FallAbility>();
                m_Fall.AbilityPhysicMaterial = zeroFriction;
            }

            DiasGames.ThirdPersonSystem.RollAbility m_Roll = character.GetComponent <DiasGames.ThirdPersonSystem.RollAbility>();
            if (m_Roll == null)
            {
                m_Roll = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.RollAbility>();
            }

            DiasGames.ThirdPersonSystem.CrouchAbility m_Crouch = character.GetComponent <DiasGames.ThirdPersonSystem.CrouchAbility>();
            if (m_Crouch == null)
            {
                m_Crouch = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.CrouchAbility>();
                m_Crouch.AbilityPhysicMaterial = groundFriction;
            }

            LayerMask m_FootLayers = (1 << 0) | (1 << 14) | (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20);

            // Vault ability
            DiasGames.ThirdPersonSystem.ClimbingSystem.VaultAbility m_Vault = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.VaultAbility>();
            if (m_Vault == null)
            {
                m_Vault = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.VaultAbility>();
            }

            m_Vault.ClimbingMask = (1 << 21);
            ////

            // Step Up ability Setup
            DiasGames.ThirdPersonSystem.ClimbingSystem.StepUpAbility m_StepUp = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.StepUpAbility>();
            if (m_StepUp == null)
            {
                m_StepUp = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.StepUpAbility>();
            }

            m_StepUp.ClimbingMask = (1 << 16);
            ////

            // Half Climb ability Setup
            DiasGames.ThirdPersonSystem.ClimbingSystem.LowerClimbAbility m_LowerClimb = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.LowerClimbAbility>();
            if (m_LowerClimb == null)
            {
                m_LowerClimb = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.LowerClimbAbility>();
            }

            m_LowerClimb.ClimbingMask = (1 << 17);
            ////

            // Climbing ability setup
            DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbingAbility m_Climbing = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbingAbility>();
            if (m_Climbing == null)
            {
                m_Climbing = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbingAbility>();
            }

            m_Climbing.ClimbingMask = (1 << 18) | (1 << 19);
            m_Climbing.CameraData   = climbingCamera;
            ////

            DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbIK m_ClimbIK = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbIK>();
            if (m_ClimbIK == null)
            {
                m_ClimbIK = character.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbIK>();
            }

            m_ClimbIK.m_FeetLayers = m_FootLayers;

            DiasGames.ThirdPersonSystem.ClimbingSystem.DropToClimbAbility m_DropToClimb = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.DropToClimbAbility>();
            if (m_DropToClimb == null)
            {
                m_DropToClimb = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.DropToClimbAbility>();
            }

            m_DropToClimb.DroppableLayer = (1 << 19) | (1 << 20);
            m_DropToClimb.CameraData     = climbingCamera;

            DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbLadderAbility m_Ladder = character.GetComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbLadderAbility>();
            if (m_Ladder == null)
            {
                m_Ladder = character.gameObject.AddComponent <DiasGames.ThirdPersonSystem.ClimbingSystem.ClimbLadderAbility>();
            }
            m_Ladder.CameraData = ladderCamera;


            // -------------------------- SET IGNORE ABILITIES ---------------------------------- //

            // Jump
            m_Jump.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_Jump.IgnoreAbilities.Add(m_Locomotion);

            // Roll
            m_Roll.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_Roll.IgnoreAbilities.Add(m_Locomotion);
            m_Roll.IgnoreAbilities.Add(m_Crouch);

            //Crouch
            m_Crouch.IgnoreAbilities = new List <ThirdPersonAbility>();
            m_Crouch.IgnoreAbilities.Add(m_Locomotion);

            // Climb ladder
            m_Ladder.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_Ladder.IgnoreAbilities.Add(m_Locomotion);
            m_Ladder.IgnoreAbilities.Add(m_Fall);
            m_Ladder.IgnoreAbilities.Add(m_Jump);

            // Step up
            m_StepUp.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_StepUp.IgnoreAbilities.Add(m_Locomotion);

            // Half climb
            m_LowerClimb.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_LowerClimb.IgnoreAbilities.Add(m_Locomotion);
            m_LowerClimb.IgnoreAbilities.Add(m_Fall);
            m_LowerClimb.IgnoreAbilities.Add(m_Jump);

            // Climbing
            m_Climbing.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_Climbing.IgnoreAbilities.Add(m_Fall);
            m_Climbing.IgnoreAbilities.Add(m_Jump);

            // Drop to climb
            m_DropToClimb.IgnoreAbilities = new List <DiasGames.ThirdPersonSystem.ThirdPersonAbility>();
            m_DropToClimb.IgnoreAbilities.Add(m_Locomotion);

            // Vault
            m_Vault.IgnoreAbilities = new List <ThirdPersonAbility>();
            m_Vault.IgnoreAbilities.Add(m_Locomotion);
            m_Vault.IgnoreAbilities.Add(m_Jump);
            m_Vault.IgnoreAbilities.Add(m_Fall);
            m_Vault.IgnoreAbilities.Add(m_Crouch);

            // -------------------------------------------------------------------------------- //
        }
        protected virtual void AddAbilities()
        {
            if (character.GetComponent <DiasGames.ThirdPersonSystem.AnimatorManager>() == null)
            {
                Undo.AddComponent <DiasGames.ThirdPersonSystem.AnimatorManager>(character);
            }

            if (character.GetComponent <DiasGames.ThirdPersonSystem.UnityInputManager>() == null)
            {
                Undo.AddComponent <DiasGames.ThirdPersonSystem.UnityInputManager>(character);
            }

            FreeLocomotion m_FreeLocomotion = character.GetComponent <FreeLocomotion>();

            if (m_FreeLocomotion == null)
            {
                m_FreeLocomotion = Undo.AddComponent <FreeLocomotion>(character);

                SerializedObject locomotion = new SerializedObject(m_FreeLocomotion);

                locomotion.FindProperty("m_IdlePhysicMaterial").objectReferenceValue    = groundFriction;
                locomotion.FindProperty("m_AbilityPhysicMaterial").objectReferenceValue = zeroFriction;

                locomotion.ApplyModifiedProperties();
            }

            Strafe m_Strafe = character.GetComponent <Strafe>();

            if (m_Strafe == null)
            {
                m_Strafe = Undo.AddComponent <Strafe>(character);

                SerializedObject strafe = new SerializedObject(m_Strafe);

                strafe.FindProperty("m_IdleFriction").objectReferenceValue          = groundFriction;
                strafe.FindProperty("m_AbilityPhysicMaterial").objectReferenceValue = zeroFriction;

                strafe.ApplyModifiedProperties();
            }

            DiasGames.ThirdPersonSystem.JumpAbility m_Jump = character.GetComponent <DiasGames.ThirdPersonSystem.JumpAbility>();
            if (m_Jump == null)
            {
                m_Jump = Undo.AddComponent <DiasGames.ThirdPersonSystem.JumpAbility>(character);
                m_Jump.AbilityPhysicMaterial = zeroFriction;

                AudioClip             jumpClip = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/Dias Games/Third Person System/Audio/male_jump.wav");
                CharacterAudioManager manager  = character.GetComponent <CharacterAudioManager>();
                if (manager != null)
                {
                    if (m_Jump.OnEnterAbilityEvent == null)
                    {
                        m_Jump.OnEnterAbilityEvent = new UnityEvent();
                    }

                    UnityEventTools.AddObjectPersistentListener(m_Jump.OnEnterAbilityEvent, manager.PlayVoiceSound, jumpClip);
                }
            }

            DiasGames.ThirdPersonSystem.FallAbility m_Fall = character.GetComponent <DiasGames.ThirdPersonSystem.FallAbility>();
            if (m_Fall == null)
            {
                m_Fall = Undo.AddComponent <DiasGames.ThirdPersonSystem.FallAbility>(character);
                m_Fall.AbilityPhysicMaterial = zeroFriction;
            }

            DiasGames.ThirdPersonSystem.RollAbility m_Roll = character.GetComponent <DiasGames.ThirdPersonSystem.RollAbility>();
            if (m_Roll == null)
            {
                m_Roll = Undo.AddComponent <DiasGames.ThirdPersonSystem.RollAbility>(character);
            }


            DiasGames.ThirdPersonSystem.CrouchAbility m_Crouch = character.GetComponent <DiasGames.ThirdPersonSystem.CrouchAbility>();
            if (m_Crouch == null)
            {
                m_Crouch = Undo.AddComponent <DiasGames.ThirdPersonSystem.CrouchAbility>(character);
            }

            m_Crouch.AbilityPhysicMaterial = groundFriction;

            CrawlAbility m_Crawl = character.GetComponent <CrawlAbility>();

            if (m_Crawl == null)
            {
                m_Crawl = Undo.AddComponent <CrawlAbility>(character);
            }

            m_Crawl.AbilityPhysicMaterial = groundFriction;
            // -------------------------- SET IGNORE ABILITIES ---------------------------------- //

            // Strafe
            AddIgnoreAbility(m_Strafe, m_FreeLocomotion);

            // Jump
            AddIgnoreAbility(m_Jump, m_FreeLocomotion);
            AddIgnoreAbility(m_Jump, m_Strafe);

            // Roll
            AddIgnoreAbility(m_Roll, m_FreeLocomotion);
            AddIgnoreAbility(m_Roll, m_Strafe);
            AddIgnoreAbility(m_Roll, m_Crouch);

            //Crouch
            AddIgnoreAbility(m_Crouch, m_FreeLocomotion);
            AddIgnoreAbility(m_Crouch, m_Strafe);
            AddIgnoreAbility(m_Crouch, m_Crawl);

            //Crawl
            AddIgnoreAbility(m_Crawl, m_FreeLocomotion);
            AddIgnoreAbility(m_Crawl, m_Strafe);
            AddIgnoreAbility(m_Crawl, m_Crouch);

            // -------------------------------------------------------------------------------- //
        }