// Use this for initialization void Awake() { meleeCamplaces = new SpCamPositions(meleedIdle.localPosition, meleeAim.localPosition, meleeRun.localPosition); rangedCamplaces = new SpCamPositions(rangedIdle.localPosition, rangedAim.localPosition, rangedRun.localPosition); ISpView meleeBasicView = new SpOneView(meleedIdle, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); ISpView meleeRunView = new SpOneView(meleeRun, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); ISpView meleeAimView = new SpOneView(meleeAim, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); ISpView rangedBasicView = new SpOneView(rangedIdle, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); ISpView rangedRunView = new SpOneView(rangedRun, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); ISpView rangedAimView = new SpOneView(rangedAim, transform, 5.0f, -40.0f, 30.0f, 0.1f, 5f); meleeView = new SpStateView(meleeBasicView, meleeAimView, meleeRunView); rangedView = new SpStateView(rangedBasicView, rangedAimView, rangedRunView); objectRotator = new SpacemarineRotator(objectToRotateTransform, 5f); cameraFollow = new SpCameraFollow(target, transform, collidewith, ref meleeView, ref rangedView, ref objectRotator); }
// Use this for initialization void Start() { ICameraData camData = userCamera.GetComponent <ICameraData>(); spCamera = camData.SpCamera; invertoryLogic = GetComponent <IInvertoryData>().InvertoryLogic; Transform follow = transform; CharacterController characterController = GetComponent <CharacterController>(); characterControl = new SpacemarineMove(ref characterController, ref follow, collideWith); movementInput = new SpMovementAndMeleeCombat(ref rayCastFrom, collideWith, ref characterController); movementLogic = new SpMovementAndMeleeLogic(movementInput); rangedInput = new RangedCombatInput(); rangedLogic = new RangedCombatLogic(ref rangedInput, spCamera.CameraTransform); spaceMove = new ControlSpMovement(ref movementLogic, ref characterControl, ref characterAnimator, ref rangedLogic, ref invertoryLogic, ref spCamera); }
public ControlSpMovement(ref IMovementAndMeleeCombatLogic input, ref IMove characterController , ref Animator animator, ref IRangedCombatLogic rangedLogic, ref IInvertoryLogic invertoryLogic, ref ISpCameraFollow camera) { this.rangedInput = rangedLogic; this.rangedInput.InputChanged += RangedInput_InputChanged; this.invertoryInput = invertoryLogic; this.spCamera = camera; // Movement FSM setup this.movementAndMeleeControl = input; this.fSMSpMovement = new FSMachineSpacemarineMove(EMovementID.Walking, ref this.movementAndMeleeControl, true); WalkState walkState = new WalkState(true, 2.0f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Walking, ref animator); RunState runState = new RunState(false, 5.0f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Running, ref animator); SmashState smashState = new SmashState(false, 6.0f, 1.25f, ref characterController, ref this.movementAndMeleeControl, EMovementID.Smashing, ref animator); FallState fallState = new FallState(2.0f, -Physics.gravity.y * Vector3.down, true, ref characterController, ref this.movementAndMeleeControl, EMovementID.Falling, ref animator); LandState landState = new LandState(0.75f, false, ref input, ref characterController, EMovementID.Landing); this.fSMSpMovement.AddState(walkState); this.fSMSpMovement.AddState(runState); this.fSMSpMovement.AddState(smashState); this.fSMSpMovement.AddState(fallState); this.fSMSpMovement.AddState(landState); this.fSMSpMovement.SetDefaultState(walkState); this.fSMSpMovement.StateChanged += FSMSpMovement_StateChanged; // Melee FSM machine setup AttackState attackState = new AttackState(false, EMeleeAttackID.Attacking, ref this.movementAndMeleeControl, ref invertoryLogic, ref animator); MeleeIdle meleeIdle = new MeleeIdle(true, EMeleeAttackID.Idle, ref this.movementAndMeleeControl); this.fSMSpCombat = new FSMCombatSpacemarine(true, EMeleeAttackID.Idle, ref this.movementAndMeleeControl, ref invertoryLogic); this.fSMSpCombat.AddState(attackState); this.fSMSpCombat.AddState(meleeIdle); this.fSMSpCombat.SetDefaultState(meleeIdle); //Ranged FSM setup IHoldWeapon holdWeaponInfo = new HoldPistol(5.0f); IRangedState holdState = new HoldState(true, ref rangedLogic, ERangedAttackID.Hold, ref holdWeaponInfo, ref animator, ref invertoryInput); IRangedShootState shootState = new ShootState(true, ERangedAttackID.Shoot, ref rangedLogic, ref animator, ref invertoryLogic); IRangedState reloadState = new ReloadState(true, ref rangedLogic, ERangedAttackID.Reload, ref invertoryLogic, ref animator); IRangedState laydownState = new LaydownState(true, ref rangedLogic, ERangedAttackID.LayDown, ref invertoryLogic); this.fSMSpRangedCombat = new FSMRangedSpacemarine(true, ERangedAttackID.LayDown, ref rangedLogic, ref invertoryLogic); this.fSMSpRangedCombat.AddState(holdState); this.fSMSpRangedCombat.AddState(reloadState); this.fSMSpRangedCombat.AddState(shootState); this.fSMSpRangedCombat.AddState(laydownState); this.fSMSpRangedCombat.SetDefaultState(laydownState); this.fSMSpRangedCombat.StateChanged += FSMSpRangedCombat_StateChanged; // Invertory Setup InvertoryIdle invertoryIdleState = new InvertoryIdle(true, ref invertoryLogic); InvertorySwitch invertorySwitchState = new InvertorySwitch(true, ref invertoryLogic, ref animator); this.fSMInvertory = new FSMInvertory(EInvertoryStateID.None, ref invertoryLogic); this.fSMInvertory.AddState(invertoryIdleState); this.fSMInvertory.AddState(invertorySwitchState); this.fSMInvertory.SetDefaultState(invertoryIdleState); this.fSMInvertory.StateChanged += FSMInvertory_StateChanged; if (invertoryLogic.HasInputModel) { this.spCamera.ObjectRotator.CanRotate = !invertoryLogic.InputInfo.CurrentWeapons.IsMeleeEquipment; this.spCamera.IsMeleeViewEnabled = !invertoryLogic.InputInfo.CurrentWeapons.IsMeleeEquipment; } else { this.spCamera.IsMeleeViewEnabled = false; } }