|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof(Building))]
|
|
|
|
public static class BuildingComponentSystem
|
|
|
|
{
|
|
|
|
public static Building CreateBuilding(this BuildingComponent self, int ConfigId, float X, float Y, long id = 0)
|
|
|
|
{
|
|
|
|
Building building;
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
building = self.AddChild<Building>();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
building = self.AddChildWithId<Building>(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
building.ConfigId = ConfigId;
|
|
|
|
building.Position = new Vector2(X, Y);
|
|
|
|
building.Durable = building.Config.Durable;
|
|
|
|
return building;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool CheckOutBuildingByIds(this BuildingComponent self, int[] StructureID)
|
|
|
|
{
|
|
|
|
bool hasBuilding = false;
|
|
|
|
foreach (var v in self.Children)
|
|
|
|
{
|
|
|
|
Building building = (Building) v.Value;
|
|
|
|
if (Array.IndexOf(StructureID, building.ConfigId) != -1 )
|
|
|
|
{
|
|
|
|
hasBuilding = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasBuilding;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool CheckOutBuildingBySpecialType(this BuildingComponent self, int special)
|
|
|
|
{
|
|
|
|
bool hasBuilding = false;
|
|
|
|
foreach (var v in self.Children)
|
|
|
|
{
|
|
|
|
Building building = (Building) v.Value;
|
|
|
|
if (special == building.Config.Special)
|
|
|
|
{
|
|
|
|
hasBuilding = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasBuilding;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void DurableReduce(this BuildingComponent self)
|
|
|
|
{
|
|
|
|
foreach (var v in self.Children.Values)
|
|
|
|
{
|
|
|
|
((Building)v).DurableReduce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int GetBuildingNum(this BuildingComponent self, int configId)
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
foreach (var keyValuePair in self.Children)
|
|
|
|
{
|
|
|
|
Building building = (Building)keyValuePair.Value;
|
|
|
|
if (building.ConfigId == configId)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|