예제 #1
0
        bool _createPlayerScript(BaseCamera camera)
        {
            switch (CharacterType)
            {
            case CharacterTypes.Default:
            {
                PlayerThirdPerson playerScript = character.GetComponent <PlayerThirdPerson>();
                if (!playerScript)
                {
                    playerScript = Undo.AddComponent <PlayerThirdPerson>(character);
                }
                playerScript.m_Camera = camera;
                // Create crouch camera target
                Transform camCrouchTargetXform = Utils.FindChildTransformByName(character.transform, "CameraCrouchTarget");
                if (!camCrouchTargetXform)
                {
                    GameObject cameraCrouchTarget = new GameObject("CameraCrouchTarget");
                    cameraCrouchTarget.transform.SetParent(character.transform);
                    cameraCrouchTarget.transform.localPosition = new Vector3(0.276f, 0.961f, 0.0f);
                    camCrouchTargetXform = cameraCrouchTarget.transform;
                }
                playerScript.crouchCameraTarget = camCrouchTargetXform;
                playerScript.standCameraTarget  = camera.Target;
            }
            break;

            case CharacterTypes.ThirdPerson:
            {
                PlayerThirdPerson playerScript = character.GetComponent <PlayerThirdPerson>();
                if (!playerScript)
                {
                    playerScript = Undo.AddComponent <PlayerThirdPerson>(character);
                }
                playerScript.m_Camera = camera;
                // Create crouch camera target
                Transform camCrouchTargetXform = Utils.FindChildTransformByName(character.transform, "CameraCrouchTarget");
                if (!camCrouchTargetXform)
                {
                    GameObject cameraCrouchTarget = new GameObject("CameraCrouchTarget");
                    cameraCrouchTarget.transform.SetParent(character.transform);
                    cameraCrouchTarget.transform.localPosition = new Vector3(0.276f, 0.961f, 0.0f);
                    camCrouchTargetXform = cameraCrouchTarget.transform;
                }
                playerScript.crouchCameraTarget = camCrouchTargetXform;
                playerScript.standCameraTarget  = camera.Target;
            }
            break;

            case CharacterTypes.TopDown:
            {
                PlayerTopDown playerScript = character.GetComponent <PlayerTopDown>();
                if (!playerScript)
                {
                    playerScript = Undo.AddComponent <PlayerTopDown>(character);
                }
                playerScript.m_Camera            = camera;
                playerScript.walkableTarrainMask = LayerMask.GetMask("Walkable");
            }
            break;
            }
            return(true);
        }
        /// <summary>
        /// initialize component
        /// </summary>
        public override bool initialize()
        {
            if (m_Initialized)
            {
                return(true);
            }
            if (!base.initialize())
            {
                return(false);
            }


            if (m_Player is PlayerTopDown)
            {
                m_TopDownPlayer = m_Player as PlayerTopDown;
            }
            else
            {
                Debug.LogError("TopDownPlayer component missing <" + this.ToString() + ">");
                return(false);
            }

            // setup ragdoll callbacks
            m_TopDownPlayer.ragdoll.OnHit = () =>
            {
                m_TopDownPlayer.character.simulateRootMotion = false;
                m_TopDownPlayer.character.disableMove        = true;
                m_TopDownPlayer.character.rigidBody.velocity = Vector3.zero;

                m_TopDownPlayer.disableInput = true;
                m_TopDownPlayer.noLookIK();
                m_TopDownPlayer.character.rigidBody.isKinematic      = true;
                m_TopDownPlayer.character.rigidBody.detectCollisions = false;
                m_TopDownPlayer.character.capsule.enabled            = false;
                if (m_TopDownPlayer.ragdoll.isFullRagdoll)
                {
                    m_TopDownPlayer.m_Camera.switchTargets(m_TopDownPlayer.ragdoll.RagdollBones[(int)BodyParts.Spine]);
                }
            };
            m_TopDownPlayer.ragdoll.OnStartTransition = () =>
            {
                if (!m_TopDownPlayer.ragdoll.isFullRagdoll && !m_TopDownPlayer.ragdoll.isGettingUp)
                {
                    m_TopDownPlayer.character.simulateRootMotion         = true;
                    m_TopDownPlayer.character.rigidBody.detectCollisions = true;
                    m_TopDownPlayer.character.rigidBody.isKinematic      = false;
                    m_TopDownPlayer.character.capsule.enabled            = true;
                }
                else
                {
                    m_TopDownPlayer.animator.SetFloat(/*"pForward"*/ HashIDs.ForwardFloat, 0.0f);
                    m_TopDownPlayer.animator.SetFloat(/*"pSide"*/ HashIDs.SideFloat, 0.0f);
                }
            };
            //m_TopDownPlayer.ragdoll.RagdollEventTime = 3.0f;
            //m_TopDownPlayer.ragdoll.OnTimeEnd = () =>
            //{
            //    m_TopDownPlayer.ragdoll.blendToMecanim();
            //};
            //m_Ragdoll.OnBlendEnd = () =>
            // {
            //     Debug.Log("ON BLEND END");
            // };
            //m_Ragdoll.OnGetUpEvent = () =>
            //  {
            //      Debug.Log("ON GET UP EVENT");
            //  };
            m_TopDownPlayer.ragdoll.LastEvent = () =>
            {
                m_TopDownPlayer.character.simulateRootMotion = true;
                m_TopDownPlayer.character.disableMove        = false;
                m_TopDownPlayer.disableInput = false;
                m_TopDownPlayer.character.rigidBody.isKinematic      = false;
                m_TopDownPlayer.character.rigidBody.detectCollisions = true;
                m_TopDownPlayer.character.capsule.enabled            = true;
                m_TopDownPlayer.m_Camera.switchTargets(m_TopDownPlayer.m_Camera.Target);
            };

            m_TopDownPlayer.OnAttackHit         = attack_hit_notify;
            m_TopDownPlayer.OnAttackEndNotify   = attack_end_notify;
            m_TopDownPlayer.OnAttackStartNotify = attack_start_notify;

            if (m_TopDownPlayer.triggers)
            {
                // setup trigger callbacks
                m_TopDownPlayer.triggers.OnTriggerStart = () =>
                {
                    m_TopDownPlayer.stop();
                    m_TopDownPlayer.enableMove = false;
                    if (m_TopDownPlayer.legsIK)
                    {
                        m_TopDownPlayer.legsIK.enabled = false;
                    }
                    m_TopDownPlayer.disableInput = true;
                    bool isOnLedge = m_TopDownPlayer.animator.GetBool(/*"pOnLedge"*/ HashIDs.OnLedgeBool);
                    if (!isOnLedge)
                    {
                        m_PrevStrafing    = m_Player.strafing;
                        m_Player.strafing = false;
                        m_TopDownPlayer.noLookIK();
                    }
                };
                m_TopDownPlayer.triggers.OnTriggerEnd = () =>
                {
                    m_TopDownPlayer.stop();
                    Ray        ray  = new Ray(transform.position, Vector3.down);
                    int        mask = m_TopDownPlayer.walkableTarrainMask;
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, float.MaxValue, mask))
                    {
                        m_TopDownPlayer.currentDestination = hit.point;
                    }
                    m_TopDownPlayer.enableMove = true;
                    bool isOnLedge = m_TopDownPlayer.animator.GetBool(/*"pOnLedge"*/ HashIDs.OnLedgeBool);
                    if (!isOnLedge)
                    {
                        m_Player.m_Camera.additiveRotation = false;
                        m_Player.strafing = m_PrevStrafing;
                        if (m_TopDownPlayer.legsIK)
                        {
                            m_TopDownPlayer.legsIK.enabled = true;
                        }
                        if (m_TopDownPlayer.strafing)
                        {
                            m_TopDownPlayer.character.setMoveMode(TPCharacter.MovingMode.Strafe);
                        }
                    }
                    m_TopDownPlayer.disableInput = false;
                };
            }

            if (!attackSweepBody)
            {
                Debug.LogError("Attack sweep rigidbody missing! <" + this.ToString() + ">"); return(false);
            }

            m_Initialized = true;
            return(m_Initialized);
        }