Example #1
0
        // 아래 두 함수 하나로, 실패 구현
        public void Upgrade(int upgradeIndex)
        {
            var id = upgradeIndex - 50001;

            if (IsMaxUpgraded(upgradeIndex))
            {
                Debug.Log("Level Max");
                return;
            }

            // Debug.Log("Upgrade index: " + upgradeIndex);
            var prob = SuccessRate[GetUpgradeLv(id)] / 100f;

            if (_dataController.Gold < (ulong)_dataDic.FindUpgrade(upgradeIndex).Cost[GetUpgradeLv(id)])
            {
                PopUpWindow.Alert("골드가 부족해요.");
                return;
            }

            Random.InitState((int)Time.time);
            PopUpWindow.SetSliderValue(prob);
            _dataController.Gold -= (ulong)_dataDic.FindUpgrade(upgradeIndex).Cost[GetUpgradeLv(id)];

            // 업그레이드 레벨은 0 ~ 20이고 20에선 업글 불가
            if (Random.value < prob)
            {
                Action onComplete = () => PopUpWindow.Alert("업그레이드 성공!");

                PopUpWindow.AnimateSlider(1, 0.6f, onComplete);
                LevelUp(id);

                // 관찰자들에게 이벤트 메세지 송출
                foreach (var target in _dataController.Observers)
                {
                    ExecuteEvents.Execute <IEventListener>(target, null, (x, y) => x.OnObjClick(this, id));
                }
            }
            else
            {
                Action onComplete = () => PopUpWindow.Alert("업그레이드 실패...");


                PopUpWindow.AnimateSlider(0, 0.6f, onComplete);
            }
        }
Example #2
0
        private void Initialize()
        {
            var gameObj = GameObject.Find("Alarm Window");

            if (gameObj == null)
            {
                Debug.LogWarning("Alarm object is destroyed and not able to use alert.");
                return;
            }

            if (_alertPanel == null)
            {
                _alertPanel = gameObj;
            }

            _alertText = AlertText == null?_alertPanel.GetComponentInChildren <Text>() : AlertText;

            _upgradeSlider = UpgradeSlider == null?gameObj.GetComponentInChildren <Slider>() : UpgradeSlider;

            _this            = gameObj.GetComponent <PopUpWindow>();
            _blockTouchImage =
                gameObj.transform.parent.parent.gameObject
                .GetComponent <Image>();    //UI&DialogPanel(임시)은 AlarmWindow의 할아버지
        }