//地面を離れた(移動中の勢いを保持)
        private void OnGroundContactLost()
        {
            Vector3 _currentVelocity = rb2d.velocity;

            _currentVelocity = Calc.RemoveDotVector(_currentVelocity, transform.up);

            float _length = _currentVelocity.magnitude;

            //速度方向を計算
            Vector3 _velocityDirection = Vector3.zero;

            if (System.Math.Abs(_length) > 0.001f)
            {
                _velocityDirection = _currentVelocity / _length;
            }

            //「walkSpeed」および「airControl」に基づいて「_length」から減算し、オーバーシュートを確認
            if (_length >= walkSpeed * airControl)
            {
                _length -= walkSpeed * airControl;
            }

            //momentumを更新
            momentum = _velocityDirection * _length;

            //イベント発行
            if (OnCharacterEvent != null)
            {
                OnCharacterEvent.Invoke(CharacterEventType.GroundContactLost);
            }
        }
 public void SetPosition(Vector3 pos)
 {
     Position = pos;
     if (OnChange != null)
     {
         OnChange.Invoke(this);
     }
 }
Ejemplo n.º 3
0
    IEnumerator Initialize()
    {
        while (true)
        {
            //Call after other script Update function called
            yield return(new WaitForEndOfFrame());

            if (cManager.EnemyTeam.Count != 0)
            {
                cManager.SelectedEnemy = cManager.EnemyTeam.First();

                OnSelectCharacter.Invoke(cManager.SelectedEnemy);
                yield break;
            }
        }
    }
Ejemplo n.º 4
0
    private void UpdateKeyboardInput()
    {
        var keyboard = Keyboard.current;

        if (keyboard == null)
        {
            return;
        }

        if (keyboard.rightArrowKey.isPressed && keyboard.leftArrowKey.isPressed)
        {
            IsMovingRight = false;
            IsMovingLeft  = false;
        }
        else if (keyboard.rightArrowKey.isPressed)
        {
            IsMovingRight = true;
        }
        else if (keyboard.leftArrowKey.isPressed)
        {
            IsMovingLeft = true;
        }
        else
        {
            IsMovingRight = false;
            IsMovingLeft  = false;
        }

        if (keyboard.spaceKey.wasPressedThisFrame)
        {
            OnCharacterJump?.Invoke();
        }
    }
Ejemplo n.º 5
0
 public void AddCharacter(Character character)
 {
     if (!Characters.Contains(character))
     {
         Characters.Add(character);
         OnCharacterAdded.Invoke(character);
     }
 }
Ejemplo n.º 6
0
 public void DecreaseLife(int ToDecrease)
 {
     LifeTotal -= ToDecrease;
     if (LifeTotal < 0)
     {
         Death.Invoke(this);
     }
 }
Ejemplo n.º 7
0
 //击中玩家
 public void TouchPlayer()
 {
     if (GameControl.Instance.Player.GetComponent <PlayerControl>().IsSpellLock)
     {
         return;
     }
     GameControl.Instance.Camera.GetComponent <BeHitEffect>().ShowBeHitEffect();
     target.GetComponent <PlayerControl>().BeHurt((int)Range_Angle_Damage[curentSkill].z);
     OnTouch.Invoke(gameObject);
 }
    //This takes in a path and moves the unit along that path


    //Event handler functions
    //void OnMouseDown()
    //{
    //    clicked.Invoke(this);
    //}
    public void OnPointerClick(PointerEventData eventData)
    {
        //
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            //Debug.Log("Clicked " + name);
            clicked.Invoke(this);
        }
        //Debug.Log("Character");
    }
Ejemplo n.º 9
0
 protected void OnDie()
 {
     GetComponent <CharacterController>().enabled    = false;
     GetComponent <CharacterContrMovement>().enabled = false;
     GetComponent <Collider>().enabled = false;
     Armament.enabled = false;
     enabled          = false;
     die?.Invoke(this);
     FormationsManager.instance.DieUnit(this);
     Destroy(gameObject);
 }
Ejemplo n.º 10
0
    private void DeadAnimation()
    {
        agent.Stop();
        myAnimator.Play("death");
        transform.FindChild("Canvas").gameObject.SetActive(false);
        OnDie.Invoke(gameObject);

        transform.GetComponent <CapsuleCollider>().enabled = false;
        if (GameControl.Instance.Player.GetComponent <PlayerControl>().IsSpellLock == true)
        {
            GameControl.Instance.Player.GetComponent <PlayerControl>().BeginAttack();
        }
    }
Ejemplo n.º 11
0
    public void RemoveCharacter(Character character)
    {
        if (Characters.Contains(character))
        {
            Characters.Remove(character);
            OnCharacterRemoved.Invoke(character);
        }
        else
        {
            Debug.LogError("This Character is not tracked by the manager returning in to the pool to prevent possible bugs.");
        }

        //CheckGameCharacterState(character);
    }
 // Sets the current target
 public void SetTarget(Character target)
 {
     myTarget = target;
     Debug.LogFormat("Target is {0}", myTarget.Name);
     if (ActiveSkill != null)
     {
         // TODO: This is terrible. Should probably make this syntax better
         ActiveSkill.CharacterTargets.Clear();
         ActiveSkill.CharacterTargets.Add(target);
     }
     // TODO: This event is a little weird, passing in character since it has a Target.
     //       Might expect this to be the target character...
     //       thought about args with Character, Character, but eh...
     OnTargetSelected.Invoke(this);
 }
Ejemplo n.º 13
0
 public void NextTurn()
 {
     if (CurrentCharacter != null)
     {
         OnTurnEnd.Invoke(CurrentCharacter);
         if (CurrentCharacter == lastCharacter)
         {
             NextRound();
         }
     }
     if (gameOver)
     {
         return;
     }
     // Peel off the next character
     CurrentCharacter = TurnOrder.Dequeue();
     // Remove dead characters from turn queue
     while (CurrentCharacter.isDead)
     {
         if (CurrentCharacter == lastCharacter)
         {
             NextRound();
         }
         // Skip turn if they are dead
         TurnOrder.Enqueue(CurrentCharacter);
         CurrentCharacter = TurnOrder.Dequeue();
     }
     // Queue them back into the turn order
     TurnOrder.Enqueue(CurrentCharacter);
     // Tick down skill's cooldowns
     foreach (Skill sk in CurrentCharacter.Skills)
     {
         sk.ChangeCooldown(-1);
     }
     // If someone is knocked down skip their turn
     // TODO: This seems misplaced... Not sure where it should go yet.
     if (CurrentCharacter.isKnockedDown == true)
     {
         CurrentCharacter.SetKnockdown(false);
         CurrentCharacter.SetGettingUp(true);
         NextTurn();
         // if you don't return out it does some funny stuff like skip people's turns
         return;
     }
     // Tell everyone it's the next turn
     OnTurnStart.Invoke(CurrentCharacter);
     CurrentCharacter.OnActionEnd.AddListener(characterFinished);
 }
Ejemplo n.º 14
0
    /// <summary>
    /// Spawns specific character and notify subscribers about it.
    /// </summary>
    public void Spawn()
    {
        var character = CreateCharacterController();

        // setup
        character.Health = StateInfo.Health;
        character.Damage = StateInfo.Damage;
        character.Force  = StateInfo.Force;
        character.Speed  = StateInfo.Speed;

        // Inject dependencies
        character.Animator = character.Transform.GetComponent <Animator>();

        // notify subscribers that character is created
        OnSpawn.Invoke(character);
    }
 public void attackButtonClicked()
 {
     if (!hasAttacked && currentStamina >= character.attackStaminaCost)
     {
         if (inventory.equippedWeapon.weaponType == Item.WEAPON.SPIRIT)
         {
             DisplayRange(true, true, true);
         }
         else
         {
             DisplayRange(true, true, false);
         }
         //Debug.Log(selectableTiles.Count);
         turnOffPanel();
         unitAttacking.Invoke(this);
     }
 }
Ejemplo n.º 16
0
    void OnTriggerEnter2D(Collider2D other)
    {
        switch (other.tag)
        {
        case "PointObject":
            if (OnScoreChange != null)
            {
                OnScoreChange.Invoke(1);     //When create a point object script add variable for point value
                Manager <SoundManager> .Instance.PlaySoundEffect(SoundManager.SoundEffect.Pickup);
            }
            Destroy(other.gameObject);     //When create a point object script create destroy object function to call
            break;

        case "EndLevel":
            if (OnLevelEnd != null)
            {
                OnLevelEnd.Invoke();
                Manager <SoundManager> .Instance.PlaySoundEffect(SoundManager.SoundEffect.EndLevel);
            }
            break;

        case "DestroyPlayer":
            if (OnPlayerDestroyed != null)
            {
                OnPlayerDestroyed.Invoke();
                Manager <InputManager> .Instance.OnCharacterRelease -= ReleaseCharacter;
                Manager <InputManager> .Instance.OnMoveLeft         -= MoveLeft;
                Manager <InputManager> .Instance.OnMoveRight        -= MoveRight;
                Manager <InputManager> .Instance.OnJump             -= Jump;
                Destroy(this.gameObject);
            }
            break;

        default:
            break;
        }
    }
Ejemplo n.º 17
0
 private void FlyAnimation()
 {
     myAnimator.SetBool("fly", true);
     OnTrace.Invoke(gameObject);
 }
Ejemplo n.º 18
0
 private void IdleAnimation()
 {
     myAnimator.SetBool("fly", false);
     myAnimator.SetBool("walk", false);
     OnIdle.Invoke(gameObject);
 }
Ejemplo n.º 19
0
 //攻击结束(帧函数)
 public void EndAttack()
 {
     OnEngAttack.Invoke(gameObject);
 }
Ejemplo n.º 20
0
 //攻击开始(帧函数)
 public void BeginAttack()
 {
     OnBeginAttack.Invoke(gameObject);
 }
Ejemplo n.º 21
0
 public void RemoveCharacter(Character c)
 {
     characters.Remove(c);
     OnCharacterRemoved.Invoke(c);
 }
Ejemplo n.º 22
0
 private void IdleAnimation()
 {
     myAnimator.SetBool("run", false);
     OnIdle.Invoke(gameObject);
     agent.Stop();
 }
 public void openItemMenu()
 {
     openInventory.Invoke(this);
     turnOffPanel();
 }
 public void passActive() //called when action panel pass button is clicked, removes unit from active list without taking any more actions
 {
     passTurn.Invoke(this);
 }
Ejemplo n.º 25
0
 protected void Start()
 {
     EventStart.Invoke(this);
     health?.EventDie.AddListener(OnDie);
     Command = new GuardCommand(this);
 }
Ejemplo n.º 26
0
 private void DeadAnimation()
 {
     myAnimator.SetTrigger("death");
     IsDeath = true;
     OnDie.Invoke(gameObject);
 }
 public void ConfirmSelection(Character character)
 {
     //ver como faz se for tocar animação no selector
     gameObject.SetActive(false);
     CharactedSelected.Invoke(character);
 }
Ejemplo n.º 28
0
 public void AddCharacter(Character c)
 {
     characters.Add(c);
     OnCharacterAdded.Invoke(c);
 }
        /// <summary>
        /// Shows remains letters dynamically
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private IEnumerator ShowRemainingCharacters()
        {
            if (!textAnimator.allLettersShown)
            {
                isInsideRoutine = true;
                wantsToSkip     = false;

                onTypewriterStart?.Invoke();

                IEnumerator WaitTime(float time)
                {
                    if (time > 0)
                    {
                        float t = 0;
                        while (t <= time)
                        {
                            t += textAnimator.time.deltaTime;
                            yield return(null);
                        }
                    }
                }

                float timeToWait;
                char  characterShown;

                if (resetTypingSpeedAtStartup)
                {
                    typewriterPlayerSpeed = 1;
                }

                float typewriterTagsSpeed = 1;

                bool HasSkipped()
                {
                    return(canSkipTypewriter && wantsToSkip);
                }

                float timePassed = 0;

                float deltaTime;
                UpdateDeltaTime();

                void UpdateDeltaTime()
                {
                    deltaTime = textAnimator.time.deltaTime * typewriterPlayerSpeed * typewriterTagsSpeed;
                }

                //Shows character by character until all are shown
                while (!textAnimator.allLettersShown)
                {
                    //searches for actions [before the character, incl. at the very start of the text]
                    if (textAnimator.hasActions)
                    {
                        //loops until features ended (there could be multiple ones in the same text position, example: when two tags are next to eachother without spaces
                        while (textAnimator.TryGetAction(out TypewriterAction action))
                        {
                            //Default features
                            switch (action.actionID)
                            {
                            case "waitfor":
                                float waitTime;
                                FormatUtils.TryGetFloat(action.parameters, 0, 1f, out waitTime);
                                yield return(WaitTime(waitTime));

                                break;

                            case "waitinput":
                                yield return(WaitInput());

                                break;

                            case "speed":
                                FormatUtils.TryGetFloat(action.parameters, 0, 1, out typewriterTagsSpeed);

                                //clamps speed (time cannot go backwards!)
                                if (typewriterTagsSpeed <= 0)
                                {
                                    typewriterTagsSpeed = 0.001f;
                                }

                                break;

                            //Action is custom
                            default:
                                yield return(DoCustomAction(action));

                                break;
                            }
                        }
                    }


                    //increases the visible chars count and stores the new one
                    characterShown = textAnimator.IncreaseVisibleChars();
                    UpdateDeltaTime();

                    //triggers event unless it's a space
                    if (characterShown != ' ')
                    {
                        onCharacterVisible?.Invoke(characterShown);
                    }

                    //gets the time to wait based on the newly character showed
                    timeToWait = WaitTimeOf(characterShown);

                    //waiting less time than a frame, we don't wait yet
                    if (timeToWait < deltaTime)
                    {
                        timePassed += timeToWait;

                        if (timePassed >= deltaTime) //waits only if we "surpassed" a frame duration
                        {
                            yield return(null);

                            timePassed %= deltaTime;
                        }
                    }
                    else
                    {
                        while (timePassed < timeToWait && !HasSkipped())
                        {
                            OnTypewriterCharDelay();
                            timePassed += deltaTime;
                            yield return(null);

                            UpdateDeltaTime();
                        }

                        timePassed %= timeToWait;
                    }

                    //Skips typewriter
                    if (HasSkipped())
                    {
                        textAnimator.ShowAllCharacters(hideAppearancesOnSkip);

                        if (triggerEventsOnSkip)
                        {
                            textAnimator.TriggerRemainingEvents();
                        }

                        break;
                    }
                }

                // triggers the events at the end of the text
                //
                // the typewriter is arrived here without skipping
                // meaning that all events were triggered and we only
                // have to fire the ones at the very end
                // (outside tmpro's characters count length)
                if (!canSkipTypewriter || !wantsToSkip)
                {
                    textAnimator.TriggerRemainingEvents();
                }

                isInsideRoutine = false;

                textToShow = string.Empty; //text has been showed, no need to store it now

                onTextShowed?.Invoke();
            }
        }
Ejemplo n.º 30
0
 private void RunAnimation()
 {
     myAnimator.SetBool("run", true);
     OnTrace.Invoke(gameObject);
 }