From c9d7e77fb0dd55e612b412c943bfa33d70fe1375 Mon Sep 17 00:00:00 2001 From: wserver/wangdisen <1065498738@qq.com> Date: Tue, 16 Aug 2022 14:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9InitFarmlandDic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Hotfix/Demo/Unit/UnitFactory.cs | 20 +------------------ .../Hotfix/Demo/Operate/ConstructOperate.cs | 2 ++ Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs | 1 + Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs | 20 +++++++++++++++++++ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Server/Hotfix/Demo/Unit/UnitFactory.cs b/Server/Hotfix/Demo/Unit/UnitFactory.cs index 9508e3d..c5c9884 100644 --- a/Server/Hotfix/Demo/Unit/UnitFactory.cs +++ b/Server/Hotfix/Demo/Unit/UnitFactory.cs @@ -57,7 +57,6 @@ namespace ET unit.SeasonConfig = SeasonConfigCategory.Instance.Get(unit.Season); unitComponent.AddChild(unit); - InitNoDb(unit); } else { @@ -195,23 +194,6 @@ namespace ET }*/ } - public static void InitNoDb(Unit unit) - { - var bc = unit.GetComponent(); - if (bc == null) - { - return; - } - foreach (var v in unit.GetComponent().Children.Values) - { - foreach (var c in v.Children.Values) - { - if (c.GetType() == typeof (Farmland)) - { - unit.FarmlandDic[c.Id] = (Farmland) c; - } - } - } - } + } } \ No newline at end of file diff --git a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs index 235f706..5382180 100644 --- a/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs +++ b/Unity/Codes/Hotfix/Demo/Operate/ConstructOperate.cs @@ -6,6 +6,7 @@ namespace ET [FriendClass(typeof (Construct))] [FriendClass(typeof (Building))] [FriendClass(typeof (Farmland))] + [FriendClass(typeof(Unit))] public static class ConstructOperate { public static Construct CreateConstruct(Unit unit, int configId, float x, float y, long id = 0, long buildingId = 0) @@ -178,6 +179,7 @@ namespace ET { var farmland = build.AddChild(); farmland.FarmlandState = FarmlandState.FARMLAND_STATE_FREE; + unit.FarmlandDic[farmland.Id] = farmland; } } diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs index bd430c6..c853c70 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitFactory.cs @@ -110,6 +110,7 @@ namespace ET unitComponent.Add(unit); unit.AddComponent(); + unit.InitFarmlandDic(); Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit}); return unit; diff --git a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs index e9543ed..3335395 100644 --- a/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs +++ b/Unity/Codes/Hotfix/Demo/Unit/UnitSystem.cs @@ -146,6 +146,7 @@ namespace ET self.UpdateValleyTime = TimeHelper.ServerUnix(); self.SeasonConfig = SeasonConfigCategory.Instance.Get(self.Season); self.InitPeopleNumberic(); + self.InitFarmlandDic(); } public static void updateSeason(this Unit self) @@ -245,6 +246,25 @@ namespace ET ((People) v).GrowUp(); } } + + public static void InitFarmlandDic(this Unit self) + { + var bc = self.GetComponent(); + if (bc == null) + { + return; + } + foreach (var v in self.GetComponent().Children.Values) + { + foreach (var c in v.Children.Values) + { + if (c.GetType() == typeof (Farmland)) + { + self.FarmlandDic[c.Id] = (Farmland) c; + } + } + } + } } } \ No newline at end of file