Esempio n. 1
0
    private void Awake()
    {
        //イベントシステムオブジェクトにアタッチされたスクリプトを取得
        eventSystemObject = GameObject.FindWithTag("EventSystem");
        GrowPlant      growPlant      = eventSystemObject.GetComponent <GrowPlant>();
        CounterControl counterControl = eventSystemObject.GetComponent <CounterControl>();

        //親オブジェクト取得
        parentFieldObject = this.gameObject.transform.parent.gameObject;
        //栽培中としてステータス変更
        parentFieldObject.tag = "NowPlantingField";

        this.gameObject.AddComponent <ObservableEventTrigger>()
        .OnPointerDownAsObservable()
        .Subscribe(pointerEventData => {
            //肥料を与える
            if (this.gameObject.tag != "FruitPlant" && growPlant.fertilizerSelected)
            {
                GameObject obj       = (GameObject)Instantiate(fruitPlant, parentFieldObject.transform);
                obj.transform.parent = parentFieldObject.transform;
                Destroy(this.gameObject);
                counterControl.ConsumeFertilizer(1);
            }
            //収穫する
            if (this.gameObject.tag == "FruitPlant" && growPlant.harvestSelected)
            {
                //収穫処理実行
                Destroy(this.gameObject);
                parentFieldObject.tag = "plantfield";
                counterControl.IncreaseHarvestAmount(1);
            }
        })
        .AddTo(gameObject);

        //植物を成長させる(芽→花)
        if (this.gameObject.tag == "SproutPlant")
        {
            Observable.Timer(TimeSpan.FromSeconds(5))
            .Subscribe(_ =>
            {
                GameObject obj       = (GameObject)Instantiate(bloomPlant, parentFieldObject.transform);
                obj.transform.parent = parentFieldObject.transform;
                Destroy(gameObject);
            })
            .AddTo(gameObject);
        }
        //植物を成長させる(花→果実)
        else if (this.gameObject.tag == "BloomPlant")
        {
            Observable.Timer(TimeSpan.FromSeconds(5))
            .Subscribe(_ =>
            {
                GameObject obj       = (GameObject)Instantiate(fruitPlant, parentFieldObject.transform);
                obj.transform.parent = parentFieldObject.transform;
                Destroy(gameObject);
            })
            .AddTo(gameObject);
        }
    }
Esempio n. 2
0
    public void StartUp()
    {
        offsetPos = new Vector3(-1000, 0, -1000);
        int     BreedCount = 0;
        Vector3 Vec3       = new Vector3();

        woodlist = new int[STAGE_AREA, STAGE_AREA];

        //生成リストを取得
        ObjNames = DataBaseManager.SetUpStartObjectData();

        //A国の範囲内には生成しない
        for (int xz = 0; xz < STAGE_AREA; xz++)
        {
            for (int yz = 0; yz < STAGE_AREA; yz++)
            {
                woodlist[xz, yz] = 0;
                if (xz < HumCastle.x + (Area_A / 2) && xz > HumCastle.x - (Area_A / 2))
                {
                    if (yz < HumCastle.z + (Area_A / 2) && yz > HumCastle.z - (Area_A / 2))
                    {
                        // woodlist[xz, yz] = -1;
                    }
                }
                //B国の範囲内には生成しない
                Vec3 = new Vector3(xz, 0, yz);
                if (Math.Length(RobCastle - Vec3) < Area_B)
                {
                    woodlist[xz, yz] = -1;
                }
            }
        }

        //第1世代を生成
        for (int z = 0; z < STAGE_AREA; z++)
        {
            for (int x = 0; x < STAGE_AREA; x++)
            {
                if (BreedCount < BREED_LIMIT)//第1世代
                {
                    if (Random.Range(0, 100) == 0 && woodlist[z, x] == 0)
                    {
                        int        rInst = Random.Range(0, ObjNames.Length);
                        GameObject g     = GrowPlant.CreateGrowPlant(ObjNames[rInst], new Vector3(x * 5, 0, z * 20) + offsetPos, 20);
                        woodlist[z, x] = rInst;
                        BreedCount++;
                    }
                }
            }
        }
    }