public NpcController(GameView inGameView, ActorFacing inFacing) : base(inGameView)
        {
            // --------------------------------------------------------------------------------
            // Initializing
            // --------------------------------------------------------------------------------
            _animator = inGameView.GetComponent <GameAnimator>() ??
                        throw new Exception($"GameView [{inGameView.name}] must attached GameAnimator component.");

            _collider = inGameView.GetComponent <HitBox>() ??
                        throw new Exception($"GameView [{inGameView.name}] must attached GameCollider component.");

            _view = inGameView as EnemyView ?? throw new Exception($"NpcController can only attached to EnemyView");

            _lastAction    = ActorActions.None;
            _currentAction = ActorActions.None;
            _facing        = inFacing;
            _directionX    = GetIntDirection();
            _view.SetDirectionX(_directionX);

            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect player
            // --------------------------------------------------------------------------------
            var rayLength = (_view.GetSize().x / 2) + _view.Profile.sightDistance;

            _sightRay                 = gameView.AddComponent(new RaySensor(gameView, GetDirection(), rayLength, true));
            _sightRay.onHitEvent     += inO => { hasEnemy = true; };
            _sightRay.onHitLostEvent += () => { hasEnemy = false; };
            _sightRay.SetOffset(new Vector2(0, (_view.GetSize().y - 7)));  //set the origin ray as middle center

            SystemFacade.NPC.AddComponent(this);
        }
예제 #2
0
        public override void Setup(Character character)
        {
            this.rb     = character.GetComponent <Rigidbody>();
            this.cd     = character.GetComponent <CapsuleCollider>();
            this.sensor = new RaySensor(this.transform, this.cd);

            this.ConfigureCollider();
            this.ConfigureRigidBody();
            this.ConfigureSensor();
        }
예제 #3
0
        public ControlView(GameView inGameView, PlayerProfile inProfile) : base(inGameView)
        {
            // --------------------------------------------------------------------------------
            // Initializing
            // --------------------------------------------------------------------------------
            _collider = inGameView.GetComponent <HitBox>() ??
                        throw new NullReferenceException($"Missing Component HitBox");

            _animator = inGameView.GetComponent <GameAnimator>() ??
                        throw new NullReferenceException($"Missing Component GameAnimator");

            _view = inGameView as PlayerView ?? throw new Exception($"ControlView must be attached on PlayerView");

            _facing        = ActorFacing.Right;
            _directionX    = 1;
            profile        = inProfile;
            _lastAction    = ActorActions.None;
            _currentAction = ActorActions.None;
            _isQuickMove   = false;
            _jumpRequest   = false;

            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect is level collider
            // --------------------------------------------------------------------------------
            var rayChild  = _view.CreateChild("CollisionRay");
            var rayLength = (_view.GetSize().x / 2) + profile.colliderBlockDistance;

            _levelColliderSensor                 = rayChild.AddComponent(new RaySensor(rayChild, GetDirection(), rayLength, true));
            _levelColliderSensor.onHitEvent     += inO => { _isBlocked = true; };
            _levelColliderSensor.onHitLostEvent += () => { _isBlocked = false; };
            _levelColliderSensor.SetOffset(new Vector2(0, (_view.GetSize().y / 2))); //set the origin ray as middle center
            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect is grounded
            // --------------------------------------------------------------------------------
            var rayGround = gameView.AddComponent(new RaySensor(gameView, Vector2.down, 5f, true));

            rayGround.onHitEvent     += inO => { _playerInTheAir = false; };
            rayGround.onHitLostEvent += () => { _playerInTheAir = true; };
        }
예제 #4
0
 void Start()
 {
     raySensor = GetComponent <RaySensor>();
     raySensor.SensorUpdateMode = RaySensor.UpdateMode.Manual;
     age = 0;
 }