示例#1
0
    private void Start()
    {
        unitController = transform.parent.GetComponentInParent <UnitController>();
        baseController = transform.parent.GetComponentInParent <BaseController>();
        if (unitController == null)
        {
            throw new Exception("There is no unit controller present on one of the base containers, please fix this issue.");
        }

        AddEventListeners();
        Parent = GetComponentInParent <BaseTile>();
        TeamId = Parent.GetComponentInParent <BaseController>().TeamID;

        if (GroupId == Guid.Empty)
        {
            bool createNew = true;

            foreach (var neighbor in Parent.Neighbors)
            {
                if (neighbor.RoomScript is BaseUnitRoom)
                {
                    var other = neighbor.RoomScript as BaseUnitRoom;
                    if (other.GroupId == Guid.Empty)
                    {
                        continue;
                    }
                    else
                    {
                        if (createNew)
                        {
                            createNew = false;
                            GroupId   = other.GroupId;
                        }
                        else if (other.GroupId != GroupId)
                        {
                            unitController.MergeGroupIntoGroup(other.GroupId, GroupId);
                        }
                    }
                }
            }

            if (createNew)
            {
                GroupId = unitController.CreateUnitGroup();
            }

            AttachUnitGroup();

            unitGroup.AddMax();
        }

        AttachUnitGroup();

        InvokeRepeating("CheckSpawnable", 1.0f, 1.0f);

        if (!Parent.Loaded)
        {
            //singleFree = true;
        }
        baseController.GetGameResources().AddResources(RespawnCost);
    }