設定から畑を生成する処理を追加
This commit is contained in:
parent
c3f07e576b
commit
57602681eb
|
|
@ -1,12 +1,20 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UniRx.Triggers;
|
using UniRx.Triggers;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
public enum CornFieldRank
|
||||||
|
{
|
||||||
|
Rank1,
|
||||||
|
Rank2,
|
||||||
|
Rank3
|
||||||
|
}
|
||||||
|
|
||||||
public class CornField : MonoBehaviour
|
public class CornField : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Button promoteGrowthButton;
|
[SerializeField] private Button promoteGrowthButton;
|
||||||
|
|
@ -15,11 +23,11 @@ public class CornField : MonoBehaviour
|
||||||
[SerializeField] private CornHarvester cornHarvester;
|
[SerializeField] private CornHarvester cornHarvester;
|
||||||
[Space]
|
[Space]
|
||||||
[SerializeField] private List<PlantLine> plantLines = new List<PlantLine>();
|
[SerializeField] private List<PlantLine> plantLines = new List<PlantLine>();
|
||||||
[SerializeField] private List<CornSeedling> centerPlants = new List<CornSeedling>();
|
private readonly List<PlantLine> availableLines = new List<PlantLine>();
|
||||||
private readonly List<CornSeedling> plants = new List<CornSeedling>();
|
private static readonly int maxPeriod = 60;
|
||||||
private static readonly float maxPeriod = 60f;
|
private static readonly int minPeriod = 45;
|
||||||
private static readonly float minPeriod = 45f;
|
|
||||||
|
|
||||||
|
private readonly ReactiveProperty<int> harvestedCornCount = new ReactiveProperty<int>();
|
||||||
private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
|
private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
|
|
@ -30,67 +38,171 @@ public class CornField : MonoBehaviour
|
||||||
.Take(1)
|
.Take(1)
|
||||||
.Subscribe(_ => TransitionManager.Instance.LoadScene(GameScenes.CornField)).AddTo(this);
|
.Subscribe(_ => TransitionManager.Instance.LoadScene(GameScenes.CornField)).AddTo(this);
|
||||||
|
|
||||||
|
// データ
|
||||||
var settings = new DateTime[3]
|
// 解放済みの畑, 畑の質, 収穫機レベル
|
||||||
|
var plantSetting = new List<PlantLineType>()
|
||||||
{
|
{
|
||||||
DateTime.Now,
|
PlantLineType.Center,
|
||||||
DateTime.Now,
|
PlantLineType.Bottom,
|
||||||
DateTime.Now,
|
|
||||||
};
|
};
|
||||||
// settings = new DateTime[3]
|
var fieldLevel = (int)CornFieldRank.Rank3;
|
||||||
// {
|
var machineLevel = 1;
|
||||||
// DateTime.Now.AddSeconds(-Random.Range(0, 15)),
|
// コーン株の進行度
|
||||||
// DateTime.Now.AddSeconds(-Random.Range(0, 15)),
|
var progressDataList = new List<SeedlingProgressData>()
|
||||||
// DateTime.Now.AddSeconds(-Random.Range(0, 15)),
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
plants.Clear();
|
|
||||||
plants.AddRange(centerPlants);
|
|
||||||
|
|
||||||
for (int i = 0; i < plants.Count; i++)
|
|
||||||
{
|
{
|
||||||
var period = 15 + Random.Range(0, 15);
|
GenerateSeedlingData(PlantLineType.Center),
|
||||||
var ii = i;
|
};
|
||||||
plants[ii].SetSeedlingGene(settings[ii], period, SeedlingRank.Rank1);
|
|
||||||
plants[ii].Harvested.Subscribe(_ =>
|
// 畑リセット
|
||||||
|
availableLines.Clear();
|
||||||
|
foreach (var line in plantLines)
|
||||||
|
{
|
||||||
|
line.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// セーブデータから畑を復元
|
||||||
|
foreach (var line in plantSetting)
|
||||||
|
{
|
||||||
|
Debug.Log($"{line}");
|
||||||
|
var plantLine = plantLines.First(x => x.LineName == line);
|
||||||
|
plantLine.gameObject.SetActive(true);
|
||||||
|
availableLines.Add(plantLine);
|
||||||
|
// 初回データ作成
|
||||||
|
if (!progressDataList.Exists(x => x.type == line))
|
||||||
{
|
{
|
||||||
// 収穫
|
progressDataList.Add(GenerateSeedlingData(line));
|
||||||
VibrationManager.Instance.PlayVibrationOnce();
|
}
|
||||||
var harvest = Instantiate(harvestPrefab, plants[ii].transform);
|
|
||||||
this.CallWaitForSeconds(.5f, () =>
|
|
||||||
{
|
|
||||||
var beginPos = harvest.transform.position;
|
|
||||||
this.CallLerp(.4f, f =>
|
|
||||||
{
|
|
||||||
harvest.transform.position = Vector3.Lerp(beginPos, harvestInsertPosition.position, f.EaseInCubic());
|
|
||||||
}, () =>
|
|
||||||
{
|
|
||||||
var seedCount = 25;
|
|
||||||
cornHarvester.AddCount(seedCount);
|
|
||||||
Destroy(harvest);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// 新しい苗
|
|
||||||
period = 15 + Random.Range(0, 15);
|
|
||||||
settings[ii] = DateTime.Now;
|
|
||||||
plants[ii].SetSeedlingGene(settings[ii], period, SeedlingRank.Rank1);
|
|
||||||
}).AddTo(compositeDisposable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 株設定
|
||||||
|
foreach (var line in availableLines)
|
||||||
|
{
|
||||||
|
var lineData = progressDataList.First(x => x.type == line.LineName);
|
||||||
|
var i = 0;
|
||||||
|
foreach (var seedling in line.Seedlings)
|
||||||
|
{
|
||||||
|
var index = i;
|
||||||
|
i++;
|
||||||
|
seedling.SetSeedlingGene(lineData.Seedlings[index].firstTime, lineData.Seedlings[index].period, (CornFieldRank)fieldLevel);
|
||||||
|
seedling.Harvested.Subscribe(_ =>
|
||||||
|
{
|
||||||
|
// 収穫
|
||||||
|
VibrationManager.Instance.PlayVibrationOnce();
|
||||||
|
for (int j = 0; j < GetHarvestCount((CornFieldRank)fieldLevel); j++)
|
||||||
|
{
|
||||||
|
var harvestedCorn = 20;
|
||||||
|
harvestedCornCount.Value += harvestedCorn;
|
||||||
|
var harvestAnimation = Instantiate(harvestPrefab, seedling.transform);
|
||||||
|
this.CallWaitForSeconds(.5f, () =>
|
||||||
|
{
|
||||||
|
var beginPos = harvestAnimation.transform.position;
|
||||||
|
this.CallLerp(.4f, f =>
|
||||||
|
{
|
||||||
|
harvestAnimation.transform.position = Vector3.Lerp(beginPos, harvestInsertPosition.position, f.EaseInQuadratic());
|
||||||
|
}, () =>
|
||||||
|
{
|
||||||
|
cornHarvester.AddCount(harvestedCorn);
|
||||||
|
Destroy(harvestAnimation);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 新しい苗
|
||||||
|
lineData.Seedlings[index] = GenerateSeedlingGene();
|
||||||
|
seedling.SetSeedlingGene(lineData.Seedlings[index].firstTime, lineData.Seedlings[index].period, CornFieldRank.Rank1);
|
||||||
|
}).AddTo(compositeDisposable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 時短ボタン
|
||||||
promoteGrowthButton.OnClickAsObservable().Subscribe(_ =>
|
promoteGrowthButton.OnClickAsObservable().Subscribe(_ =>
|
||||||
{
|
{
|
||||||
VibrationManager.Instance.PlayVibrationOnce();
|
VibrationManager.Instance.PlayVibrationOnce();
|
||||||
for (int i = 0; i < plants.Count; i++)
|
foreach (var line in availableLines)
|
||||||
{
|
{
|
||||||
if (Random.Range(0, 2) == 0){
|
var lineData = progressDataList.First(x => x.type == line.LineName);
|
||||||
settings[i] = settings[i].AddSeconds(-1);
|
var i = 0;
|
||||||
plants[i].PromoteGrowth(settings[i]);
|
foreach (var seedling in line.Seedlings)
|
||||||
};
|
{
|
||||||
|
if (Random.Range(0, 2) == 0)
|
||||||
|
{
|
||||||
|
var tmpData = lineData.Seedlings[i];
|
||||||
|
tmpData.firstTime = lineData.Seedlings[i].firstTime.AddSeconds(-1);
|
||||||
|
lineData.Seedlings[i] = tmpData;
|
||||||
|
seedling.PromoteGrowth(lineData.Seedlings[i].firstTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// 設定のセーブ
|
||||||
}).AddTo(compositeDisposable);
|
}).AddTo(compositeDisposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SeedlingProgressData GenerateSeedlingData(PlantLineType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PlantLineType.Top:
|
||||||
|
return new SeedlingProgressData
|
||||||
|
{
|
||||||
|
type = PlantLineType.Top,
|
||||||
|
Seedlings = new List<(DateTime firstTime, int period)>()
|
||||||
|
{
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
case PlantLineType.Center:
|
||||||
|
return new SeedlingProgressData
|
||||||
|
{
|
||||||
|
type = PlantLineType.Center,
|
||||||
|
Seedlings = new List<(DateTime firstTime, int period)>()
|
||||||
|
{
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case PlantLineType.Bottom:
|
||||||
|
return new SeedlingProgressData
|
||||||
|
{
|
||||||
|
type = PlantLineType.Bottom,
|
||||||
|
Seedlings = new List<(DateTime firstTime, int period)>()
|
||||||
|
{
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
GenerateSeedlingGene(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private (DateTime, int) GenerateSeedlingGene()
|
||||||
|
{
|
||||||
|
// return (DateTime.Now, Random.Range(minPeriod, maxPeriod + 1));
|
||||||
|
return (DateTime.Now.AddSeconds(-Random.Range(0, 15)), 15 + Random.Range(0, 15));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetHarvestCount(CornFieldRank rank)
|
||||||
|
{
|
||||||
|
switch (rank)
|
||||||
|
{
|
||||||
|
case CornFieldRank.Rank1:
|
||||||
|
return 1;
|
||||||
|
case CornFieldRank.Rank2:
|
||||||
|
return 2;
|
||||||
|
case CornFieldRank.Rank3:
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(rank), rank, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class SeedlingProgressData
|
||||||
|
{
|
||||||
|
public PlantLineType type;
|
||||||
|
public List<(DateTime firstTime, int period)> Seedlings;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 61c5405c000a4baea2bc5b6ad44ce2b2
|
||||||
|
timeCreated: 1627558442
|
||||||
Loading…
Reference in New Issue