예제 #1
0
 //Should be Synchronized
 public StatusCode AddExecutionUnit(ExecutionUnit unit)
 {
     lock (ExecutionUnitQueue)
     {
         ExecutionUnitQueue.Enqueue(unit);
     }
     UnitAdded?.Invoke(this, new ThreadPoolItemEventArg(unit));
     return(StatusCode.SUCCEED_STATUS);
 }
예제 #2
0
    /// <summary>
    /// Adds unit to the game
    /// </summary>
    /// <param name="unit">Unit to add</param>
    public void AddUnit(Transform unit)
    {
        unit.GetComponent <Unit>().UnitClicked   += OnUnitClicked;
        unit.GetComponent <Unit>().UnitDestroyed += OnUnitDestroyed;

        if (UnitAdded != null)
        {
            UnitAdded.Invoke(this, new UnitCreatedEventArgs(unit));
        }
    }
예제 #3
0
        private void TryAddUnit(int totalUnitInx, CircleUnitModel unitModel)
        {
            if (!Teams[GetTeamIndex(totalUnitInx)].TryAddUnit(unitModel as TUnit))
            {
                Debug.Log($"{unitModel.UnitId} is already exists", LogType.Warning);
                return;
            }

            UnitAdded?.Invoke(unitModel as TUnit);
        }
예제 #4
0
        public void AddUnit(UnitData unitData)
        {
            UnitData unitDataClose = Object.Instantiate(unitData);

            if (UnitAdded != null)
            {
                UnitAdded.Invoke(unitDataClose);
            }
            IUnit unit = unitDataClose.CreateUnit(_playerData, this);

            Units.Add(unit);
        }
예제 #5
0
    private T SpawnUnit <T>(Tile tile, T prototype, Action <T> onSpawn) where T : Unit
    {
        var unit = prototype == null ? new GameObject().AddComponent <T>() : GameObject.Instantiate <T>(prototype);

        unit.Removed += OnUnitRemoved;

        _units.Add(unit);

        onSpawn(unit);

        UnitAdded?.Invoke(unit);

        unit.MoveTo(tile);

        return(unit);
    }
예제 #6
0
        void Initialize()
        {
            Players = new List <Player>();
            for (int i = 0; i < PlayersParent.childCount; i++)
            {
                var player = PlayersParent.GetChild(i).GetComponent <Player>();
                if (player != null)
                {
                    if (Players.Any(x => x.PlayerNumber == player.PlayerNumber))
                    {
                        Debug.LogError($"Same PlayerNumber '{player.PlayerNumber}' in Players.");
                    }
                    Players.Add(player);
                }
                else
                {
                    Debug.LogError("Invalid object in Players Parent game object");
                }
            }
            NumberOfPlayers     = Players.Count;
            CurrentPlayerNumber = Players.Min(p => p.PlayerNumber);

            Cells = new List <Cell>();
            for (int i = 0; i < transform.childCount; i++)
            {
                var cell = transform.GetChild(i).gameObject.GetComponent <Cell>();
                if (cell != null)
                {
                    Cells.Add(cell);
                }
                else
                {
                    Debug.LogError("Invalid object in cells parent game object");
                }
            }

            foreach (var cell in Cells)
            {
                cell.CellClicked       += OnCellClicked;
                cell.CellHighlighted   += OnCellHighlighted;
                cell.CellDehighlighted += OnCellDehighlighted;
                cell.GetNeighbours(Cells);
            }

            Units = new List <Unit>();
            var unitGenerator = GetComponent <IUnitGenerator>();

            if (unitGenerator != null)
            {
                var units = unitGenerator.SpawnUnits(Cells);
                foreach (var unit in units)
                {
                    Units.Add(unit);
                    unit.UnitClicked   += OnUnitClicked;
                    unit.UnitDestroyed += OnUnitDestroyed;

                    UnitAdded?.Invoke(this, new UnitCreatedEventArgs(unit.transform));
                }
            }
            else
            {
                Debug.LogError("No IUnitGenerator script attached to cell grid");
            }
        }