Exemplo n.º 1
0
    public void Initialize()
    {
        this.MyAnimator = GetComponentInChildren<Animator>();
        this.MyReference = GetComponentInChildren<CharacterReference>();
        this.MyEventHandler = GetComponentInChildren<CharacterEventHandler>();

        this.MyReference.ParentCharacter = this;

        //setup animator parameters initial values
        this.MyAnimator.SetBool("IsAiming", false);
        this.MyAnimator.SetBool("IsSneaking", false);

        this.Destination = transform.position;
        MyNavAgent = GetComponent<NavMeshAgent>();
        UpperBodyState = HumanUpperBodyStates.Idle;
        ActionState = HumanActionStates.None;

        //load aim target and look target
        GameObject aimTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKAimTargetRoot"));
        GameObject lookTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKLookTarget"));
        AimTargetRoot = aimTarget.transform;
        AimTarget = AimTargetRoot.Find("IKAimTarget").transform;
        LookTarget = lookTarget.transform;

        this.MyAimIK = GetComponentInChildren<AimIK>();
        this.MyAimIK.solver.target = AimTarget;
        this.MyAimIK.solver.IKPositionWeight = 0;
        this.MyAimIK.solver.SmoothDisable();

        this.MyLeftHandIK = GetComponentInChildren<LeftHandIKControl>();
        this.MyLeftHandIK.Initialize();

        this.MyHeadIK = GetComponentInChildren<LookAtIK>();
        this.MyHeadIK.solver.target = LookTarget;

        this.MyStatus = new CharacterStatus();
        this.MyStatus.Initialize();

        //each time a human char is initialized it's added to NPC manager's list of human characters to keep track of
        GameManager.Inst.NPCManager.AddHumanCharacter(this);

        CurrentAnimState = new HumanAnimStateIdle(this);
        //SendCommand(HumanCharCommands.Unarm);

        MyAI = GetComponent<AI>();
        MyAI.Initialize(this);

        //subscribe events
        this.MyEventHandler.OnLongGunPullOutFinish += OnLongGunPullOutFinish;
        this.MyEventHandler.OnLongGunPutAwayFinish += OnLongGunPutAwayFinish;
        this.MyEventHandler.OnPistolPullOutFinish += OnPistolPullOutFinish;
        this.MyEventHandler.OnPistolPutAwayFinish += OnPistolPutAwayFinish;
        this.MyEventHandler.OnReloadFinish += OnReloadFinish;
        this.MyEventHandler.OnThrowFinish += OnThrowFinish;
        this.MyEventHandler.OnThrowLeaveHand += OnThrowLeaveHand;
        this.MyEventHandler.OnBulletInjury += OnBulletInjury;
        this.MyEventHandler.OnDeath += OnDeath;
    }
Exemplo n.º 2
0
    public void OnThrowFinish()
    {
        if(UpperBodyState == HumanUpperBodyStates.Aim)
        {
            MyAimIK.solver.SmoothEnable();
            //MyAimIK.solver.transform = this.MyReference.CurrentWeapon.GetComponent<Weapon>().AimTransform;
        }
        else
        {
            MyAimIK.solver.SmoothDisable();
        }

        MyHeadIK.solver.SmoothEnable();

        //move weapon back to right hand mount
        if(this.MyReference.CurrentWeapon != null)
        {
            Weapon myWeapon = this.MyReference.CurrentWeapon.GetComponent<Weapon>();
            myWeapon.transform.parent = MyReference.RightHandWeaponMount.transform;
            myWeapon.transform.localPosition = myWeapon.InHandPosition;
            myWeapon.transform.localEulerAngles = myWeapon.InHandAngles;
        }

        IsBodyLocked = false;
        ActionState = HumanActionStates.None;

        SendCommand(HumanCharCommands.FinishThrow);
    }
Exemplo n.º 3
0
    public override void SendCommand(HumanCharCommands command)
    {
        //following commands are not given by AI or user. All commands that will unlock the body go here

        if(IsBodyLocked)
        {
            return;
        }

        //following commands are given by AI or user, and can be locked
        CurrentAnimState.SendCommand(command);

        if(command == HumanCharCommands.Crouch)
        {
            CapsuleCollider collider = GetComponent<CapsuleCollider>();
            collider.height = 1.3f;
            collider.center = new Vector3(0, 0.6f, 0);

        }

        if(command == HumanCharCommands.StopCrouch)
        {
            CapsuleCollider collider = GetComponent<CapsuleCollider>();
            collider.height = 1.7f;
            collider.center = new Vector3(0, 1, 0);
        }

        if(command == HumanCharCommands.Aim && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && CurrentStance != HumanStances.Sprint)
        {
            if(ActionState == HumanActionStates.None)
            {
                UpperBodyState = HumanUpperBodyStates.Aim;
                MyAimIK.solver.SmoothEnable(2.5f);
                MyLeftHandIK.SmoothEnable();
                MyHeadIK.solver.SmoothDisable();
                MyAnimator.SetBool("IsAiming", true);
                //StartCoroutine(WaitAndEnableAimIK(0.2f));
            }
            else if(ActionState == HumanActionStates.SwitchWeapon)
            {
                UpperBodyState = HumanUpperBodyStates.Aim;
            }
        }

        if(command == HumanCharCommands.StopAim && ActionState == HumanActionStates.None)
        {
            UpperBodyState = HumanUpperBodyStates.Idle;
            MyAimIK.solver.SmoothDisable(9);
            MyHeadIK.solver.SmoothEnable();
            MyAnimator.SetBool("IsAiming", false);

            if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                MyLeftHandIK.SmoothDisable(9);
            }
            //Debug.Log("stopping aim");
        }

        if(command == HumanCharCommands.Sprint)
        {

            if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun)
            {
                CurrentStance = HumanStances.CrouchRun;
            }
            else
            {
                CurrentStance = HumanStances.Sprint;
                MyAimIK.solver.SmoothDisable();
                MyHeadIK.solver.SmoothDisable();
            }
        }

        if(command == HumanCharCommands.StopSprint)
        {
            if(UpperBodyState == HumanUpperBodyStates.Aim)
            {
                MyAimIK.solver.SmoothEnable();
            }

            if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch)
            {
                CurrentStance = HumanStances.Crouch;
            }
            else
            {
                CurrentStance = HumanStances.Run;
            }
            MyHeadIK.solver.SmoothEnable();
        }

        if(command == HumanCharCommands.SwitchWeapon2)
        {
            Debug.Log("current human action state " + ActionState);
            if(ActionState == HumanActionStates.None)
            {
                MyLeftHandIK.SmoothDisable(15);
                MyAimIK.solver.SmoothDisable(9);
                MyAnimator.SetInteger("WeaponType", 2);
                SwitchWeapon("AK47");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.SwitchWeapon1)
        {
            if(ActionState == HumanActionStates.None)
            {
                if(UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    //MyLeftHandIK.SmoothEnable();
                }
                else
                {

                }
                MyLeftHandIK.SmoothDisable(15);
                MyAimIK.solver.SmoothDisable(9);
                MyAnimator.SetInteger("WeaponType", 1);
                SwitchWeapon("44MagnumRevolver");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.Unarm)
        {
            if(ActionState == HumanActionStates.None)
            {
                MyLeftHandIK.SmoothDisable();
                UpperBodyState = HumanUpperBodyStates.Idle;
                MyAimIK.solver.SmoothDisable();
                MyHeadIK.solver.SmoothEnable();
                MyAnimator.SetBool("IsAiming", false);
                MyAnimator.SetInteger("WeaponType", 0);
                SwitchWeapon("");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.PullTrigger)
        {
            if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
            {
                return;
            }

            if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                //
                this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull();

            }
        }

        if(command == HumanCharCommands.ReleaseTrigger)
        {
            if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
            {
                return;
            }

            if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                //
                this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease();

            }
        }

        if(command == HumanCharCommands.Reload)
        {
            if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null)
            {
                if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
                {
                    MyAimIK.solver.SmoothDisable();
                    MyAnimator.SetTrigger("Reload");

                    MyLeftHandIK.SmoothDisable();

                }

                MyHeadIK.solver.SmoothDisable();

                ActionState = HumanActionStates.Reload;

            }
        }

        if(command == HumanCharCommands.CancelReload)
        {
            if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null)
            {
                Debug.Log("cancel reload");
                if(UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    MyAimIK.solver.SmoothEnable();
                    MyAnimator.SetTrigger("CancelReload");
                }
                else
                {
                    MyAnimator.SetTrigger("CancelReload");
                }

                if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
                {
                    MyLeftHandIK.SmoothEnable();
                }
                else
                {
                    Debug.Log("done reloading pistol " + UpperBodyState);
                    if(UpperBodyState == HumanUpperBodyStates.Aim)
                    {
                        MyLeftHandIK.SmoothEnable();
                    }
                    else
                    {
                        MyLeftHandIK.SmoothDisable();
                    }
                }

                MyHeadIK.solver.SmoothEnable();
                ActionState = HumanActionStates.None;
            }
        }

        if(command == HumanCharCommands.ThrowGrenade)
        {
            if(ActionState != HumanActionStates.None)
            {
                return;
            }

            if(UpperBodyState == HumanUpperBodyStates.Aim)
            {
                //MyAimIK.solver.SmoothDisable();
            }

            if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
            {
                MyLeftHandIK.SmoothEnable();
            }

            //MyHeadIK.solver.SmoothDisable(1);

            //move weapon to torso mount so that right hand is free
            if(this.MyReference.CurrentWeapon != null)
            {
                this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform;
            }
            MyAnimator.SetTrigger("ThrowGrenade");

            _throwTarget = this.AimPoint;
            _throwDir = this.AimPoint - transform.position;
            IsBodyLocked = true;

            ActionState = HumanActionStates.Throw;

            _thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("TestGrenade"))).GetComponent<ThrownObject>();
            _thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true;

            _thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform;
            _thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition;
            _thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation;
        }
    }
Exemplo n.º 4
0
    public void OnReloadFinish()
    {
        if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null)
        {
            Debug.Log("finish reload");
            if(UpperBodyState == HumanUpperBodyStates.Aim)
            {
                MyAimIK.solver.SmoothEnable();
            }

            if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
            {
                MyLeftHandIK.SmoothEnable();
            }
            else
            {
                Debug.Log("done reloading pistol " + UpperBodyState);
                if(UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    MyLeftHandIK.SmoothEnable();
                }
                else
                {
                    MyLeftHandIK.SmoothDisable();
                }
            }
            MyHeadIK.solver.SmoothEnable();

            ActionState = HumanActionStates.None;
        }
    }
Exemplo n.º 5
0
 public void OnPistolPutAwayFinish()
 {
     ActionState = HumanActionStates.None;
 }
Exemplo n.º 6
0
 public void OnPistolPullOutFinish()
 {
     ActionState = HumanActionStates.None;
     if(UpperBodyState == HumanUpperBodyStates.Aim)
     {
         SendCommand(HumanCharCommands.Aim);
     }
     else
     {
         MyLeftHandIK.SmoothDisable(6);
     }
 }
Exemplo n.º 7
0
 public void OnLongGunPutAwayFinish()
 {
     ActionState = HumanActionStates.None;
 }
Exemplo n.º 8
0
    public void OnLongGunPullOutFinish()
    {
        ActionState = HumanActionStates.None;
        this.MyLeftHandIK.SmoothEnable();

        if(UpperBodyState == HumanUpperBodyStates.Aim)
        {
            SendCommand(HumanCharCommands.Aim);
        }
    }