Esempio n. 1
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));
            }
        }
    }
Esempio n. 2
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);
        }
    }
Esempio n. 3
0
    public GameObject GetUnitPrefab(YBEnum.eUnitName name)
    {
        string strName = name.ToString();

        if (!dicUnitPrefabs.ContainsKey(strName))
        {
            Debug.LogError("잘못된 키 입니다.");
            return(null);
        }

        return(dicUnitPrefabs[strName]);
    }
Esempio n. 4
0
    public Unit CreateUnit(YBEnum.eUnitName unitName, YBEnum.eColorType colorType, Vector2 position)
    {
        // 유닛 프리펩과 모델을 가져온다.
        GameObject unitPrefab  = PrefabsManager.GetInstance().GetUnitPrefab(unitName);
        GameObject modelPrefab = PrefabsManager.GetInstance().GetModelPrefab(unitName, colorType);

        // 유닛을 생성한다.
        GameObject unitGo = Instantiate(unitPrefab, Vector3.zero, Quaternion.identity);

        // 모델을 생성한다.
        // 이름을 모델로 변경한다.
        // 트랜스폼을 조정한다.
        GameObject modelGo = Instantiate(modelPrefab);

        modelGo.name             = "Model";
        modelGo.transform.parent = unitGo.transform;

        // 유닛의 위치를 변경한다.
        unitGo.transform.position = position;

        // 유닛의 태그를 설정한다.
        unitGo.tag = colorType.ToString();

        // 유닛 정보를 초기화 한다.
        Unit unit = unitGo.GetComponent <Unit>();

        if (unit.status == null)
        {
            UnitData data = DataManager.GetInstance().GetUnitData(unitName.ToString());

            // 유닛 데이터를 복사해서 생성한다.
            unit.status = new UnitData(data);
        }

        return(unit);
    }
Esempio n. 5
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)));
                        }
                    }
                }
            }
        }
    }
Esempio n. 6
0
    public GameObject GetModelPrefab(YBEnum.eUnitName name, YBEnum.eColorType colorType)
    {
        string newName = string.Format("{0}_{1}", name.ToString(), colorType.ToString());

        return(dicModelPrefabs[newName]);
    }
Esempio n. 7
0
    public static int ParseToInt(string str)
    {
        YBEnum.eUnitName unitType = (YBEnum.eUnitName)Enum.Parse(typeof(YBEnum.eUnitName), str);

        return((int)unitType);
    }
Esempio n. 8
0
    public static YBEnum.eUnitName ParseToEnum(string str)
    {
        YBEnum.eUnitName unitType = (YBEnum.eUnitName)Enum.Parse(typeof(YBEnum.eUnitName), str);

        return(unitType);
    }