コード例 #1
0
 private void OnTriggerEnter2D(Collider2D otherCollider)
 {
     if (triggerCondition == TriggerCondition.Enter && checkCondition(otherCollider) == true)
     {
         triggered.Invoke();
         foreach (CrossSceneEventSO crossSceneEventSO in actionsOnTrigger)
         {
             crossSceneEventSO.Event.Invoke();
         }
     }
 }
コード例 #2
0
    //take damage function
    public void TakeDamage(int amount)
    {
        if (invincibility >= invincibilityTime)
        {
            if (DamagedEventSO != null)
            {
                DamagedEventSO.Event?.Invoke();
            }

            DamagedEvent?.Invoke();

            health -= amount;

            invincibility = 0;

            hpUpdated.Invoke(health);
            if (health <= 0)
            {
                CommitSuduku();
            }
            else
            {
                if (flashCustomColor)
                {
                    StartCoroutine(ChangeColor());
                }
            }
        }
    }
コード例 #3
0
    public void CommitSuduku()
    {
        if (DiedEventSO != null)
        {
            DiedEventSO.Event.Invoke();
        }

        DiedEvent.Invoke();

        if (gameObject.layer == 11 && onDeathReplaceWith == null)
        {
            Enemy_Logic tmp = GetComponent <Enemy_Logic>();
            if (tmp != null)
            {
                tmp.enabled = false;
            }

            gameObject.layer = 12;
            Animator tempAnimator = GetComponent <Animator>();
            if (tempAnimator != null)
            {
                tempAnimator.SetBool("isSaved", true);
            }

            if (disableColliderOnDeath)
            {
                GetComponent <Collider2D>().enabled = false;
            }
        }
        else if (onDeathReplaceWith != null)
        {
            Instantiate(onDeathReplaceWith, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }
コード例 #4
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (target == null || target == collision)
     {
         OnTriggerStay2DEvent.Invoke();
     }
 }
コード例 #5
0
 public void Update()
 {
     _currentTime += Time.deltaTime;
     if (_currentTime >= TimeSec)
     {
         DelayEvent?.Invoke();
         enabled = false;
     }
 }
コード例 #6
0
    /// <summary>
    /// 加载关卡
    /// </summary>
    /// <param name="index"></param>
    public void LoadLevel(int index)
    {
        for (int i = 0; i < this.levels.Length; i++)
        {
            var l = levels[i];
            l.events.SetActive(i == index);
            l.objects.SetActive(i == index);
        }

        flags.Clear();
        Inventory.Instance.Clear();
        OnChange?.Invoke();
    }
コード例 #7
0
    /// <summary>
    /// 当游戏成功时
    /// </summary>
    protected void OnSuccessGame()
    {
        if (!_success)
        {
            //防止重复添加
            _success = true;
            for (int i = 0; i < SuccessTags.Count; i++)
            {
                Stage.Instance.AddFlag(SuccessTags[i]);
            }
            for (int i = 0; i < SuccessItems.Count; i++)
            {
                Inventory.Instance.AddItem(SuccessItems[i]);
            }

            SuccessEvent?.Invoke();
        }
    }
コード例 #8
0
    IEnumerator AttackSequence()
    {
        bool attacking = true;
        float timer = 0;
        int attacksInCurrentSequence = 0;

        while (attacking)
        {
            timer = Mathf.Min(aditionalWindupDelay, timer + Time.deltaTime);
            if (timer == aditionalWindupDelay)
                attacking = false;
            yield return null;
        }

        attacking = true;
        timer = 0;
        while (attacking)
        {
            yield return null;
            timer = Mathf.Min(attackDelay, timer + Time.deltaTime);
            if (timer == attackDelay && attacking)
            {
                timer = 0;

                if (attacksInCurrentSequence < weakAttackCount)
                {
                    weakAttack.Invoke();
                    attacksInCurrentSequence++;
                }
                else
                {
                    strongAttack.Invoke();
                    attacksInCurrentSequence = 0;
                    NextPhase();
                    attacking = false;
                }
            }
        }

        animator.SetBool("Attack", false);
        if(willTakeHit)
            animator.SetInteger("HP", animator.GetInteger("HP") - 1);
        willTakeHit = false;
    }
コード例 #9
0
    public void DoTriggerEffect(ClickableItem item)
    {
        switch (triggerType)
        {
        case TriggerType.PickUp:
            //拾取
            Inventory.Instance.AddItem(item);
            break;

        case TriggerType.Dialog:
            //对话
            switch (triggerTarget)
            {
            case "对话.一幅彩色的画":
                item.girlBalloon?.ShowMessage("一幅彩色的画");
                break;
            }

            if (!string.IsNullOrEmpty(flag))
            {
                Stage.Instance.AddFlag(flag);
            }

            break;

        case TriggerType.Open:
            //打开游戏
            CloseUpView.Instance.OpenMiniGame(triggerTarget);

            break;

        case TriggerType.None:

            if (!string.IsNullOrEmpty(flag))
            {
                Stage.Instance.AddFlag(flag);
            }

            break;
        }
        OnSuccessTrigger?.Invoke();
    }
コード例 #10
0
 void Ouch()
 {
     TakeDamage.Invoke();
 }
コード例 #11
0
 private void OnCollisionStay2D(Collision2D collision)
 {
     OnCollisionStay2DEvent.Invoke();
 }
コード例 #12
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     OnCollisionEnter2DEvent.Invoke();
 }
コード例 #13
0
    IEnumerator LoadPrompt()
    {
        bool promptUp = false;

        if (textMeshProReference != null)
        {
            textMeshProReference.text    = "";
            textMeshProReference.enabled = false;
        }
        else
        {
            Debug.LogError("text shouldn't be null in: " + this);
        }
        while (isActiveAndEnabled)
        {
            if (doPrompt == true)
            {
                if (promptUp != true)
                {
                    if (textMeshProReference != null)
                    {
                        textMeshProReference.enabled = true;
                        textMeshProReference.text    = promptMessage;
                    }
                    else
                    {
                        Debug.LogError("text shouldn't be null in: " + this);
                    }
                    promptUp = true;
                }

                if (Input.GetKeyDown(triggerKey) == true && enableInput)
                {
                    foreach (CrossSceneEventSO crossSceneEvent in CrossSceneEventsToFire)
                    {
                        crossSceneEvent.Event.Invoke();
                    }
                    activated.Invoke();
                    Trigger();
                }

                doPrompt = false;
            }
            else
            {
                if (promptUp == true)
                {
                    if (textMeshProReference != null)
                    {
                        textMeshProReference.text    = "";
                        textMeshProReference.enabled = false;
                    }
                    else
                    {
                        Debug.LogError("text shouldn't be null in: " + this);
                    }
                    promptUp = false;
                }
            }
            yield return(new WaitForFixedUpdate());
        }

        loadPromptTracker = false;
    }
コード例 #14
0
    //update loop
    private void Update()
    {
        if (movementState == CustomGCOTypes.MovementState.Enabled)
        {
            {//handle inputs
                jumpButtonPressed = Input.GetAxis("Vertical") > float.Epsilon;

                //run
                Vector2 velocity = rigidbody2D.velocity;
                velocity.x           = Input.GetAxis("Horizontal") * runSpeed;
                rigidbody2D.velocity = velocity;

                //dash
                if (Input.GetAxis("Dash") > float.Epsilon && dash == 0 && dashUsed != true && isDashing == false)
                {
                    isDashing = true;
                    StartCoroutine(Dash());
                    Dashed.Invoke();
                }

                //jump
                if (jumpButtonPressed && airbornTime < allowedAirbornTime)
                {
                    velocity             = rigidbody2D.velocity;
                    velocity.y           = jumpVelocity;
                    rigidbody2D.velocity = velocity;
                    ////non linear jump
                    //rigidbody2D.AddForce(Vector2.up * jumpVelocity);
                    Jumped.Invoke();
                }
            }

            {//update physics
                isGrounded = CheckGrounded();
                //smart gravity
                if (isGrounded != true)
                {
                    if (rigidbody2D.velocity.y < 0)
                    {
                        rigidbody2D.velocity += Vector2.up * (-9.8f) * (fallMultiplier) * Time.deltaTime;
                    }
                    else if (rigidbody2D.velocity.y > 0 && jumpButtonPressed != true)
                    {
                        rigidbody2D.velocity += Vector2.up * (-9.8f) * (lowJumpMultiplier) * Time.deltaTime;
                    }
                }

                //update dash timer
                dash     = Mathf.Max(dash - Time.deltaTime, 0);
                dashUsed = isGrounded ? false : dashUsed;

                //update airborn timer
                airbornTime = Mathf.Min(airbornTime + Time.deltaTime, allowedAirbornTime);

                //update jump constraints
                if (isGrounded)//reset the jump on the ground
                {
                    airbornTime = 0;
                }
                else if (jumpButtonPressed != true)//if we release the jump button off the ground, don't allow a resume jump
                {
                    airbornTime = allowedAirbornTime;
                }
            }
        }
        if (enableDebugging == true)//change the color while on the ground
        {
            spriteRenderer.color = isGrounded ? Color.green : Color.white;
        }
    }