예제 #1
0
    void CreateUnit()
    {
        // 유닛 생성
        for (int i = 0; i < PlayData.listUnitInfos.Count; i++)
        {
            var info = PlayData.listUnitInfos[i];

            YBEnum.eUnitName  eUnitName = UnitName.ParseToEnum(info.unit_name);
            YBEnum.eColorType colorType = (YBEnum.eColorType)info.color;
            Vector2           pos       = new Vector2(info.x, info.y);

            Unit unit = UnitsPool.instance.CreateUnit(eUnitName, colorType, pos);
            unit.transform.parent = unitsTr;

            var trModel = unit.transform.Find("Model").transform;

            // 왼쪽이 0
            int dir = (0 - unit.transform.position.x < 0) ? 0 : 1;
            if (unit.status.name.CompareTo("Catapult") == 0)
            {
                dir = (0 - unit.transform.position.x < 0) ? 1 : 0;
            }

            trModel.rotation = Quaternion.Euler(new Vector3(0, 180 * dir, 0));

            listEnemies.Add(unit);
        }
    }
예제 #2
0
    private void Update()
    {
        bool left  = Input.GetMouseButtonDown(0);
        bool right = Input.GetMouseButtonDown(1);

        if ((left || right) && !EventSystem.current.IsPointerOverGameObject())
        {
            Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(inputRay, out hit))
            {
                YBEnum.eColorType colorType = YBEnum.eColorType.None;

                if (left)
                {
                    colorType = YBEnum.eColorType.Yellow;
                }
                if (right)
                {
                    colorType = YBEnum.eColorType.Green;
                }

                Toggle toggle = toggles.Find(t => t.isOn);
                if (toggle == null)
                {
                    return;
                }

                YBEnum.eUnitName strToEnum = UnitName.ParseToEnum(toggle.name);
                listUnit.Add(UnitsPool.instance.CreateUnit(strToEnum, colorType, hit.point));
            }
        }
    }
예제 #3
0
    IEnumerator Touch()
    {
        /* 터치가 한번 있었을 때
         * 움직이면 false;
         * 터치하나더 생기면 false;
         */
        float time = 0;

        // Vector2 oldPos = Input.GetTouch(0).position;

        while (time < 0.05f)
        {
            time += Time.deltaTime;

            //float dst = (oldPos - Input.GetTouch(0).position).magnitude;
            //if (dst > 1f)
            //{
            //    yield break;
            //}

            if (Input.touchCount == 2)
            {
                yield break;
            }

            yield return(null);
        }

        if (this.selectedUnitName != null)
        {
            // 코스트를 계산한다.
            var data     = DataManager.GetInstance().GetUnitData(selectedUnitName);
            var unitCost = data.cost;

            if (maxCost - unitCost < 0)
            {
                yield break;
            }

            else
            {
                Vector3      touchPos = mainCamera.ScreenToWorldPoint(Input.mousePosition);
                Ray2D        ray      = new Ray2D(touchPos, Vector2.zero);
                RaycastHit2D hit;

                hit = Physics2D.Raycast(ray.origin, ray.direction);

                if (hit.collider != null)
                {
                    if (hit.collider.CompareTag("YellowBase") || hit.collider.CompareTag("GreenBase"))
                    {
                        // 코스트 계산한다.
                        maxCost     -= unitCost;
                        txtCost.text = maxCost.ToString();

                        // 소환
                        YBEnum.eUnitName strToEnum = UnitName.ParseToEnum(this.selectedUnitName);

                        // 리스트에 추가한다.
                        var unit    = UnitsPool.instance.CreateUnit(strToEnum, YBEnum.eColorType.Yellow, hit.point);
                        var trModel = unit.transform.Find("Model").transform;

                        // 왼쪽이 0
                        int dir = (0 - unit.transform.position.x < 0) ? 0 : 1;
                        if (unit.status.name.CompareTo("Catapult") == 0)
                        {
                            dir = (0 - unit.transform.position.x < 0) ? 1 : 0;
                        }

                        trModel.rotation = Quaternion.Euler(new Vector3(0, 180 * dir, 0));

                        listUnit.Add(unit);

                        if (hit.collider.CompareTag("YellowBase"))
                        {
                            YellowBean.SoundManager.Instance.PlaySFX(string.Format("y_idle{0}", UnityEngine.Random.Range(0, 10)));
                        }
                        else
                        {
                            YellowBean.SoundManager.Instance.PlaySFX(string.Format("g_idle{0}", UnityEngine.Random.Range(0, 12)));
                        }
                    }
                }
            }
        }
    }