Beispiel #1
0
 public void DestroyBuilding(Building building)
 {
     if (building && building.gameObject)
     {
         BuildingAgent ba = buildingAgents.Find(x => x.MBuilding == building);
         if (ba)
         {
             ba.Hide();
             ba.Clear();
             buildingAgents.Remove(ba);
             this.buildings.TryGetValue(building.MBuildingInfo, out var buildings);
             if (buildings != null)
             {
                 buildings.Remove(building);
                 if (buildings.Count < 1)
                 {
                     this.buildings.Remove(building.MBuildingInfo);
                 }
             }
         }
         if (buildingAgents.Count < 1 && currentInfo == building.MBuildingInfo && UI.listWindow.alpha > 0)
         {
             HideBuiltList();
         }
         if (AStarManager.Instance)
         {
             var colliders = building.GetComponentsInChildren <Collider>();
             if (colliders.Length > 0)
             {
                 Vector3 min = colliders[0].bounds.min;
                 Vector3 max = colliders[0].bounds.max;
                 for (int i = 1; i < colliders.Length; i++)
                 {
                     if (ZetanUtility.Vector3LessThan(colliders[i].bounds.min, min))
                     {
                         min = colliders[i].bounds.min;
                     }
                     if (ZetanUtility.Vector3LargeThan(colliders[i].bounds.max, max))
                     {
                         max = colliders[i].bounds.max;
                     }
                 }
                 AStarManager.Instance.UpdateGraphs(min, max);
             }
             else
             {
                 var collider2Ds = building.GetComponentsInChildren <Collider2D>();
                 if (collider2Ds.Length > 0)
                 {
                     Vector3 min = collider2Ds[0].bounds.min;
                     Vector3 max = collider2Ds[0].bounds.max;
                     for (int i = 1; i < collider2Ds.Length; i++)
                     {
                         if (ZetanUtility.Vector3LessThan(collider2Ds[i].bounds.min, min))
                         {
                             min = collider2Ds[i].bounds.min;
                         }
                         if (ZetanUtility.Vector3LargeThan(collider2Ds[i].bounds.max, max))
                         {
                             max = collider2Ds[i].bounds.max;
                         }
                     }
                     AStarManager.Instance.UpdateGraphs(min, max);
                 }
             }
         }
         building.Destroy();
     }
     CannotManage();
 }
Beispiel #2
0
    public void Build()
    {
        if (!currentInfo)
        {
            return;
        }
        if (BuildAble)
        {
            if (BackpackManager.Instance.IsMaterialsEnough(currentInfo.Materials))
            {
                Building building = Instantiate(currentInfo.Prefab);
                if (building.StarBuild(currentInfo, preview.Position))
                {
                    foreach (MaterialInfo m in currentInfo.Materials)
                    {
                        if (!BackpackManager.Instance.TryLoseItem_Boolean(m.ItemInfo))
                        {
                            FinishPreview();
                            return;
                        }
                    }
                    foreach (MaterialInfo m in currentInfo.Materials)
                    {
                        BackpackManager.Instance.LoseItem(m.ItemInfo);
                    }
                    if (!buildings.ContainsKey(currentInfo))
                    {
                        buildings.Add(currentInfo, new List <Building>());
                    }
                    buildings[currentInfo].Add(building);
                    var bf = ObjectPool.Get(UI.buildingFlagPrefab, UIManager.Instance.BuildingFlagParent).GetComponent <BuildingFlag>();
                    bf.Init(building);
                    if (AStarManager.Instance)
                    {
                        var collider2Ds = building.GetComponentsInChildren <Collider2D>();
                        if (collider2Ds.Length > 0)
                        {
                            Vector3 min = collider2Ds[0].bounds.min;
                            Vector3 max = collider2Ds[0].bounds.max;
                            for (int i = 1; i < collider2Ds.Length; i++)
                            {
                                if (ZetanUtility.Vector3LessThan(collider2Ds[i].bounds.min, min))
                                {
                                    min = collider2Ds[i].bounds.min;
                                }
                                if (ZetanUtility.Vector3LargeThan(collider2Ds[i].bounds.max, max))
                                {
                                    max = collider2Ds[i].bounds.max;
                                }
                            }
                            AStarManager.Instance.UpdateGraphs(min, max);
                        }
                        else
                        {
                            var colliders = building.GetComponentsInChildren <Collider>();
                            if (colliders.Length > 0)
                            {
                                Vector3 min = colliders[0].bounds.min;
                                Vector3 max = colliders[0].bounds.max;
                                for (int i = 1; i < colliders.Length; i++)
                                {
                                    if (ZetanUtility.Vector3LessThan(colliders[i].bounds.min, min))
                                    {
                                        min = colliders[i].bounds.min;
                                    }
                                    if (ZetanUtility.Vector3LargeThan(colliders[i].bounds.max, max))
                                    {
                                        max = colliders[i].bounds.max;
                                    }
                                }
                                AStarManager.Instance.UpdateGraphs(min, max);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageManager.Instance.New("耗材不足");
            }
            FinishPreview();
        }
        else
        {
            MessageManager.Instance.New("空间不足");
#if UNITY_ANDROID
            FinishPreview();
#endif
        }
    }