Пример #1
0
    void Awake()
    {
        grid          = GetComponent <GridLayoutGroup>();
        grid.cellSize = new Vector2(200, 200);
        grid.spacing  = new Vector2(100, 100);

        HelpFunctions.DestroyChilds(transform);

        List <TextAsset> maps = SaveLoadManager.GetMaps().ToList();

        for (int i = 0; i < maps.Count; i++)
        {
            LevelButton level = Instantiate <LevelButton>(prefabLevel);
            level.SetCall(maps[i].name);

            level.Count = i;

            Transform temp = level.transform;

            temp.SetParent(transform);

            temp.localScale    = Vector3.one;
            temp.localPosition = Vector3.zero;
        }
    }
Пример #2
0
 public static void CreateSurface(int _height, int _width)
 {
     HelpFunctions.DestroyChilds(MapConstants.hexGrid);
     MapConstants.cells = new Cell[_height, _width];
     for (int z = 0; z < _height; z++)
     {
         for (int x = 0; x < _width; x++)
         {
             CreateCell(z, x);
         }
     }
 }
Пример #3
0
    /*		Cell[,] old = MapConstants.cells;
     *      int height = MapConstants.height + _height;
     *      int widht = MapConstants.width + _width];
     *      MapConstants.cells = new Cell[height, widht];
     *      for (int z = MapConstants.height; z < height; z++) {
     *              for (int x = MapConstants.width; x < widht; x++) {
     *                      CreateCell(z, x);
     *              }
     *      }*/
    public static void IncreaseSurface(int _height, int _width)
    {
        int increaseOn = _height - MapConstants.height;
        int oldheight  = MapConstants.cells.GetLength(0);

        HelpFunctions.DestroyChilds(MapConstants.hexGrid);
        MapConstants.cells = new Cell[_height, _width];
        for (int z = 0; z < _height; z++)
        {
            for (int x = 0; x < _width; x++)
            {
                CreateCell(z, x);
            }
        }
        Debug.Log(increaseOn + "\t" + oldheight);
    }
Пример #4
0
    private static void CreateGame(Transform _parent, Cell _prefab, string[] _temp)
    {
        #region Map
        HelpFunctions.DestroyChilds(_parent);                                                  //удаляем старую карту

        string[] cellsCoordinates = _temp.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); //удаление не нужных \n

        for (int z = 0, i = 0; z < MapConstants.height; z++)
        {
            for (int x = 0; x < MapConstants.width; x++, i++)
            {
                string[] param = cellsCoordinates[i].Split('|');                //отбираем позицию|поворот|размер|и материал

                Vector3    position = Vector3.zero;
                Quaternion rotation = new Quaternion();
                Vector3    scale    = Vector3.zero;


                position = HelpFunctions.Vector3FromString(param[0]);
                rotation = HelpFunctions.QuaternionFromString(param[1]);
                scale    = HelpFunctions.Vector3FromString(param[2]);
                Material material = Resources.Load(LevelMaterials + param[3], typeof(Material)) as Material;

                //Instantiate
                Cell cell = Instantiate <Cell>(_prefab);               //создание

                cell.coordinates = HexPoint.FromOffsetCoordinates(x, z);

                cell.transform.SetParent(_parent, false);
                cell.transform.localPosition = position;
                cell.transform.localRotation = rotation;
                cell.transform.localScale    = scale;
                cell.rootMaterial            = material;

                MapConstants.cells[z, x] = cell;
            }
        }
        #endregion
        #region Interface
        ProgrammingContainer container    = GameObject.FindObjectOfType <ProgrammingContainer>();
        Transform            mainFunction = container.transform;
        HelpFunctions.DestroyChilds(mainFunction);

        GameObject obj = LoadSlotByName("Slot").gameObject;
        for (int i = 0; i < MapConstants.sizeMainProgram.y; i++)
        {
            for (int j = 0; j < MapConstants.sizeMainProgram.x; j++)
            {
                Transform slot = Instantiate(obj).transform;
                slot.SetParent(mainFunction, false);
                slot.localPosition = Vector3.one;
                slot.localScale    = Vector3.one;
            }
        }
        if (MapConstants.startItems.Count != 0)
        {
            container.startItems = MapConstants.startItems;
        }
        if (MapConstants.startPrograms.Count != 0)
        {
            Transform parent = mainFunction.parent.parent;            //куда создавать програмы
            for (int i = 0; i < MapConstants.startPrograms.Count; i++)
            {
                print(MapConstants.startPrograms[i]);
                Program p = Instantiate <Program>(LoadProgramByName(MapConstants.startPrograms[i]), parent);
                //Transform program = Instantiate(p).transform;
                p.transform.localPosition = Vector3.one;
                p.transform.localScale    = Vector3.one;
            }
        }
        #endregion
    }