예제 #1
0
        /// <summary>
        /// Triggered when a TopDownController touches the platform
        /// </summary>
        /// <param name="controller">The TopDown controller that collides with the platform.</param>
        public virtual void OnTriggerStay(Collider collider)
        {
            TopDownController controller = collider.gameObject.MMGetComponentNoAlloc <TopDownController>();

            if (controller == null)
            {
                return;
            }

            if (State == FallingPlatformStates.Falling)
            {
                return;
            }

            if (TimeBeforeFall > 0)
            {
                _platformTopY = (_collider != null) ? _collider.bounds.max.y : this.transform.position.y;

                if (controller.ColliderBottom.y >= _platformTopY)
                {
                    _contact = true;
                    State    = FallingPlatformStates.Shaking;
                }
            }
            else
            {
                if (!InevitableFall)
                {
                    _contact = false;
                    State    = FallingPlatformStates.Idle;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Triggered when a TopDownController touches the platform
        /// </summary>
        /// <param name="controller">The TopDown controller that collides with the platform.</param>
        public virtual void OnTriggerStay(Collider collider)
        {
            TopDownController controller = collider.gameObject.MMGetComponentNoAlloc <TopDownController>();

            if (controller == null)
            {
                return;
            }

            if (State == FallingPlatformStates.Falling)
            {
                return;
            }

            if (TimeBeforeFall > 0)
            {
                _contact = true;
                State    = FallingPlatformStates.Shaking;
            }
            else
            {
                if (!InevitableFall)
                {
                    _contact = false;
                    State    = FallingPlatformStates.Idle;
                }
            }
        }
예제 #3
0
 /// <summary>
 /// On Awake we grab our components
 /// </summary>
 protected virtual void Awake()
 {
     AgentPath                = new NavMeshPath();
     _topDownController       = GetComponentInParent <TopDownController>();
     _characterMovement       = GetComponentInParent <Character>()?.FindAbility <CharacterMovement>();
     _lastValidTargetPosition = this.transform.position;
 }
 /// <summary>
 /// On init we grab our components
 /// </summary>
 protected override void Initialization()
 {
     _characterHandleWeapon = this.gameObject.GetComponent <CharacterHandleWeapon>();
     _aiActionShoot2D       = this.gameObject.GetComponent <AIActionShoot2D>();
     _aiActionShoot3D       = this.gameObject.GetComponent <AIActionShoot3D>();
     _controller            = this.gameObject.GetComponent <TopDownController>();
 }
예제 #5
0
        /// <summary>
        /// Initialization
        /// </summary>
        protected virtual void Awake()
        {
            _ignoredGameObjects = new List <GameObject>();
            _health             = GetComponent <Health>();
            _topDownController  = GetComponent <TopDownController>();
            _boxCollider2D      = GetComponent <BoxCollider2D>();
            _boxCollider        = GetComponent <BoxCollider>();
            _sphereCollider     = GetComponent <SphereCollider>();
            _circleCollider2D   = GetComponent <CircleCollider2D>();

            _gizmosColor   = Color.red;
            _gizmosColor.a = 0.25f;
            if (_boxCollider2D != null)
            {
                SetGizmoOffset(_boxCollider2D.offset);
            }
            if (_boxCollider != null)
            {
                SetGizmoOffset(_boxCollider.center);
            }
            if (_sphereCollider != null)
            {
                SetGizmoOffset(_sphereCollider.center);
            }
            if (_circleCollider2D != null)
            {
                SetGizmoOffset(_circleCollider2D.offset);
            }

            InitializeFeedbacks();
        }
예제 #6
0
        /// <summary>
        /// Sets the weapon's owner
        /// </summary>
        /// <param name="newOwner">New owner.</param>
        public virtual void SetOwner(Character newOwner, CharacterHandleWeapon handleWeapon)
        {
            Owner = newOwner;
            if (Owner != null)
            {
                CharacterHandleWeapon = handleWeapon;
                _characterMovement    = Owner.GetComponent <Character>()?.FindAbility <CharacterMovement>();
                _controller           = Owner.GetComponent <TopDownController>();

                if (CharacterHandleWeapon.AutomaticallyBindAnimator)
                {
                    if (CharacterHandleWeapon.CharacterAnimator != null)
                    {
                        _ownerAnimator = CharacterHandleWeapon.CharacterAnimator;
                    }
                    if (_ownerAnimator == null)
                    {
                        _ownerAnimator = CharacterHandleWeapon.gameObject.GetComponentInParent <Character>().CharacterAnimator;
                    }
                    if (_ownerAnimator == null)
                    {
                        _ownerAnimator = CharacterHandleWeapon.gameObject.GetComponentInParent <Animator>();
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Gets and stores input manager, camera and components
        /// </summary>
        protected virtual void Initialization()
        {
            if (this.gameObject.MMGetComponentNoAlloc <TopDownController2D>() != null)
            {
                CharacterDimension = CharacterDimensions.Type2D;
            }
            if (this.gameObject.MMGetComponentNoAlloc <TopDownController3D>() != null)
            {
                CharacterDimension = CharacterDimensions.Type3D;
            }

            // we initialize our state machines
            MovementState  = new MMStateMachine <CharacterStates.MovementStates>(gameObject, SendStateChangeEvents);
            ConditionState = new MMStateMachine <CharacterStates.CharacterConditions>(gameObject, SendStateChangeEvents);

            // we get the current input manager
            SetInputManager();
            // we get the main camera
            // we store our components for further use
            CharacterState = new CharacterStates();
            _controller    = this.gameObject.GetComponent <TopDownController> ();
            _health        = this.gameObject.GetComponent <Health> ();

            CacheAbilitiesAtInit();
            if (CharacterBrain == null)
            {
                CharacterBrain = this.gameObject.GetComponent <AIBrain>();
            }

            Orientation2D = FindAbility <CharacterOrientation2D>();
            Orientation3D = FindAbility <CharacterOrientation3D>();

            AssignAnimator();

            // instantiate camera target
            if (CameraTarget == null)
            {
                CameraTarget = new GameObject();
            }
            CameraTarget.transform.SetParent(this.transform);
            CameraTarget.transform.localPosition = Vector3.zero;
            CameraTarget.name = "CameraTarget";

            if (LinkedInputManager != null)
            {
                if (OptimizeForMobile && LinkedInputManager.IsMobile)
                {
                    if (this.gameObject.MMGetComponentNoAlloc <MMConeOfVision2D>() != null)
                    {
                        this.gameObject.MMGetComponentNoAlloc <MMConeOfVision2D>().enabled = false;
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// On start we grab our character movement component and pick a random direction
        /// </summary>
        protected override void Initialization()
        {
            _characterGridMovement = this.gameObject.GetComponentInParent <Character>()?.FindAbility <CharacterGridMovement>();
            _topDownController     = this.gameObject.GetComponentInParent <TopDownController>();
            _collider   = this.gameObject.GetComponentInParent <Collider>();
            _collider2D = this.gameObject.GetComponentInParent <Collider2D>();

            _raycastDirections2D = new[] { Vector2.right, Vector2.left, Vector2.up, Vector2.down };
            _raycastDirections3D = new[] { Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

            PickNewDirection();
        }
예제 #9
0
        /// <summary>
        /// Triggered when something collides with the button activated zone
        /// </summary>
        /// <param name="collider">Something colliding with the water.</param>
        protected virtual void TriggerEnter(GameObject collider)
        {
            if (!CheckConditions(collider))
            {
                return;
            }

            // if we can only activate this zone when grounded, we check if we have a controller and if it's not grounded,
            // we do nothing and exit
            if (CanOnlyActivateIfGrounded)
            {
                if (collider != null)
                {
                    TopDownController controller = collider.gameObject.MMGetComponentNoAlloc <TopDownController>();
                    if (controller != null)
                    {
                        if (!controller.Grounded)
                        {
                            return;
                        }
                    }
                }
            }

            // at this point the object is colliding and authorized, we add it to our list
            _collidingObjects.Add(collider.gameObject);
            if (!TestForLastObject(collider))
            {
                return;
            }

            if (ShouldUpdateState)
            {
                _characterButtonActivation = collider.gameObject.MMGetComponentNoAlloc <Character>()?.FindAbility <CharacterButtonActivation>();
                if (_characterButtonActivation != null)
                {
                    _characterButtonActivation.InButtonActivatedZone     = true;
                    _characterButtonActivation.ButtonActivatedZone       = this;
                    _characterButtonActivation.InButtonAutoActivatedZone = AutoActivation;
                }
            }

            if (AutoActivation)
            {
                _autoActivationCoroutine = StartCoroutine(TriggerButtonActionCo());
            }

            // if we're not already showing the prompt and if the zone can be activated, we show it
            if (ShowPromptWhenColliding)
            {
                ShowPrompt();
            }
        }
예제 #10
0
        /// <summary>
        /// Initialization
        /// </summary>
        protected virtual void Awake()
        {
            _ignoredGameObjects = new List <GameObject>();
            _health             = GetComponent <Health>();
            _topDownController  = GetComponent <TopDownController>();
            _boxCollider2D      = GetComponent <BoxCollider2D>();
            _boxCollider        = GetComponent <BoxCollider>();
            _sphereCollider     = GetComponent <SphereCollider>();
            _circleCollider2D   = GetComponent <CircleCollider2D>();

            _gizmosColor   = Color.red;
            _gizmosColor.a = 0.25f;

            InitializeFeedbacks();
        }
예제 #11
0
 /// <summary>
 /// Gets and stores components for further use
 /// </summary>
 protected virtual void Initialization()
 {
     BindAnimator();
     _controller         = GetComponent <TopDownController>();
     _controller2D       = GetComponent <TopDownController2D>();
     _controller3D       = GetComponent <TopDownController3D>();
     _model              = _character.CharacterModel;
     _characterMovement  = GetComponent <CharacterMovement>();
     _spriteRenderer     = GetComponent <SpriteRenderer>();
     _health             = GetComponent <Health> ();
     _inputManager       = _character.LinkedInputManager;
     _state              = _character.CharacterState;
     _movement           = _character.MovementState;
     _condition          = _character.ConditionState;
     _abilityInitialized = true;
 }
예제 #12
0
 /// <summary>
 /// On init we grab all the components we'll need
 /// </summary>
 protected override void Initialization()
 {
     _collider          = this.gameObject.GetComponent <Collider>();
     _controller        = this.gameObject.GetComponent <TopDownController>();
     _character         = this.gameObject.GetComponent <Character>();
     _characterMovement = this.gameObject.GetComponent <CharacterMovement>();
     _health            = this.gameObject.GetComponent <Health>();
     _mmPath            = this.gameObject.GetComponent <MMPath>();
     // initialize the start position
     _startPosition         = transform.position;
     _initialPosition       = this.transform.position;
     _initialDirection      = _direction;
     _initialScale          = transform.localScale;
     _currentIndex          = 0;
     _indexLastFrame        = -1;
     LastReachedPatrolPoint = this.transform.position;
 }
예제 #13
0
 /// <summary>
 /// On init we grab all the components we'll need
 /// </summary>
 protected override void Initialization()
 {
     _controller        = this.gameObject.GetComponentInParent <TopDownController>();
     _character         = this.gameObject.GetComponentInParent <Character>();
     _orientation2D     = _character?.FindAbility <CharacterOrientation2D>();
     _characterMovement = _character?.FindAbility <CharacterMovement>();
     _health            = _character?._health;
     _mmPath            = this.gameObject.GetComponentInParent <MMPath>();
     // initialize the start position
     _startPosition = transform.position;
     // initialize the direction
     _direction      = _orientation2D.IsFacingRight ? Vector2.right : Vector2.left;
     _initialScale   = transform.localScale;
     _currentIndex   = 0;
     _indexLastFrame = -1;
     _waitingDelay   = 0;
     _initialized    = true;
 }
예제 #14
0
        /// <summary>
        /// Triggered when a TopDownController exits the platform
        /// </summary>
        /// <param name="controller">The TopDown controller that collides with the platform.</param>
        protected virtual void OnTriggerExit2D(Collider2D collider)
        {
            if (InevitableFall)
            {
                return;
            }

            TopDownController controller = collider.gameObject.GetComponent <TopDownController>();

            if (controller == null)
            {
                return;
            }

            _contact = false;
            if (State == FallingPlatformStates.Shaking)
            {
                State = FallingPlatformStates.Idle;
            }
        }
예제 #15
0
        /// <summary>
        /// Describes what happens when colliding with a damageable object
        /// </summary>
        /// <param name="health">Health.</param>
        protected virtual void OnCollideWithDamageable(Health health)
        {
            // if what we're colliding with is a TopDownController, we apply a knockback force
            _colliderTopDownController = health.gameObject.MMGetComponentNoAlloc <TopDownController>();
            _colliderRigidBody         = health.gameObject.MMGetComponentNoAlloc <Rigidbody>();

            if ((_colliderTopDownController != null) && (DamageCausedKnockbackForce != Vector3.zero) && (!_colliderHealth.Invulnerable) && (!_colliderHealth.ImmuneToKnockback))
            {
                _knockbackForce.x = DamageCausedKnockbackForce.x;
                _knockbackForce.y = DamageCausedKnockbackForce.y;

                if (DamageCausedKnockbackDirection == KnockbackDirections.BasedOnSpeed)
                {
                    Vector3 totalVelocity = _colliderTopDownController.Speed + _velocity;
                    _knockbackForce = Vector3.RotateTowards(DamageCausedKnockbackForce, totalVelocity.normalized, 10f, 0f);
                }
                if (DamagedTakenKnockbackDirection == KnockbackDirections.BasedOnOwnerPosition)
                {
                    if (Owner == null)
                    {
                        Owner = this.gameObject;
                    }
                    Vector3 relativePosition = _colliderTopDownController.transform.position - Owner.transform.position;
                    _knockbackForce = Vector3.RotateTowards(DamageCausedKnockbackForce, relativePosition.normalized, 10f, 0f);
                }

                if (DamageCausedKnockbackType == KnockbackStyles.AddForce)
                {
                    _colliderTopDownController.Impact(_knockbackForce.normalized, _knockbackForce.magnitude);
                }
            }

            HitDamageableFeedback?.PlayFeedbacks(this.transform.position);

            // we apply the damage to the thing we've collided with
            _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration);
            if (DamageTakenEveryTime + DamageTakenDamageable > 0)
            {
                SelfDamage(DamageTakenEveryTime + DamageTakenDamageable);
            }
        }
 /// <summary>
 /// Grabs our health and controller
 /// </summary>
 protected virtual void Initialization()
 {
     _health     = this.gameObject.GetComponent <Health>();
     _controller = this.gameObject.GetComponent <TopDownController>();
 }
 /// <summary>
 /// On Awake we grab our components
 /// </summary>
 protected virtual void Awake()
 {
     AgentPath          = new NavMeshPath();
     _topDownController = GetComponent <TopDownController>();
     _characterMovement = GetComponent <CharacterMovement>();
 }
예제 #18
0
 /// <summary>
 /// On init we grab our TopDownController component
 /// </summary>
 public override void Initialization()
 {
     _topDownController = this.gameObject.GetComponent <TopDownController>();
 }
예제 #19
0
        /// <summary>
        /// Grabs useful components, enables damage and gets the inital color
        /// </summary>
        protected virtual void Initialization()
        {
            _character = this.gameObject.GetComponent <Character>();

            if (Model != null)
            {
                Model.SetActive(true);
            }

            if (gameObject.MMGetComponentNoAlloc <Renderer>() != null)
            {
                _renderer = GetComponent <Renderer>();
            }
            if (_character != null)
            {
                if (_character.CharacterModel != null)
                {
                    if (_character.CharacterModel.GetComponentInChildren <Renderer> () != null)
                    {
                        _renderer = _character.CharacterModel.GetComponentInChildren <Renderer> ();
                    }
                }
            }
            if (_renderer != null)
            {
                if (_renderer.material.HasProperty("_Color"))
                {
                    _initialColor = _renderer.material.color;
                }
            }

            // we grab our animator
            if (_character != null)
            {
                if (_character.CharacterAnimator != null)
                {
                    _animator = _character.CharacterAnimator;
                }
                else
                {
                    _animator = GetComponent <Animator>();
                }
            }
            else
            {
                _animator = GetComponent <Animator>();
            }

            if (_animator != null)
            {
                _animator.logWarnings = false;
            }

            _initialLayer = gameObject.layer;

            _autoRespawn         = this.gameObject.GetComponent <AutoRespawn>();
            _healthBar           = this.gameObject.GetComponent <MMHealthBar>();
            _controller          = this.gameObject.GetComponent <TopDownController>();
            _characterController = this.gameObject.GetComponent <CharacterController>();
            _collider2D          = this.gameObject.GetComponent <Collider2D>();
            _collider3D          = this.gameObject.GetComponent <Collider>();

            DamageMMFeedbacks?.Initialization(this.gameObject);
            DeathMMFeedbacks?.Initialization(this.gameObject);

            _initialPosition = transform.position;
            _initialized     = true;
            CurrentHealth    = InitialHealth;
            DamageEnabled();
            UpdateHealthBar(false);
        }
예제 #20
0
 /// <summary>
 /// On init we grab our components
 /// </summary>
 protected override void Initialization()
 {
     _characterHandleWeapon = this.gameObject.GetComponentInParent <Character>()?.FindAbility <CharacterHandleWeapon>();
     _controller            = this.gameObject.GetComponentInParent <TopDownController>();
     _coneOfVision2D        = this.gameObject.GetComponent <MMConeOfVision2D>();
 }