Ejemplo n.º 1
0
    /// <summary>
    /// 쓰레기를 수거합니다.
    /// </summary>
    /// <param name="gameObject">수거할 쓰레기의 게임 오브젝트</param>
    public FloatingTimer CollectTrash(GameObject gameObject, float collectingTime = 5, Action <FloatingTimer> timeoutCallback = null)
    {
        var scrap = gameObject.GetComponent <Scrap>();
        // 이 스크립트에서 관리중인 오브젝트인지 체크
        bool isTrash = false;

        for (int i = 0; i < 5; i++)
        {
            if (trash[i] == gameObject)
            {
                // 관리중인 오브젝트에서 빼버림
                trash[i] = null;
                isTrash  = true;
                break;
            }
        }

        if (isTrash)
        {
            scrap.IsCollecting = true;
            // 타이머 표시
            //if (timeoutCallback == null)
            //{
            //    timeoutCallback = (timer) =>
            //    {
            //        if (gameObject != null)
            //            Destroy(gameObject);
            //        timer.FadeoutWithDestory();
            //    };
            //}
            timeoutCallback += (timer) =>
            {
                if (gameObject != null)
                {
                    Destroy(gameObject);
                }
                timer.FadeoutWithDestory();
            };
            return(FloatingTimer.Create(gameObject.transform, new Vector3(0f, -0.1f, 0), collectingTime, timeoutCallback));
        }
        else
        {
            UnityEngine.Debug.LogWarning($"{gameObject}는 DropItem 스크립트에서 관리되는 쓰레기 오브젝트가 아닙니다.");
        }

        return(null);
    }
Ejemplo n.º 2
0
    void Buy()
    {
        //Debug.Log("Buy");
        // 캐릭터 상호작용

        //TODO:'FindObjectOfType<CashierAi>()'대신에 매니저 클래스를 이용하여 최적화 필요함.
        var cashierAI = FindObjectOfType <CashierAi>();

        // 계산원이 없으면 무한 대기
        if (cashierAI == null)
        {
            return;
        }

        state = AiState.Buying;

        // 알바가 있으면
        if (cashierAI.IsEmployee)
        {
            cashierAI.ItemDeal(this, ItemDealCallback);
        }
        // 없으면
        else
        {
            // 유저 상호작용 요청
            FloatingButton.Create(cashierAI.transform, new Vector3(0.2f, 0), null, (button) =>
            {
                Destroy(button.gameObject);

                var timer = FloatingTimer.Create(cashierAI.transform, new Vector3(0.2f, 0), 10, (floatingTimer) =>
                {
                    floatingTimer.FadeoutWithDestory();

                    if (WishItems.Count > 0)
                    {
                        PlayData.CurrentData.Money += WishItems[0].GetData().SellPrice;
                        PlayData.CurrentData.DailyStatisticsData.SellMoney += WishItems[0].GetData().SellPrice;
                    }
                    PlayData.CurrentData.Awareness += 1;

                    ItemDealCallback();
                    // 직접 판매 퀘스트 트리거
                    ProjectTrader.QuestManager.Trigger(ProjectTrader.Datas.QuestData.GoalType.SelfDeal, 1);
                });
                //timer.boostRatio = 2;
            });
        }

        void ItemDealCallback()
        {
            // 상호작용이 끝나면
            // 가격 처리
            int price = 0;

            FindObjectOfType <SoundControl>().PaySound();

            //PlayData.CurrentData.Awareness += 1; //아이템 코드에 따라 다르게
            //FindObjectOfType<Uiup>().Upawareness(1);

            foreach (var item in WishItems)
            {
                price += item.GetData().SellPrice *item.Count;
                FindObjectOfType <Uiup>().Upmoney(price);

                PlayData.CurrentData.Awareness += (int)item.GetData().Awareness - 1; //아이템 코드에 따라 다르게
                FindObjectOfType <Uiup>().Upawareness((int)item.GetData().Awareness);
            }

            // 아이템 판매 퀘스트 트리거
            ProjectTrader.QuestManager.Trigger(QuestData.GoalType.SellItem, 1);

            // 구매할 아이템 초기화
            WishItems.Clear();

            state = AiState.Buyed;
        }
    }