Ejemplo n.º 1
0
        private void Awake()
        {
            if (!_registeredToLevelLoadedEvent)
            {
                _registeredToLevelLoadedEvent = true;
                App.OnLevelLoaded            += OnLevelLoaded;
            }

            Position = transform.position;
            Platform = Positional.GetPlatform(Position);
            Debug.Assert(Platform != null);

            Neighbours.RemoveAll(x => x == null);

            //Don't add orphans to the graph
            if (Neighbours.Count > 0)
            {
                Debug.Assert(!AllNodes.Contains(this));
                AllNodes.Add(this);
            }

#if UNITY_EDITOR && DRAW_DEBUG
            _debugDrawer = FindObjectOfType <LineDrawer>();

            if (_debugDrawer == null)
            {
                LineDrawer.OnDrawerAwake += OnDrawerAwake;
            }

            GenerateDebugGraph();
#endif //UNITY_EDITOR && DRAW_DEBUG
        }
Ejemplo n.º 2
0
        public override void OnEnable()
        {
            base.OnEnable();

            _currentPlatform = Positional.GetPlatform(Config.Owner.transform, 50.0f);
            Debug.Assert(_currentPlatform != null);
            _currentTarget     = Rand.GetRandomPointOnPlatform(_currentPlatform);
            _waitTimeRemaining = Rand.Next(_idleConfig.MaxWaitDuration);
        }
Ejemplo n.º 3
0
        public override bool Update()
        {
            if (!base.Update())
            {
                return(false);
            }

            Config.Owner.CharacterYoke.Movement = _moveLeft ? Vector2.left : Vector2.right;
            Config.Owner.CharacterYoke.Jump     = _jump &&
                                                  (_moveLeft ? Config.Owner.transform.position.x - _config.JumpThreshold <= _launchPoint.x : Config.Owner.transform.position.x + _config.JumpThreshold >= _launchPoint.x) &&
                                                  Positional.GetPlatform(Config.Owner.transform) != _config.Target;

            return(true);
        }
Ejemplo n.º 4
0
        private void PushMoveState(Vector3 target, Transform targetPlatform = null)
        {
            if (targetPlatform == null)
            {
                targetPlatform = Positional.GetPlatform(target);
            }

            if (targetPlatform == Positional.GetPlatform(Config.Owner.transform))
            {
                Config.Owner.PushState(new MoveToState.MoveToConfig(target, Config.Owner));
            }
            else
            {
                Config.Owner.PushState(new TraverseState.TraverseStateConfig(Config.Owner, targetPlatform));
            }
        }
Ejemplo n.º 5
0
        public TraverseState(TraverseStateConfig config) : base(config)
        {
            _config          = config;
            _currentPlatform = Positional.GetPlatform(Config.Owner.transform, 50.0f);
            if (_currentPlatform != null)
            {
                BoxCollider2D currentPlatformCollider = _currentPlatform.GetComponent <BoxCollider2D>();
                Bounds        currentPlatformBounds   = currentPlatformCollider.bounds;

                //Jump if the target is higher, or there's a gap between the platforms
                _jump = currentPlatformBounds.max.y <= _config.TargetBounds.max.y ||
                        currentPlatformBounds.max.x + 1.0f <= _config.TargetBounds.min.x ||
                        currentPlatformBounds.min.x - 1.0f >= _config.TargetBounds.max.x;

                //If the target is on the left
                if (_config.TargetBounds.max.x <= currentPlatformBounds.center.x)
                {
                    _moveLeft = true;

                    //If the targets rhs overlaps
                    if (_config.TargetBounds.max.x >= currentPlatformBounds.min.x && _config.TargetBounds.max.y > currentPlatformBounds.max.y)
                    {
                        _launchPoint = _config.TargetBounds.max;
                    }
                    else
                    {
                        _launchPoint = currentPlatformBounds.min;
                    }
                }
                else if (_config.TargetBounds.min.x >= currentPlatformBounds.center.x)
                {
                    _moveLeft = false;

                    //if the targets lhs overlaps
                    if (_config.TargetBounds.min.x <= currentPlatformBounds.max.x && _config.TargetBounds.max.y > currentPlatformBounds.max.y)
                    {
                        _launchPoint = _config.TargetBounds.min;
                    }
                    else
                    {
                        _launchPoint = currentPlatformBounds.max;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override bool Update()
        {
            if (!base.Update())
            {
                return(false);
            }

            Transform platform = Positional.GetPlatform(_config.Target, 5.0f);

            if (platform != Positional.GetPlatform(Config.Owner.transform))
            {
                PushMoveState(_config.Target, platform);
                return(true);
            }

            //This is for when the last node in the path isn't actually the target
            //but we still want to move towards it
            MoveToState.MoveTowards(Config.Owner, _config.Target);
            return(true);
        }
Ejemplo n.º 7
0
 protected override bool IsValid()
 {
     return(_currentPlatform != null && Positional.GetPlatform(Config.Owner.transform) != _config.Target);            //Distance being small means that we're also implicitly checking that we're grounded
 }