private void Awake() { this.WarnIfMultipleInstances(); _transform = this.transform; var rb = this.GetComponent <Rigidbody>(); //Resolve the mover _mover = this.As <IMoveUnits>(); if (_mover == null) { var fact = this.As <IMoveUnitsFactory>(); var charController = this.GetComponent <CharacterController>(); if (fact != null) { _mover = fact.Create(); } else if (charController != null) { _mover = new CharacterControllerMover(charController); } else if (rb != null) { _mover = new RigidBodyMover(rb); } else { _mover = new DefaultMover(_transform); } } //Make sure the rigidbody obeys the rules if (rb != null) { rb.constraints |= RigidbodyConstraints.FreezeRotation; rb.useGravity = false; } //Height resolver _heights = GameServices.heightStrategy.heightSampler; //Assign unit ref, container for components and steering visitors _steeringComponents = new List <ISteeringBehaviour>(); _orientationComponents = new List <IOrientationBehaviour>(); _steering = new SteeringOutput(); _orientation = new OrientationOutput(); _steeringInput = new SteeringInput(); }
private void Awake() { this.WarnIfMultipleInstances(); _transform = this.transform; var rb = this.GetComponent <Rigidbody>(); //Resolve the mover _mover = this.As <IMoveUnits>(); if (_mover == null) { var fact = this.As <IMoveUnitsFactory>(); var charController = this.GetComponent <CharacterController>(); if (fact != null) { _mover = fact.Create(); } else if (charController != null) { _mover = new CharacterControllerMover(charController); } else if (rb != null) { _mover = new RigidBodyMover(rb); } else { _mover = new DefaultMover(_transform); } } //Height resolver _heights = this.As <IHeightNavigator>(); if (_heights == null) { _heights = NoHeightNavigator.Instance; } //Assign unit ref, container for components and steering visitors _steeringComponents = new List <ISteeringBehaviour>(); _orientationComponents = new List <IOrientationBehaviour>(); _steering = new SteeringOutput(); _orientation = new OrientationOutput(); _steeringInput = new SteeringInput(); }
private void Awake() { this.WarnIfMultipleInstances(); _transform = this.transform; var rb = this.GetComponent<Rigidbody>(); //Resolve the mover _mover = this.As<IMoveUnits>(); if (_mover == null) { var fact = this.As<IMoveUnitsFactory>(); var charController = this.GetComponent<CharacterController>(); if (fact != null) { _mover = fact.Create(); } else if (charController != null) { _mover = new CharacterControllerMover(charController); } else if (rb != null) { _mover = new RigidBodyMover(rb); } else { _mover = new DefaultMover(_transform); } } //Height resolver _heights = this.As<IHeightNavigator>(); if (_heights == null) { _heights = NoHeightNavigator.Instance; } //Assign unit ref, container for components and steering visitors _steeringComponents = new List<ISteeringBehaviour>(); _orientationComponents = new List<IOrientationBehaviour>(); _steering = new SteeringOutput(); _orientation = new OrientationOutput(); _steeringInput = new SteeringInput(); }
private void Awake() { this.WarnIfMultipleInstances(); _transform = this.transform; var rb = this.GetComponent<Rigidbody>(); //Resolve the mover _mover = this.As<IMoveUnits>(); if (_mover == null) { var fact = this.As<IMoveUnitsFactory>(); var charController = this.GetComponent<CharacterController>(); if (fact != null) { _mover = fact.Create(); } else if (charController != null) { _mover = new CharacterControllerMover(charController); } else if (rb != null) { _mover = new RigidBodyMover(rb); } else { _mover = new DefaultMover(_transform); } } //Make sure the rigidbody obeys the rules if (rb != null) { rb.constraints |= RigidbodyConstraints.FreezeRotation; rb.useGravity = false; } //Height resolver _heights = GameServices.heightStrategy.heightSampler; //Assign unit ref, container for components and steering visitors _steeringComponents = new List<ISteeringBehaviour>(); _orientationComponents = new List<IOrientationBehaviour>(); _steering = new SteeringOutput(); _orientation = new OrientationOutput(); _steeringInput = new SteeringInput(); }
private void Awake() { this.WarnIfMultipleInstances(); _transform = this.transform; _facingOrientation = new FacingOrientation { priority = this.turnRequestPriority, turnSpeed = this.turnSpeed }; //Get the speed source _speedSource = this.As<IDefineSpeed>(); if (_speedSource == null) { Debug.LogError("A speed source component is required to steer."); this.enabled = false; } //Resolve the mover _mover = this.As<IMoveUnits>(); if (_mover == null) { var fact = this.As<IMoveUnitsFactory>(); var charController = this.GetComponent<CharacterController>(); if (fact != null) { _mover = fact.Create(); } else if (charController != null) { _mover = new CharacterControllerMover(charController); } else if (this.rigidbody != null) { _mover = new RigidBodyMover(_transform, this.rigidbody); } else { _mover = new DefaultMover(_transform); } } _unit = this.GetComponent<UnitComponent>(); _steeringComponents = new List<SteeringComponent>(); _minimumSpeedToTurnSquared = this.minimumSpeedToTurn * this.minimumSpeedToTurn; _stopped = true; }