Пример #1
0
    private List <T> Prepare <T> (int rate, FieldCellType division)
        where T : MonoBehaviour
    {
        // Hold our type
        Type type = typeof(T);

        // Check if the wanted number is less than what the division provides
        if (rate >= this.caveGenerator.FindDivision(division).Count)
        {
            throw new Exception("Catched Bug: " + type.ToString() + " number can't outnumber the division cells number!");
        }
        // Create a source list for these objects
        this.source.Add(type, new List <T>());
        // Create a container
        Transform container = (new GameObject("_" + type.ToString() + " Container")).transform;

        container.SetParent(this.transform);
        // Retrieve resource list from the resource manager
        List <T> prefab = this.subResource.FindResources <T>();

        // Check if there are prefabs
        if (prefab.Count == 0)
        {
            return(null);
        }
        // Instantiating operation
        this.source[type] = this.caveGenerator.Instantiate <T>(division, prefab, rate);
        // Append those instantiated objects to the container
        foreach (T item in this.SourceList <T>())
        {
            item.transform.SetParent(container);
        }
        // Return the list in case if u wanna add some additional functionalities
        return(this.SourceList <T>());
    }
Пример #2
0
        public FieldCell(FieldCellType type, int cx, int cy)
        {
            this.type = type;

            slotIndex = -1;
            SetCell(cx, cy);
        }
        public FieldCell(FieldCellType type, int cx, int cy)
        {
            this.type = type;

            slotIndex = -1;
            SetCell(cx, cy);
        }
Пример #4
0
 public FieldCell(Field field, int x, int y, FieldCellType type) : this()
 {
     Field = field;
     X     = x;
     Y     = y;
     Type  = type;
 }
Пример #5
0
    public List <T> Instantiate <T>(FieldCellType division, List <T> prefabs, int number)
        where T : MonoBehaviour
    {
        List <T> output = new List <T>();
        T        prefab;

        for (int i = 0; (i < prefabs.Count) && (number > 0); i++)
        {
            // Get prefab randomly
            prefab = prefabs[UnityEngine.Random.Range(0, prefabs.Count)];

            // Quantity of this prefab
            int q = (i == prefabs.Count - 1) ? number : UnityEngine.Random.Range(0, number);

            if (prefab == null)
            {
                throw new Exception("Incorrect prefab!");
            }

            foreach (T ins in this.Instantiate <T>(division, prefab, q))
            {
                output.Add(ins); // Add instance to the output list
            }
            // Update total number
            number -= q;
        }

        return(output);
    }
Пример #6
0
 public FieldCell(Field field, int x, int y, FieldCellType type)
     : this()
 {
     Field = field;
     X = x;
     Y = y;
     Type = type;
 }
Пример #7
0
    // Retrieving the list of cells which belong to a specific division
    public List <FieldCell> FindDivision(FieldCellType divison)
    {
        if (!this.divisions.ContainsKey(divison))
        {
            throw new Exception("Catched Error: This divison does not exists!");
        }

        return(this.divisions[divison]);
    }
Пример #8
0
 // Give the cell some components
 public void AddComponent(FieldCellType cellType, Type component)
 {
     foreach (FieldCell fc in this.divisions[cellType])
     {
         if (fc.gameObject.GetComponent(component) == null)
         {
             fc.gameObject.AddComponent(component);
         }
     }
 }
Пример #9
0
    // Colorize cells based on their type (TESTIN METHOD)
    public void Colorize(FieldCellType cellType, Color color)
    {
        if (this.divisions.Count == 0)
        {
            throw new Exception("There are no divisions");
        }

        foreach (FieldCell cell in this.divisions[cellType])
        {
            cell.SetSpriteRendererColor(color);
        }
    }
Пример #10
0
    public List <FieldCell> FindWalkableCells(FieldCellType division)
    {
        // Output
        List <FieldCell> filter = new List <FieldCell>();

        // Loop through
        foreach (FieldCell fc in this.walkable)
        {
            if (fc.Type == division)
            {
                filter.Add(fc);
            }
        }
        // Return
        return(filter);
    }
Пример #11
0
    // For creating objects randomly
    public List <T> Instantiate <T> (FieldCellType division, T prefab, int number)
        where T : MonoBehaviour
    {
        if (this.divisions[division].Count == 0)
        {
            return(null);
        }
        // Declaration
        List <T>  source  = new List <T>();
        int       counter = 0;
        FieldCell cell;

        // Operation
        while (counter < number)
        {
            do
            {
                int index = UnityEngine.Random.Range(0, this.divisions[division].Count);
                // Get a random cell
                cell = this.divisions[division][index];
            }while(!cell.IsWalkable && this.FindWalkableCells(division).Count > 0);
            // If the cell is still null after the research well we don't neet to waste time
            if (cell == null)
            {
                break;
            }
            // Instantiate
            T go = GameObject.Instantiate(prefab, cell.Position.ToVector2(), Quaternion.identity);
            // Unmark this cell as walkable
            this.MarkCellAsUnwalkable(cell);
            // Add object to the list
            source.Add(go);
            // Nullify cell
            cell = null;

            counter++;
        }
        // Return output
        return(source);
    }
 /// <summary>
 /// конструктор
 /// </summary>
 public FieldCell()
 {
     cellType  = FieldCellType.EMPTY;
     step      = 0;
     isVisited = false;
 }
Пример #13
0
 public MovableCell(FieldCellType type, int cx, int cy)
     : base(type, cx, cy)
 {
     m_direction    = Direction.DOWN;
     m_oldDirection = Direction.DOWN;
 }
Пример #14
0
 public FieldCell(FieldCellType type, int minesAround)
 {
     Type        = type;
     MinesAround = minesAround;
 }
 public MovableCell(FieldCellType type, int cx, int cy)
     : base(type, cx, cy)
 {
     m_direction = Direction.DOWN;
     m_oldDirection = Direction.DOWN;
 }