Ejemplo n.º 1
0
    // Action 버튼을 클릭했을 때 호출합니다.
    public void OnClick_Action()
    {
        if (targetField != null)
        {
            WPGameCommon._WPDebug("식물엎기를 선택");
            targetFieldCtrl.ClearFieldData();
            targetFieldCtrl.SaveFieldData();
            SetActive(false);
        }
        else
        {
            WPGameCommon._WPDebug("식물심기를 선택");
            int seedIndex       = scrollView_Select.seedIndex;
            int workerIndex     = scrollView_Select.workerIndex;
            int fertilizerIndex = scrollView_Select.fertilizerIndex;

            /*
             * if(seedIndex == -1 || workerIndex == -1 || fertilizerIndex == -1)
             * {
             *  string noticeString = string.Empty;
             *  if (seedIndex == -1) noticeString += "심을 식물";
             *  if (workerIndex == -1)
             *  {
             *      if (seedIndex == -1) noticeString += ", ";
             *      noticeString += "일꾼";
             *  }
             *  if (fertilizerIndex == -1)
             *  {
             *      if (seedIndex == -1 || workerIndex == -1) noticeString += ", ";
             *      noticeString += "비료";
             *  }
             *  noticeString += "을(를) 선택하지 않았습니다!";
             *  WPUIManager_Toast.instance.MakeToast(noticeString, 3f);
             *  return;
             * }*/
            if (seedIndex == -1)
            {
                string noticeString = string.Empty;
                if (seedIndex == -1)
                {
                    noticeString += "심을 식물";
                }
                noticeString += "을(를) 선택하지 않았습니다!";
                WPUIManager_Toast.instance.MakeToast(noticeString, 3f);
                return;
            }
            // 모두 선택하였다면 새로운 객체를 생성하여 넘겨준다. targetField는 필요하지 않을수도?

            WPUserDataManager.instance.SetFertilizer(fertilizerIndex, WPUserDataManager.instance.GetFertilizer(fertilizerIndex) - 1); // 비료 수의 감소

            targetField = new WPField(seedIndex, workerIndex, fertilizerIndex);
            targetFieldCtrl.SetFieldData(targetField);
            targetFieldCtrl.SaveFieldData();

            //심을 때 Worker도 보내줌
            SendCustomizedWorker();

            SetActive(false);
        }
    }
Ejemplo n.º 2
0
 public void ClearFieldData()
 {
     if (growRoutine != null)
     {
         StopCoroutine(growRoutine);
         growRoutine = null;
     }
     SetSprite_Seed(null);
     wpField = new WPField();
 }
Ejemplo n.º 3
0
    public void SetFieldData(WPField _wpField)
    {
        if (_wpField == null)
        {
            return;
        }

        wpField = _wpField;

        if (growRoutine == null && wpField.IsPlanted)
        {
            growRoutine = GrowRoutine();
            StartCoroutine(growRoutine);
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// UI를 화면에 param 값에 따라 표시합니다.
 /// </summary>
 /// <param name="param"></param>
 public override void SetActive(bool param)
 {
     if (param)
     {
         WPVariable.timeScale_NewsUI     = 0f;
         WPVariable.timeScale_WPDateTime = 0f;
     }
     else
     {
         WPVariable.timeScale_NewsUI     = 1f;
         WPVariable.timeScale_WPDateTime = 1f;
         targetField     = null;
         targetFieldCtrl = null;
         SetText_Time("예상 시간");
         SetText_Money("예상 금액");
     }
     base.SetActive(param);
 }
Ejemplo n.º 5
0
    /////////////////////////////////////////////////////////////////////////
    // Methods

    /// <summary>
    /// InitValues
    /// 오버라이드 해서 사용.
    /// </summary>
    protected override void InitValue()
    {
        base.InitValue();

        // static data의 설정
        if (seedData == null)
        {
            seedData = WPGameDataManager.instance.GetData <WPData_Seed>(WPEnum.GameData.eSeed);
        }

        //현재 밭의 인덱스 설정
        fieldIndex = Convert.ToInt32(this.transform.name.Substring(5));

        // 무빙타입은 NONE.
        base.SetActorMoveType(WPEnum.ActorMoveType.eMoveNone);

        // Empty 상태로 시작
        base._actorState = WPEnum.ActorState.eSeed_Empty;

        graphic_Seed = transform.Find("Graphic_Seed");

        graphic_Sickness = transform.Find("Graphic_Sickness").gameObject;

        fieldKey = (WPEnum.VariableType)System.Enum.Parse(typeof(WPEnum.VariableType), "eField" + fieldIndex.ToString());

        string data = WPUserDataManager.instance.GetFieldData(1, fieldIndex);

        if (string.IsNullOrEmpty(data))
        {
            SetFieldData(new WPField());
        }
        else
        {
            SetFieldData(WPField.ParseData(data));
        }

        IsSick = wpField.isSick;

        WPDateTime.Now.OnValueChanged += OnTimeChanged;
    }
Ejemplo n.º 6
0
    public static WPField ParseData(string data)
    {
        // split String
        string[] data_1 = data.Split("(".ToCharArray(), 2);
        // simple integrity check
        if (data_1[0] != "WPField")
        {
            return(new WPField());
        }

        string[] dataString = data_1[1].Substring(0, data_1[1].Length - 1).Split(":".ToCharArray(), 5);

        WPField newField = new WPField(
            Convert.ToInt32(dataString[0]),
            Convert.ToInt32(dataString[1]),
            Convert.ToInt32(dataString[2]));

        newField.isSick   = Convert.ToBoolean(dataString[3]);
        newField.progress = Convert.ToSingle(dataString[4]);

        return(newField);
    }
Ejemplo n.º 7
0
    // 로직 구현 방식입니다.
    // 밭을 누르면 GetFieldData로 해당 밭의 WPField 클래스를 받아오려고 합니다.
    // 만약 아무것도 심지 않은 상태라면 그 밭의 WPField 클래스는 null 값입니다. (사실 IsPlanted == false 인 wpfield가 존재하지만, GetFieldData 에 인자로 넘겨주는 과정에서 null 값을 넘겨주게 됩니다.)
    // null 이라면 그 밭은 비어있고, null 이 아니라면 그 클래스를 이용해 ui를 표시합니다.
    // null이라고 해서 새로운 WPField를 바로 생성하지 않습니다. <- 중요.
    // UI에서 선택한 정보는 WPScrollView_Select에 저장됩니다. ( seedIndex, workerIndex, fertilizerIndex )
    // 새로운 WPField를 생성하는 시점은 OnClick_Plant를 클릭했을 때 입니다.
    public void GetFieldData(WPField wpField, WPFieldCtrl wpFieldCtrl)
    {
        if (wpField == null) // 이 경우 밭의 정보가 없는 것으로, 이 때 여기서 새로운 밭을 만들어 넘겨주어야 합니다.
        {
            Text text = button_Action.GetComponentInChildren <Text>();
            if (text != null)
            {
                text.text = "심기";                                      // Action 버튼의 UI 설정
            }
            ui_FieldStatus.SetActive(false);

            button_Seed.interactable = true;                            // Seed 버튼의 활성화

            SetSprite_Seed();
            scrollView_Select.SetActive(true); // scrollView UI 활성화
        }
        else                                   // 밭의 정보가 있습니다. 이 정보를 활용하여 UI로 표시합니다.
        {
            Text text = button_Action.GetComponentInChildren <Text>();
            if (text != null)
            {
                text.text = "엎기";
            }

            WPGameCommon._WPDebug("Seed Index " + wpField.seedIndex + ":" + "Worker Index " + wpField.workerIndex + ":" + "Fertilizer Index " + wpField.fertilizerIndex);

            if (wpField.seedIndex != -1)
            {
                WPData_Seed seedData = WPGameDataManager.instance.GetData <WPData_Seed>(WPEnum.GameData.eSeed)[wpField.seedIndex];

                SetText_Time(string.Format("{0:f2}% 자람", (wpField.GrowthRate * 100f)));
                instance.SetText_Money(
                    Convert.ToInt32(seedData.ComparePrice).ToString());

                string seedDataName = seedData.DataName;
                string seedDataPath = "Image/Seed/" + seedDataName;

                Sprite seedSprite = WPResourceManager.instance.GetResource <Sprite>(seedDataPath);

                SetSprite_Seed(seedSprite);
            }

            ui_FieldStatus.SetActive(true);

            if (wpField.workerIndex != -1)
            {
            }
            else
            {
                ui_FieldStatus.Worker.SetActive(false);
            }

            if (wpField.fertilizerIndex != -1)
            {
                WPData_Fertilizer fertilizerData = WPGameDataManager.instance.GetData <WPData_Fertilizer>(WPEnum.GameData.eFertilizer)[wpField.fertilizerIndex];

                string fertilizerDataName = fertilizerData.DataName;
                string fertilizerDataPath = "Image/Fertilizer/" + fertilizerDataName;

                Sprite fertilizerSprite = WPResourceManager.instance.GetResource <Sprite>(fertilizerDataPath);

                ui_FieldStatus.Fertilizer.SetActive(true);

                ui_FieldStatus.Fertilizer.SetText(fertilizerData.Name);
                ui_FieldStatus.Fertilizer.SetSprite(fertilizerSprite);
            }
            else
            {
                ui_FieldStatus.Fertilizer.SetActive(false);
            }

            button_Seed.interactable = false;

            scrollView_Select.SetActive(false);

            this.targetField = wpField;
        }
        this.targetFieldCtrl = wpFieldCtrl;
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Actor 타입에 맞게 스폰시키는 함수.
    /// 성공적으로 스폰되었다면 eTypeSuccess 을 반환.
    /// </summary>
    /// <param name="actorKey"></param>
    /// <returns></returns>
    public int SpawnActor(int actorKey)
    {
        if ((int)WPEnum.ActorKey.eActorNullWorker == actorKey)
        {
            GameObject go = Instantiate(this._pfNullWorker, this._baseObject_Worker) as GameObject;

            if (null == go)
            {
                WPGameCommon._WPDebug("Actor_Worker 스폰에 문제발생!!");
                return((int)WPEnum.rvType.eTypeFail);
            }

            /*
             *          float xPos = UnityEngine.Random.Range(-WPVariable.currentFieldSizeX / 2f, WPVariable.currentFieldSizeX / 2f);
             *          float yPos = UnityEngine.Random.Range(-WPVariable.currentFieldSizeY / 2f, WPVariable.currentFieldSizeY / 2f);
             */

            float xPos = 10000;
            float yPos = 10000;

            // 포지션 세팅, 액터키 세팅
            go.GetComponent <WPActor>().SetActorPos(xPos, yPos);
            go.GetComponent <WPActor>().SetActorKey(actorKey);

            // 리스트에 반영
            _actorList_Worker.Add(go);

            return((int)WPEnum.rvType.eTypeSuccess);
        }
        else if ((int)WPEnum.ActorKey.eActorFarmField == actorKey)
        {
            GameObject go = Instantiate(this._field, this._baseObject_Field) as GameObject;

            if (null == go || farmIndex > 3 || fieldIndex > 5)
            {
                WPGameCommon._WPDebug("Actor_Worker 스폰에 문제발생!!");
                return((int)WPEnum.rvType.eTypeFail);
            }

            float xPos = WPField.FieldPos(fieldIndex).x;
            float yPos = WPField.FieldPos(fieldIndex).y;

            // 포지션 세팅, 액터키 세팅
            go.GetComponent <WPActor>().SetActorPos(xPos, yPos);
            go.GetComponent <WPActor>().SetActorKey(actorKey);

            go.name = "Field" + farmIndex.ToString() + fieldIndex.ToString();
            fieldIndex++;

            if (fieldIndex > 5)
            {
                fieldIndex = 0;
                WPGameCommon._WPDebug(farmIndex.ToString() + "번째 농장 스폰 완료!!");
            }

            // 리스트에 반영
            _actorList_Worker.Add(go);

            return((int)WPEnum.rvType.eTypeSuccess);
        }
        else if ((int)WPEnum.ActorKey.eActorWorker == actorKey)
        {
            GameObject go = Instantiate(this._pfWorker, this._baseObject_Worker) as GameObject;

            if (null == go)
            {
                WPGameCommon._WPDebug("Actor_Worker 스폰에 문제발생!!");
                return((int)WPEnum.rvType.eTypeFail);
            }


            float xPos = UnityEngine.Random.Range(-WPVariable.currentFieldSizeX / 2f, WPVariable.currentFieldSizeX / 2f);
            float yPos = UnityEngine.Random.Range(-WPVariable.currentFieldSizeY / 2f, WPVariable.currentFieldSizeY / 2f);

            // 포지션 세팅, 액터키 세팅
            go.GetComponent <WPActor>().SetActorPos(xPos, yPos);
            go.GetComponent <WPActor>().SetActorKey(actorKey);

            // 리스트에 반영
            _actorList_Worker.Add(go);

            return((int)WPEnum.rvType.eTypeSuccess);
        }
        else
        {
            return((int)WPEnum.rvType.eTypeFail);
        }
    }