You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.2 KiB
59 lines
2.2 KiB
3 years ago
|
using UnityEngine;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
public class FarmlandViewComponentAwakeSystem: AwakeSystem<FarmlandViewComponent>
|
||
|
{
|
||
|
public override void Awake(FarmlandViewComponent self)
|
||
|
{
|
||
|
self.Awake();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
[FriendClass(typeof(FarmlandViewComponent))]
|
||
|
[FriendClass(typeof(Farmland))]
|
||
|
[FriendClass(typeof(Building))]
|
||
|
[FriendClass(typeof(BuildingViewComponent))]
|
||
|
public static class FarmlandViewComponentSystem
|
||
|
{
|
||
|
public static void Awake(this FarmlandViewComponent self)
|
||
|
{
|
||
|
self.Farmland = self.GetParent<Farmland>();
|
||
|
|
||
|
self.SeedCropPrfb = self.LoadAssetSync<GameObject>("Sprout".ToPrefabAddress());
|
||
|
self.RipeCropPrfb = self.LoadAssetSync<GameObject>("Wheat".ToPrefabAddress());
|
||
|
|
||
|
self.UpdateByState();
|
||
|
}
|
||
|
|
||
|
public static void UpdateByState(this FarmlandViewComponent self)
|
||
|
{
|
||
|
var building = self.Farmland.GetParent<Building>();
|
||
|
var buildingView = building.GetComponent<BuildingViewComponent>();
|
||
|
|
||
|
if (self.FarmlandRoot != null)
|
||
|
{
|
||
|
Util.GameObjectPoolHelper.ReturnObjectToPool(self.FarmlandRoot);
|
||
|
}
|
||
|
switch (self.Farmland.FarmlandState)
|
||
|
{
|
||
|
case FarmlandState.FARMLAND_STATE_FREE:
|
||
|
case FarmlandState.FARMLAND_STATE_SEED:
|
||
|
break;
|
||
|
case FarmlandState.FARMLAND_STATE_GROW:
|
||
|
self.FarmlandRoot = Util.GameObjectPoolHelper.SpawnGameObject(self.SeedCropPrfb);
|
||
|
self.FarmlandRoot.transform.position = buildingView.GetCenterPos();
|
||
|
self.FarmlandRoot.transform.parent = buildingView.BuildingRoot.transform;
|
||
|
break;
|
||
|
case FarmlandState.FARMLAND_STATE_RIPE:
|
||
|
self.FarmlandRoot = Util.GameObjectPoolHelper.SpawnGameObject(self.RipeCropPrfb);
|
||
|
self.FarmlandRoot.transform.position = buildingView.GetCenterPos();
|
||
|
self.FarmlandRoot.transform.parent = buildingView.BuildingRoot.transform;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|