コード例 #1
0
 private void Pickup(InputActionEventData data)
 {
     if (m_canPickup && m_status.CanAct && m_objectStack.Count < m_status.MaxCarry)
     {
         Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, m_status.PickupRange, m_status.ItemMask);
         if (hits.Length > 0)
         {
             float            lastDist = 1000;
             ObjectController obj      = null;
             foreach (Collider2D hit in hits)
             {
                 float dist = Vector2.Distance(transform.position, hit.transform.position);
                 if (dist < lastDist)
                 {
                     obj      = hit.gameObject.GetComponent <ObjectController>();
                     lastDist = dist;
                 }
             }
             if (obj != null && !obj.CurrentState.Thrown && !obj.CurrentState.Held)
             {
                 if (m_pickup != null)
                 {
                     StopCoroutine(m_pickup);
                 }
                 m_lastPickupTime = Time.time;
                 m_canPickup      = false;
                 m_anim.SetTrigger(AnimationConst.Pickup);
                 m_pickup = StartCoroutine(PickupObject(obj));
                 GameController.Instance.CurrentState.ItemsTouched++;
             }
         }
     }
 }
コード例 #2
0
        private IEnumerator PickupObject(ObjectController obj)
        {
            m_status.SetCanAct(false);
            obj.PickedUp();
            RuntimeManager.PlayOneShot(m_pickupSound);
            m_objectStack.Enqueue(obj);
            Vector2 p0 = (Vector2)obj.transform.position;
            Vector2 p1 = (Vector2)obj.transform.position + new Vector2(0, m_stackHeight + m_pickupOffset);
            Vector2 p2 = StackOrigin + new Vector2(0, m_stackHeight);
            float   t;
            Vector2 position;
            int     currentPoint = 0;

            while (currentPoint < StackCurveSamples)
            {
                t        = currentPoint / (StackCurveSamples - 1.0f);
                position = (1.0f - t) * (1.0f - t) * p0 + 2.0f * (1.0f - t) * t * p1 + t * t * p2;
                float speed = m_status.PickupSpeed * Time.deltaTime;
                obj.transform.position = Vector2.MoveTowards(obj.transform.position, position, speed);
                if (Vector2.Distance(obj.transform.position, position) <= .05f)
                {
                    currentPoint++;
                }
                yield return(null);
            }
            obj.transform.SetParent(m_stackContainer);
            obj.transform.position = p2;
            m_stackHeight         += obj.ObjectHeight;
            m_anim.SetBool(AnimationConst.Carry, true);
            m_status.SetCanAct(true);
        }
コード例 #3
0
        private void CheckNearbyItems()
        {
            float playerDist = Vector2.Distance(transform.position, m_player.transform.position);

            if (m_hasRequest)
            {
                m_requestContainer.SetActive(playerDist <= m_requestDist);
            }
            ObjectController obj = Physics2D.OverlapCircle(transform.position, m_openDist, m_itemLayer)?.GetComponent <ObjectController>();

            if ((playerDist <= m_openDist && m_player.GetComponent <HeldObjectManager>().HasItem) ||
                (obj != null && obj.CurrentState.Thrown))
            {
                if (!m_hasOpened)
                {
                    m_anim.SetBool(AnimationConst.Open, true);
                    m_hasOpened = true;
                }
                m_lastOpenTime = Time.time;
            }
            else
            {
                if (m_hasOpened)
                {
                    if (Time.time > m_lastOpenTime + m_closeDelay)
                    {
                        m_anim.SetBool(AnimationConst.Open, false);
                        m_hasOpened = false;
                    }
                }
            }
        }
コード例 #4
0
 public void ScatterStack()
 {
     if (m_pickup != null)
     {
         StopCoroutine(m_pickup);
     }
     while (m_objectStack.Count > 0)
     {
         ObjectController obj = m_objectStack.Dequeue();
         obj.transform.DOComplete();
         Vector2 dir = Random.insideUnitCircle.normalized;
         obj.Drop(obj.transform.position, dir * m_scatterStrength);
     }
     m_stackHeight = 0;
     m_anim.SetBool(AnimationConst.Carry, false);
 }
コード例 #5
0
        public void Feed(ObjectController obj)
        {
            GameController.Instance.IncreaseSustinence(obj.SustinenceProvided);
            if (obj.Id == m_request)
            {
                GameController.Instance.IncreaseHappiness(obj.HappinessProvided);
            }
            if (m_checkRequest != null)
            {
                StopCoroutine(m_checkRequest);
            }
            m_anim.SetTrigger(AnimationConst.Chomp);
            bool success = obj.Id == m_request;

            if (success)
            {
                m_remainingItems--;
            }
            m_checkRequest = StartCoroutine(CheckRequest(success));
            GameController.Instance.CurrentState.ItemsEaten++;
            Destroy(obj.gameObject);
        }
コード例 #6
0
        private void Throw(InputActionEventData data)
        {
            if (m_status.CanAct && m_canThrow && m_objectStack.Count > 0)
            {
                RuntimeManager.PlayOneShot(m_throwSound);
                m_anim.SetTrigger(AnimationConst.Throw);
                ObjectController obj = m_objectStack.Dequeue();
                obj.transform.DOComplete();

                Vector2      throwDir = m_status.FacingDir * m_status.ThrowForce;
                RaycastHit2D hit      = Physics2D.Raycast(transform.position, m_status.FacingDir, Mathf.Infinity, m_throwTargetLayer);
                if (hit.collider != null)
                {
                    throwDir = ((Vector2)hit.transform.position - (Vector2)obj.transform.position).normalized * m_status.ThrowForce;
                }

                obj.Throw(obj.transform.position, throwDir);
                ReorganizeStack();
                m_lastThrowTime = Time.time;
                m_canThrow      = false;
            }
            m_anim.SetBool(AnimationConst.Carry, m_objectStack.Count > 0);
        }