添加高粱生长阶段

This commit is contained in:
huqibin 2025-06-03 14:35:15 +08:00
parent b73f6d51a2
commit 37741b3b20
4 changed files with 5326 additions and 740 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,26 +7,41 @@ using UnityEngine.SocialPlatforms;
public enum SorghumState public enum SorghumState
{ {
Healthy, Diseased,//病株成熟
Diseased Healthy,//健康成熟
}
public enum SorghumPeriod
{
Mature,//成熟
Seedling//幼苗
} }
public class SorghumController : PermanentTriggerBase public class SorghumController : PermanentTriggerBase
{ {
public GameObject DiseasedStrain; public GameObject Diseased_Mature;//病株成熟
public GameObject HealthyStrain; public GameObject Healthy_Mature;//健康成熟
public GameObject Diseased_Seedling;//病株成熟
public GameObject Healthy_Seedling;//健康幼苗
public SorghumState State = SorghumState.Healthy; public SorghumState State = SorghumState.Healthy;
public SorghumPeriod Period = SorghumPeriod.Mature;
public bool RandomRotate = true; public bool RandomRotate = true;
//LODGroup lodGroup = null; //LODGroup lodGroup = null;
public void Init(SorghumState _state = SorghumState.Healthy, bool _rand = false) public void Init(SorghumState _state = SorghumState.Healthy, SorghumPeriod _period = SorghumPeriod.Mature, bool _rand = false)
{ {
State = _state; State = _state;
DiseasedStrain.SetActive(State == SorghumState.Diseased); Period = _period;
HealthyStrain.SetActive(State == SorghumState.Healthy); //DiseasedStrain.SetActive(State == SorghumState.Diseased);
//HealthyStrain.SetActive(State == SorghumState.Healthy);
Diseased_Mature.SetActive(State == SorghumState.Diseased && Period == SorghumPeriod.Mature);//病株成熟
Healthy_Mature.SetActive(State == SorghumState.Healthy && Period == SorghumPeriod.Mature); //健康成熟
Diseased_Seedling.SetActive(State == SorghumState.Diseased && Period == SorghumPeriod.Seedling);//病株成熟
Healthy_Seedling.SetActive(State == SorghumState.Healthy && Period == SorghumPeriod.Seedling); //健康幼苗
RandomRotate = _rand; RandomRotate = _rand;
if (RandomRotate) if (RandomRotate)
@ -52,23 +67,41 @@ public class SorghumController : PermanentTriggerBase
case SorghumState.Healthy: case SorghumState.Healthy:
triggerName = "¸ßÁ»_Õý³£"; triggerName = "¸ßÁ»_Õý³£";
this.gameObject.name = "¸ßÁ»_Õý³£"; this.gameObject.name = "¸ßÁ»_Õý³£";
//lodGroup = HealthyStrain.GetComponent<LODGroup>();
break; break;
} }
switch (Period)
{
//lodGroup = HealthyStrain.GetComponent<LODGroup>();
case SorghumPeriod.Seedling:
triggerName += "幼苗";
this.gameObject.name += "幼苗";
break;
case SorghumPeriod.Mature:
triggerName += "成熟";
this.gameObject.name += "成熟";
break;
}
} }
public GameObject GetCurrentSorghum() public GameObject GetCurrentSorghum()
{ {
if (State == SorghumState.Diseased) if (Period == SorghumPeriod.Mature)
{ {
return DiseasedStrain; if (State == SorghumState.Diseased)
return Diseased_Mature;
else
return Healthy_Mature;
} }
else else
{ {
return HealthyStrain; if (State == SorghumState.Diseased)
return Diseased_Seedling;
else
return Healthy_Seedling;
} }
} }
protected override void OnMDown() protected override void OnMDown()
@ -82,8 +115,10 @@ public class SorghumController : PermanentTriggerBase
GameObject targetObj = GameObject.Find("Split_Obj"); GameObject targetObj = GameObject.Find("Split_Obj");
GameObject targetHD = targetObj.transform.GetChild(0).gameObject; GameObject targetHD_M = targetObj.transform.GetChild(0).gameObject;
GameObject targetSD = targetObj.transform.GetChild(1).gameObject; GameObject targetSC_M = targetObj.transform.GetChild(1).gameObject;
GameObject targetHD_S = targetObj.transform.GetChild(2).gameObject;
GameObject targetSC_S = targetObj.transform.GetChild(3).gameObject;
GameObject SplitCamera = GameObject.Find("SplitCamera"); GameObject SplitCamera = GameObject.Find("SplitCamera");
foreach (Transform item in SplitCamera.transform) foreach (Transform item in SplitCamera.transform)
@ -91,17 +126,26 @@ public class SorghumController : PermanentTriggerBase
item.gameObject.SetActive(true); item.gameObject.SetActive(true);
} }
targetHD_M.SetActive(false);
targetHD_S.SetActive(false);
targetSC_M.SetActive(false);
targetSC_S.SetActive(false);
if (State == SorghumState.Diseased) if (State == SorghumState.Diseased)
{ {
targetHD.SetActive(true); if (Period == SorghumPeriod.Seedling)
targetSD.SetActive(false); targetHD_S.SetActive(true);
else
targetHD_M.SetActive(true);
GameManager.UIMgr.ShowPanel<UI_BGPanel>(E_UI_Layer.Top); GameManager.UIMgr.ShowPanel<UI_BGPanel>(E_UI_Layer.Top);
GameManager.UIMgr.ShowPanel<UI_GraphicRextualPanel>(E_UI_Layer.Top, (p) => { p.Init(); }); GameManager.UIMgr.ShowPanel<UI_GraphicRextualPanel>(E_UI_Layer.Top, (p) => { p.Init(); });
} }
else else
{ {
targetHD.SetActive(false); if (Period == SorghumPeriod.Seedling)
targetSD.SetActive(true); targetSC_S.SetActive(true);
else
targetSC_M.SetActive(true);
GameManager.UIMgr.ShowPanel<UI_BGPanel>(E_UI_Layer.Top); GameManager.UIMgr.ShowPanel<UI_BGPanel>(E_UI_Layer.Top);
GameManager.UIMgr.ShowPanel<UI_PlantComparisonPanel>(E_UI_Layer.Top, (p) => { p.Init(); }); GameManager.UIMgr.ShowPanel<UI_PlantComparisonPanel>(E_UI_Layer.Top, (p) => { p.Init(); });
} }
@ -113,7 +157,7 @@ public class SorghumController : PermanentTriggerBase
//if (GameManager.RunModelMgr?.ModeType != E_ModeType.Study) //if (GameManager.RunModelMgr?.ModeType != E_ModeType.Study)
//{ //{
_highlight = GetComponentInChildren<HighlightEffect>(); //_highlight = GetComponentInChildren<HighlightEffect>();
if (_highlight != null) if (_highlight != null)
_highlight.SetHighlighted(true); _highlight.SetHighlighted(true);

View File

@ -12,6 +12,8 @@ public class SorghumFieldController : MonoBehaviour
public float strainDistance = 1; public float strainDistance = 1;
public float diseasedRate = 0; public float diseasedRate = 0;
public SorghumPeriod sorghumPeriod = SorghumPeriod.Mature;
// 新增动态渲染相关字段 // 新增动态渲染相关字段
[Header("Dynamic Rendering")] [Header("Dynamic Rendering")]
public int chunksPerAxis = 10; // 每轴区块数量 public int chunksPerAxis = 10; // 每轴区块数量
@ -41,7 +43,7 @@ public class SorghumFieldController : MonoBehaviour
// 预生成所有高粱并分配到区块 // 预生成所有高粱并分配到区块
GenerateSorghumGrid(sorghumPrefab, rowDistance, strainDistance); GenerateSorghumGrid(sorghumPrefab, rowDistance, strainDistance);
ProcessDiseasedPlants(diseasedRate, randomRotate); ProcessDiseasedPlants(diseasedRate, randomRotate, sorghumPeriod);
// 初始隐藏所有高粱 // 初始隐藏所有高粱
SetAllChunksVisibility(true); SetAllChunksVisibility(true);
@ -55,8 +57,8 @@ public class SorghumFieldController : MonoBehaviour
{ {
Vector3 spawnPos = new Vector3(x, fieldBounds.min.y, z); Vector3 spawnPos = new Vector3(x, fieldBounds.min.y, z);
GameObject obj = Instantiate(prefab, spawnPos, Quaternion.identity, fieldArea.transform); GameObject obj = Instantiate(prefab, spawnPos, Quaternion.identity, fieldArea.transform);
AddToChunk(obj); AddToChunk(obj);
} }
} }
@ -76,7 +78,7 @@ public class SorghumFieldController : MonoBehaviour
chunkMap[chunkCoord].Add(sorghum); chunkMap[chunkCoord].Add(sorghum);
} }
void ProcessDiseasedPlants(float diseasedRate, bool randomRotate) void ProcessDiseasedPlants(float diseasedRate, bool randomRotate, SorghumPeriod period)
{ {
SorghumController[] sorghumControllers = FindObjectsOfType<SorghumController>(); SorghumController[] sorghumControllers = FindObjectsOfType<SorghumController>();
int DisCount = (int)(sorghumControllers.Length * diseasedRate); int DisCount = (int)(sorghumControllers.Length * diseasedRate);
@ -85,7 +87,7 @@ public class SorghumFieldController : MonoBehaviour
int iter = (int)(sorghumControllers.Length * UnityEngine.Random.value); int iter = (int)(sorghumControllers.Length * UnityEngine.Random.value);
if (iter >= sorghumControllers.Length) iter = sorghumControllers.Length - 1; if (iter >= sorghumControllers.Length) iter = sorghumControllers.Length - 1;
if (iter < 0) iter = 0; if (iter < 0) iter = 0;
sorghumControllers[iter].Init(SorghumState.Diseased, randomRotate); sorghumControllers[iter].Init(SorghumState.Healthy, SorghumPeriod.Mature, randomRotate);
sorghumControllers[iter] = sorghumControllers[sorghumControllers.Length - 1]; sorghumControllers[iter] = sorghumControllers[sorghumControllers.Length - 1];
SorghumController[] newArry = new SorghumController[sorghumControllers.Length - 1]; SorghumController[] newArry = new SorghumController[sorghumControllers.Length - 1];
Array.Copy(sorghumControllers, newArry, sorghumControllers.Length - 1); Array.Copy(sorghumControllers, newArry, sorghumControllers.Length - 1);
@ -93,7 +95,7 @@ public class SorghumFieldController : MonoBehaviour
foreach (var item in sorghumControllers) foreach (var item in sorghumControllers)
{ {
item.Init(SorghumState.Healthy, randomRotate); item.Init(SorghumState.Healthy, period, randomRotate);
SetRenderersEnabled(false, item.gameObject); SetRenderersEnabled(false, item.gameObject);
//item.gameObject.GetComponentInChildren<Renderer>().enabled = false; // 初始隐藏 //item.gameObject.GetComponentInChildren<Renderer>().enabled = false; // 初始隐藏
} }