Esempio n. 1
0
    public static void CreateCell(int _z, int _x)
    {
        //position
        Vector3 position;

        position.x = (_x + (_z * 0.5f) - (int)(_z * 0.5f)) * (HexMetrics.innerRadius * 2f);
        position.y = 0f;
        position.z = _z * (HexMetrics.outerRadius * 1.5f);

        Cell cell = MapConstants.cells[_z, _x] = Instantiate <Cell>(MapConstants.prefab.GetComponent <Cell>());

        cell.coordinates = HexPoint.FromOffsetCoordinates(_x, _z);


        cell.transform.SetParent(MapConstants.hexGrid, false);
        cell.transform.localPosition = position;


        //text
        //TextMeshProUGUI label = Instantiate<TextMeshProUGUI>(cellLabelPrefab);
        //label.rectTransform.SetParent(gridCanvas.transform, false);
        //label.rectTransform.anchoredPosition = new Vector2(position.x, position.z);

        //label.text = cell.coordinates.ToStringOnSeparateLines();
    }
Esempio n. 2
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
    }