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 override void LoadCharacterModel(string prefabName)
    {
        if (this.Model != null)
        {
            GameObject.Destroy(this.Model);
        }

        GameObject o = GameObject.Instantiate(Resources.Load(prefabName)) as GameObject;

        o.transform.parent           = this.transform;
        o.transform.localPosition    = Vector3.zero;
        o.transform.localEulerAngles = Vector3.zero;

        this.MyAnimator         = o.transform.GetComponent <Animator>();
        this.MyReference        = o.transform.GetComponent <CharacterReference>();
        this.MyAnimEventHandler = o.transform.GetComponent <AnimationEventHandler>();

        this.MyReference.ParentCharacter = this;
        this.MyReference.LiveCollider    = transform.GetComponent <CapsuleCollider>();
        if (this.MyReference.DeathCollider != null)
        {
            this.MyReference.DeathCollider.GetComponent <DeathCollider>().ParentCharacter = this;
            this.MyReference.DeathCollider.enabled = false;
        }

        if (this.MyReference.FixedMeleeLeft != null)
        {
            this.MyReference.FixedMeleeLeft.Attacker = this;
            this.MyReference.FixedMeleeLeft.Rebuild(null, null);
        }

        if (this.MyReference.FixedMeleeRight != null)
        {
            this.MyReference.FixedMeleeRight.Attacker = this;
            this.MyReference.FixedMeleeRight.Rebuild(null, null);
        }

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

        this.MyLeftHandIK = o.transform.GetComponent <LeftHandIKControl>();
        this.MyLeftHandIK.Initialize();

        this.MyHeadIK = o.transform.GetComponent <HeadIKControl>();
        this.MyHeadIK.Initialize();
        this.MyHeadIK.LookTarget = LookTarget;


        //setup animator parameters initial values
        this.MyAnimator.SetInteger("AlertLevel", 0);

        this.Model      = o;
        this.Model.name = prefabName;

        if (this.MyAI != null)
        {
            this.MyAI.BlackBoard.EquippedWeapon = null;
        }


        //subscribe events
        this.MyAnimEventHandler.OnMeleeStrikeLeftFinish -= OnMeleeStrikeFinish;
        this.MyAnimEventHandler.OnMeleeStrikeLeftFinish += OnMeleeStrikeFinish;

        this.MyAnimEventHandler.OnMeleeStrikeRightFinish -= OnMeleeStrikeFinish;
        this.MyAnimEventHandler.OnMeleeStrikeRightFinish += OnMeleeStrikeFinish;

        this.MyAnimEventHandler.OnMeleeBlocked -= OnMeleeBlocked;
        this.MyAnimEventHandler.OnMeleeBlocked += OnMeleeBlocked;

        this.MyAnimEventHandler.OnHitReover -= OnInjuryRecover;
        this.MyAnimEventHandler.OnHitReover += OnInjuryRecover;

        this.MyAnimEventHandler.OnAnimationActionEnd -= OnAnimationActionEnd;
        this.MyAnimEventHandler.OnAnimationActionEnd += OnAnimationActionEnd;

        this.MyAnimEventHandler.OnMeleeStrikeHalfWay -= OnMeleeStrikeHalfWay;
        this.MyAnimEventHandler.OnMeleeStrikeHalfWay += OnMeleeStrikeHalfWay;

        this.MyAnimEventHandler.OnStartStrangle -= OnStartStrangle;
        this.MyAnimEventHandler.OnStartStrangle += OnStartStrangle;
        this.MyAnimEventHandler.OnEndStrangle   -= OnEndStrangle;
        this.MyAnimEventHandler.OnEndStrangle   += OnEndStrangle;

        this.MyAnimEventHandler.OnFootStep -= OnFootStep;
        this.MyAnimEventHandler.OnFootStep += OnFootStep;
    }
Exemplo n.º 3
0
	public override void LoadCharacterModel (string prefabName)
	{
		if(this.Model != null)
		{
			GameObject.Destroy(this.Model);
		}

		GameObject o = GameObject.Instantiate(Resources.Load(prefabName)) as GameObject;
		o.transform.parent = this.transform;
		o.transform.localPosition = Vector3.zero;
		o.transform.localEulerAngles = Vector3.zero;

		this.MyAnimator = o.transform.GetComponent<Animator>();
		this.MyReference = o.transform.GetComponent<CharacterReference>();
		this.MyAnimEventHandler = o.transform.GetComponent<AnimationEventHandler>();

		this.MyReference.ParentCharacter = this;

		if(this.MyReference.FixedMeleeLeft != null)
		{
			this.MyReference.FixedMeleeLeft.Attacker = this;
			this.MyReference.FixedMeleeLeft.Rebuild(null, null);
		}

		if(this.MyReference.FixedMeleeRight != null)
		{
			this.MyReference.FixedMeleeRight.Attacker = this;
			this.MyReference.FixedMeleeRight.Rebuild(null, null);
		}

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

		this.MyLeftHandIK = o.transform.GetComponent<LeftHandIKControl>();
		this.MyLeftHandIK.Initialize();

		this.MyHeadIK = o.transform.GetComponent<HeadIKControl>();
		this.MyHeadIK.Initialize();
		this.MyHeadIK.LookTarget = LookTarget;


		//setup animator parameters initial values
		this.MyAnimator.SetInteger("AlertLevel", 0);

		this.Model = o;
		this.Model.name = prefabName;

		if(this.MyAI != null)
		{
			this.MyAI.BlackBoard.EquippedWeapon = null;
		}


		//subscribe events
		this.MyAnimEventHandler.OnMeleeStrikeLeftFinish -= OnMeleeStrikeFinish;
		this.MyAnimEventHandler.OnMeleeStrikeLeftFinish += OnMeleeStrikeFinish;

		this.MyAnimEventHandler.OnMeleeStrikeRightFinish -= OnMeleeStrikeFinish;
		this.MyAnimEventHandler.OnMeleeStrikeRightFinish += OnMeleeStrikeFinish;

		this.MyAnimEventHandler.OnMeleeBlocked -= OnMeleeBlocked;
		this.MyAnimEventHandler.OnMeleeBlocked += OnMeleeBlocked;

		this.MyAnimEventHandler.OnHitReover -= OnInjuryRecover;
		this.MyAnimEventHandler.OnHitReover += OnInjuryRecover;

		this.MyAnimEventHandler.OnAnimationActionEnd -= OnAnimationActionEnd;
		this.MyAnimEventHandler.OnAnimationActionEnd += OnAnimationActionEnd;
	}
Exemplo n.º 4
0
	public override void LoadCharacterModel(string prefabName)
	{
		if(this.Model != null)
		{
			GameObject.Destroy(this.Model);
		}

		GameObject o = GameObject.Instantiate(Resources.Load(prefabName)) as GameObject;
		o.transform.parent = this.transform;
		o.transform.localPosition = Vector3.zero;
		o.transform.localEulerAngles = Vector3.zero;

		this.MyAnimator = o.transform.GetComponent<Animator>();
		this.MyReference = o.transform.GetComponent<CharacterReference>();
		this.MyAnimEventHandler = o.transform.GetComponent<AnimationEventHandler>();

		this.MyReference.ParentCharacter = this;

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

		this.MyLeftHandIK = o.transform.GetComponent<LeftHandIKControl>();
		this.MyLeftHandIK.Initialize();

		this.MyHeadIK = o.transform.GetComponent<HeadIKControl>();
		this.MyHeadIK.Initialize();
		this.MyHeadIK.LookTarget = LookTarget;


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

		this.Model = o;
		this.Model.name = prefabName;

		if(this.MyAI != null)
		{
			this.MyAI.BlackBoard.EquippedWeapon = null;
		}


		//subscribe events
		this.MyAnimEventHandler.OnLongGunPullOutFinish -= OnLongGunPullOutFinish;
		this.MyAnimEventHandler.OnLongGunPullOutFinish += OnLongGunPullOutFinish;

		this.MyAnimEventHandler.OnLongGunPutAwayFinish -= OnLongGunPutAwayFinish;
		this.MyAnimEventHandler.OnLongGunPutAwayFinish += OnLongGunPutAwayFinish;

		this.MyAnimEventHandler.OnPistolPullOutFinish -= OnPistolPullOutFinish;
		this.MyAnimEventHandler.OnPistolPullOutFinish += OnPistolPullOutFinish;

		this.MyAnimEventHandler.OnPistolPutAwayFinish -= OnPistolPutAwayFinish;
		this.MyAnimEventHandler.OnPistolPutAwayFinish += OnPistolPutAwayFinish;

		this.MyAnimEventHandler.OnGrenadePullOutFinish -= OnGrenadePullOutFinish;
		this.MyAnimEventHandler.OnGrenadePullOutFinish += OnGrenadePullOutFinish;

		this.MyAnimEventHandler.OnMeleePullOutFinish -= OnMeleePullOutFinish;
		this.MyAnimEventHandler.OnMeleePullOutFinish += OnMeleePullOutFinish;

		this.MyAnimEventHandler.OnReloadFinish -= OnReloadFinish;
		this.MyAnimEventHandler.OnReloadFinish += OnReloadFinish;

		this.MyAnimEventHandler.OnThrowFinish -= OnThrowFinish;
		this.MyAnimEventHandler.OnThrowFinish += OnThrowFinish;

		this.MyAnimEventHandler.OnThrowLeaveHand -= OnThrowLeaveHand;
		this.MyAnimEventHandler.OnThrowLeaveHand += OnThrowLeaveHand;

		this.MyAnimEventHandler.OnStartStrangle -= OnStartStrangle;
		this.MyAnimEventHandler.OnStartStrangle += OnStartStrangle;

		this.MyAnimEventHandler.OnEndStrangle -= OnEndStrangle;
		this.MyAnimEventHandler.OnEndStrangle += OnEndStrangle;

		this.MyAnimEventHandler.OnDeath -= OnDeath;
		this.MyAnimEventHandler.OnDeath += OnDeath;

		this.MyAnimEventHandler.OnStrangledDeath -= OnStrangledDeath;
		this.MyAnimEventHandler.OnStrangledDeath += OnStrangledDeath;

		this.MyAnimEventHandler.OnHitReover -= OnInjuryRecover;
		this.MyAnimEventHandler.OnHitReover += OnInjuryRecover;

		this.MyAnimEventHandler.OnSwitchWeapon -= OnSwitchWeapon;
		this.MyAnimEventHandler.OnSwitchWeapon += OnSwitchWeapon;

		this.MyAnimEventHandler.OnFinishTakeObject -= OnTakeObjectFinish;
		this.MyAnimEventHandler.OnFinishTakeObject += OnTakeObjectFinish;

		this.MyAnimEventHandler.OnMeleeStrikeHalfWay -= OnMeleeStrikeHalfWay;
		this.MyAnimEventHandler.OnMeleeStrikeHalfWay += OnMeleeStrikeHalfWay;

		this.MyAnimEventHandler.OnMeleeComboStageTwo -= OnMeleeComboStageTwo;
		this.MyAnimEventHandler.OnMeleeComboStageTwo += OnMeleeComboStageTwo;

		this.MyAnimEventHandler.OnMeleeStrikeLeftFinish -= OnMeleeStrikeLeftFinish;
		this.MyAnimEventHandler.OnMeleeStrikeLeftFinish += OnMeleeStrikeLeftFinish;

		this.MyAnimEventHandler.OnMeleeStrikeRightFinish -= OnMeleeStrikeRightFinish;
		this.MyAnimEventHandler.OnMeleeStrikeRightFinish += OnMeleeStrikeRightFinish;

		this.MyAnimEventHandler.OnMeleeBlockFinish -= OnMeleeBlockFinish;
		this.MyAnimEventHandler.OnMeleeBlockFinish += OnMeleeBlockFinish;
	}