예제 #1
0
    //Constructor for Grid
    public Pattern(int width, int height, float cellSize, Vector3 originPosition, Sprite sprite, Color color)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;
        this.sprite         = sprite;
        this.color          = color;

        gridArray      = new int[width, height];
        flagGridArray  = new int[width, height];
        debugTextArray = new TextMesh[width, height];
        SpriteArray    = new GameObject[width, height];
        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                randomNumber = Random.Range(1, 9);
                countNumber[randomNumber] += 1;
                gridArray[x, y]            = randomNumber;

                debugTextArray[x, y] = UtilsClass.CreateWorldText(randomNumber.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 20, Color.white, TextAnchor.MiddleCenter);

                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                SpriteArray[x, y] = UtilsClass.CreateWorldSprite(gridArray[x, y].ToString(), sprite, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(20f, 20f), 0, Color.red);
            }
        }

        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }
예제 #2
0
    //Constructor for Number Status;
    public Pattern(int width, int height, float cellSize, Vector3 originPosition, int[] countNumber)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;
        this.countNumber    = countNumber;

        gridArray = new int[width, height];

        debugTextArray = new TextMesh[width, height];
        SpriteArray    = new GameObject[width, height];
        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                if (y == 0)
                {
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(countNumber[x + 1].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 10, Color.white, TextAnchor.MiddleCenter);
                }
                else
                {
                    debugTextArray[x, y] = UtilsClass.CreateWorldText((x + 1).ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 10, Color.white, TextAnchor.MiddleCenter);
                }


                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
            }
        }

        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }
예제 #3
0
    public void Calculate_H_Costs()
    {
        //Finds H's for all the grids
        char _ = 'A';

        for (int i = 0; i < grid.gridArray.GetLength(0); i++)
        {
            for (int j = 0; j < grid.gridArray.GetLength(1); j++)
            {
                float  cost_ = Calculate_H_Cost(i, j);
                string cost  = cost_.ToString();

                Vector3 Pos  = grid.GetWorldPosition(i, j);
                float   size = grid.GetCellSize();
                HCost[i, j] = UtilsClass.CreateWorldText(cost, null, Pos + new Vector3(0, size / 2, 100), 25, Color.red);
                grid.gridArray[i, j].HCost = int.Parse(cost);
                grid.gridArray[i, j].name  = _;
                LookUpTable.Add(_, new Vector2(i, j));
                UtilsClass.CreateWorldText(_.ToString(), null, Pos + new Vector3(size / 2, 3, 100), 20, Color.white);
                _ = (char)((int)_ + 1);


                if (cost_ != 1000000)
                {
                    grid.gridArray[i, j].MySprite.GetComponent <SpriteRenderer>().sprite = State_Colors[0];
                }
                else
                {
                    grid.gridArray[i, j].MySprite.GetComponent <SpriteRenderer>().sprite = State_Colors[4];
                }
            }
        }
    }
예제 #4
0
    public UIGrid(int _width, int _height, float _celZise, Vector3 _originPosition)
    {
        this.width          = _width;
        this.height         = _height;
        this.cellSize       = _celZise;
        this.originPosition = _originPosition;

        gridArray      = new int[width, height];
        debugTextArray = new TextMesh[width, height];

        // GetLength return the length of the dimension given
        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 20, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
            }
        }

        // draw the end lines
        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

        SetValue(2, 1, 56);
    }
예제 #5
0
        /*
         * 畫格線
         */
        public Grid(int width, int height, float cellSize, Vector3 originPosition)
        {
            this.width          = width;                   //格子X座標
            this.height         = height;                  //格子Y座標
            this.cellSize       = cellSize;                //格子寬度
            this.originPosition = originPosition;          //這個陣列的原點

            gridArray       = new int[width, height];      //new一個存放格子座標的陣列
            debugTextMeshes = new TextMesh[width, height]; //格子內的數字

            //歷遍陣列
            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    //生成TextMesh,透過UtilsClass.CreateWorldText設定Mesh內容、位置、大小、顏色等
                    debugTextMeshes[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 20, Color.yellow,
                                                                       TextAnchor.MiddleCenter);
                    //畫出格線
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }
            //畫出剩下兩條格線
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
        }
예제 #6
0
    private void CreateDebugText()
    {
        debugTextMesh = new TextMesh[bounds.size.x, bounds.size.y];
        Vector3 worldPosition;

        for (int x = bounds.xMin, i = 0; x < bounds.xMax; x++, i++)
        {
            for (int y = bounds.yMin, j = 0; y < bounds.yMax; y++, j++)
            {
                worldPosition = tilemapsGrid.CellToWorld(new Vector3Int(x, y, 0));
                Vector3 cellCenterPosition = worldPosition + new Vector3(tilemapsGrid.cellSize.x / 2, tilemapsGrid.cellSize.y / 2);
                if (drawText)
                {
                    debugTextMesh[i, j] = UtilsClass.CreateWorldText(x + "," + y, null, cellCenterPosition, 20, Color.white, TextAnchor.MiddleCenter, TextAlignment.Center, "DebugTextOnGround", 5);
                }
                if (drawGrid)
                {
                    Debug.DrawLine(worldPosition, worldPosition + new Vector3(tilemapsGrid.cellSize.x, 0), Color.white, 400f);
                    Debug.DrawLine(worldPosition, worldPosition + new Vector3(0, tilemapsGrid.cellSize.y), Color.white, 400f);
                }
            }
        }
        if (drawGrid)
        {
            worldPosition = tilemapsGrid.CellToWorld(new Vector3Int(bounds.xMax, bounds.yMin, 0));
            Debug.DrawLine(worldPosition, worldPosition + new Vector3(0, bounds.size.y * tilemapsGrid.cellSize.y), Color.white, 400f);
            worldPosition = tilemapsGrid.CellToWorld(new Vector3Int(bounds.xMin, bounds.yMax, 0));
            Debug.DrawLine(worldPosition, worldPosition + new Vector3(bounds.size.x * tilemapsGrid.cellSize.x, 0), Color.white, 400f);
        }
    }
예제 #7
0
        public Grid(int width, int height, float cellSize, Vector3 originPosition)
        {
            this.width          = width;
            this.height         = height;
            this.cellSize       = cellSize;
            this.originPosition = originPosition;

            gridArray = new int[width, height];

            bool showDebug = false;

            if (showDebug)
            {
                TextMesh[,] debugTextArray = new TextMesh[width, height];

                for (int x = 0; x < gridArray.GetLength(0); x++)
                {
                    for (int y = 0; y < gridArray.GetLength(1); y++)
                    {
                        debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                    }
                }
                Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

                OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) =>
                {
                    debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y].ToString();
                };
            }
        }
예제 #8
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray = new TGridObject[width, height];


        if (SHOW_DEBUG)
        {
            debugTextArray = new TextMesh[width, height];
            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 40, Color.white, TextAnchor.MiddleCenter);
                    debugTextArray[x, y].characterSize = 0.07f;
                    debugTextArray[x, y].GetComponent <MeshRenderer>().sortingLayerName = "Text";
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
        }
    }
예제 #9
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray = new int[width, height];

        stringGrid = new string[width, height];

        bool showDebug = true;

        if (showDebug)
        {
            TextMesh[,] debugTextArray = new TextMesh[width, height];

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int z = 0; z < gridArray.GetLength(1); z++)
                {
                    debugTextArray[x, z] = UtilsClass.CreateWorldText(stringGrid[x, z], null, GetWorldPosition(x, z) + new Vector3(cellSize, 0, cellSize) * .5f, 300, Color.black, TextAnchor.MiddleCenter);
                    Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x, z + 1), Color.black, 100f);
                    Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x + 1, z), Color.black, 100f);
                }
            }
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.black, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.black, 100f);

            OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) => {
                debugTextArray[eventArgs.x, eventArgs.z].text = stringGrid[eventArgs.x, eventArgs.z];
            };
        }
    }
예제 #10
0
    private TextMesh[,] debugTextArray; //debug purposes


    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray = new TGridObject[width, height];

        bool showDebug = true;

        if (showDebug)
        {
            debugTextArray = new TextMesh[width, height];

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    //Debug.Log(x + "," + y);
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 20, Color.white, TextAnchor.MiddleCenter);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }

            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
        }
        //SetValue(2, 1, 56);
    }
예제 #11
0
    public GridBase(int width, int height, float cellSize = 10f, Vector3 origin = default, bool showDebug = true)
    {
        Width          = width;
        Height         = height;
        CellSize       = cellSize;
        OriginPosition = origin;
        this.showDebug = showDebug;

        gridArray      = new T[Width, Height];
        debugTextArray = new TextMesh[Width, Height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                if (gridArray[x, y] == null && !typeof(T).IsValueType)
                {
                    if (DefaultConstructor != null)
                    {
                        gridArray[x, y] = (T)DefaultConstructor.Invoke(new object[] { this, x, y });
                    }
                    else
                    {
                        gridArray[x, y] = new T();
                    }
                }

                if (this.showDebug)
                {
                    var worldPosition = CellToWorld(x, y);

                    debugTextArray[x, y] = UtilsClass.CreateWorldText(
                        text: gridArray[x, y].ToString(),
                        parent: null,
                        localPosition: worldPosition + new Vector3(cellSize, cellSize) * 0.5f,
                        fontSize: 20,
                        color: Color.white,
                        textAnchor: TextAnchor.MiddleCenter
                        );

                    Debug.DrawLine(worldPosition, CellToWorld(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(worldPosition, CellToWorld(x + 1, y), Color.white, 100f);
                }
            }
        }

        if (showDebug)
        {
            Debug.DrawLine(CellToWorld(0, height), CellToWorld(width, height), Color.white, 100f);
            Debug.DrawLine(CellToWorld(width, 0), CellToWorld(width, height), Color.white, 100f);
        }
    }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width">Width of the grid</param>
        /// <param name="height">Height of the grid</param>
        /// <param name="cellSize">Each cells size on world space</param>
        /// <param name="originPosition">Where the grid should be placed</param>
        /// <param name="createGridObject">How should I create this value?</param>
        /// <param name="showDebug">Enable built-in debug text?</param>
        /// <param name="debugColor">Color of the built-in debug text</param>
        /// <param name="fontSize">Size of the debug text (which uses ToString() of the class)</param>
        public Grid(int width, int height, float cellSize, Vector2 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject, bool showDebug = false, Color?debugColor = null, int fontSize = 20)
        {
            this.width          = width;
            this.height         = height;
            this.cellSize       = cellSize;
            this.originPosition = originPosition;
            this.showDebug      = showDebug;

            this.createGridObject = createGridObject;

            gridArray = new TGridObject[width, height];

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    gridArray[x, y] = createGridObject(this, x, y);
                }
            }

            if (showDebug)
            {
                debugTextArray = new TextMesh[width, height];

                if (debugColor == null)
                {
                    debugColor = Color.black;
                }

                for (int x = 0; x < gridArray.GetLength(0); x++)
                {
                    for (int y = 0; y < gridArray.GetLength(1); y++)
                    {
                        debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector2(cellSize, cellSize) * 0.5f, fontSize, debugColor, textAnchor: TextAnchor.MiddleCenter);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), (Color)debugColor, float.MaxValue);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), (Color)debugColor, float.MaxValue);
                    }
                }

                Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), (Color)debugColor, float.MaxValue);
                Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), (Color)debugColor, float.MaxValue);

                OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) =>
                {
                    debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y]?.ToString();
                };
            }
        }
    public Grid(int width, int height)
    {
        this.width  = width;
        this.height = height;

        gridArray = new int[width, height];
        //passa por todos os elementos de colina
        for (int gridX = 0; gridX < gridArray.GetLength(0); gridX++)
        {
            //passa por todos os elementos de linha dentro da coluna
            for (int gridY = 0; gridY < gridArray.GetLength(1); gridY++)
            {
                UtilsClass.CreateWorldText();
            }
        }
    }
예제 #14
0
    public void A_Star_Start()
    {
        List <char> StartingRoad = new List <char>();

        StartingRoad.Add(GetGridCharXY((int)StartPos.x, (int)StartPos.y));
        Queue.Add(new QueueElementAStar(0 + grid.gridArray[(int)StartPos.x, (int)StartPos.y].HCost, GetGridCharXY(StartPos.x, StartPos.y), StartingRoad));
        Vector3 Pos = grid.GetWorldPosition((int)StartPos.x, (int)StartPos.y);

        FCost[(int)StartPos.x, (int)StartPos.y] = UtilsClass.CreateWorldText((0 + grid.gridArray[(int)StartPos.x, (int)StartPos.y].HCost).ToString(), null, Pos + new Vector3(7, 2, 100), 20, Color.white);
        grid.gridArray[(int)StartPos.x, (int)StartPos.y].G_Cost = 0;
        GCost[(int)StartPos.x, (int)StartPos.y] = UtilsClass.CreateWorldText((0).ToString(), null, Pos + new Vector3(7, 7, 100), 20, Color.yellow);



        Debug.Log("The END IS AT CHARACTER " + GetGridCharXY((int)EndPos.x, (int)EndPos.y));
    }
예제 #15
0
파일: CMDebug.cs 프로젝트: RoscaS/YAARTS
    // Creates a Button in the UI
    // public static UI_Sprite ButtonUI(Vector2 anchoredPosition, string text, Action ClickFunc) {
    // return UI_Sprite.CreateDebugButton(anchoredPosition, text, ClickFunc);
    // }

    // Creates a World Text object at the world position
    public static void Text(string text, Vector3 localPosition = default(Vector3),
                            Transform parent            = null, int fontSize = 40, Color?color = null,
                            TextAnchor textAnchor       = TextAnchor.UpperLeft,
                            TextAlignment textAlignment = TextAlignment.Left,
                            int sortingOrder            = UtilsClass.sortingOrderDefault)
    {
        UtilsClass.CreateWorldText(
            text,
            parent,
            localPosition,
            fontSize,
            color,
            textAnchor,
            textAlignment,
            sortingOrder
            );
    }
예제 #16
0
 /// <summary>
 /// Display coordinates on given tilemap for each tile
 /// </summary>
 /// <param name="map"></param>
 /// <param name="fontSize"></param>
 /// <param name="color"></param>
 void DisplayMapCoord(Tilemap map, Color color, int fontSize = 15)
 {
     foreach (var pos in map.cellBounds.allPositionsWithin)
     {
         // loop through tiles in tileMaps[0]
         List <Vector3> tileWorldLocations = new List <Vector3>();
         Vector3Int     localPlace         = new Vector3Int(pos.x, pos.y, pos.z);
         Vector3        place = tilemaps["EnvironmentMap"].CellToWorld(localPlace);
         if (tilemaps["EnvironmentMap"].HasTile(localPlace))
         {
             tileWorldLocations.Add(place);
             TextMesh txt = UtilsClass.CreateWorldText(pos.x.ToString() + ", " + pos.y.ToString(), map.transform,
                                                       place, fontSize, color, TextAnchor.MiddleCenter);
             txt.transform.localScale += new Vector3(-0.7f, -0.7f, -0.7f);
         }
     }
 }
예제 #17
0
    private TGridObject[,] gridArray;//multi dimensional array
    //private int[,] gridArray;
    //private TextMesh[,] debugTextArray;//debug purposes


    public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        //gridArray = new TGridObject[width, height];
        gridArray = new TGridObject[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y] = createGridObject(this, x, y);
            }
        }

        bool showDebug = false;

        if (showDebug)
        {
            TextMesh[,] debugTextArray = new TextMesh[width, height];//multi dimensional array

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    //Debug.Log(x + "," + y);
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 20, Color.white, TextAnchor.MiddleCenter);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }

            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

            OnGridObjectChanged += (object sender, OnGridObjectChangedEventArgs eventArgs) => {
                debugTextArray [eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y]?.ToString();
            };
        }
        //SetValue(2, 1, 56);
    }
예제 #18
0
        //Func<Grid<TGridObject>, int,int, TGridObject> : Une fonction en entrée qui a comme param une grid, un int (x), un int (y), et renvoie une grid
        public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject)
        {
            this.width          = width;
            this.height         = height;
            this.cellSize       = cellSize;
            this.originPosition = originPosition;

            gridArray = new TGridObject[width, height];

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    gridArray[x, y] = createGridObject(this, x, y); // Permet d'instancier chaque cellule sans connaître à l'avance le type
                }
            }

            bool showDebug = true;

            if (showDebug)
            {
                TextMesh[,] debugTextArray = new TextMesh[width, height];

                for (int x = 0; x < gridArray.GetLength(0); x++)
                {
                    for (int y = 0; y < gridArray.GetLength(1); y++)
                    {
                        debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                    }
                }
                Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

                OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) =>
                {
                    debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y].ToString();
                };
            }
        }
예제 #19
0
        public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject)
        {
            _width          = width;
            _height         = height;
            _cellSize       = cellSize;
            _originPosition = originPosition;

            _gridArray = new TGridObject[_width, _height];

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    _gridArray[x, y] = createGridObject(this, x, y);
                }
            }

            bool showDebug = false;

            if (showDebug)
            {
                TextMesh[,] debugTextArray = new TextMesh[_width, _height];

                for (int x = 0; x < _gridArray.GetLength(0); x++)
                {
                    for (int y = 0; y < _gridArray.GetLength(1); y++)
                    {
                        debugTextArray[x, y] = UtilsClass.CreateWorldText(_gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 20, Color.white,
                                                                          TextAnchor.MiddleCenter);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                        Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                    }
                }

                Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

                OnGridValueChanged += (sender, eventArgs) => { debugTextArray[eventArgs.X, eventArgs.Y].text = _gridArray[eventArgs.X, eventArgs.Y]?.ToString(); };
            }
        }
예제 #20
0
파일: MyGrid.cs 프로젝트: eliasduda/Pro3
    public bool debug = true;           //aktiviert debug ausgabe

    public MyGrid(int width, int height, float cellSize, Vector3 origin, Func <MyGrid <MyGridObject>, int, int, MyGridObject> createGridObject)
    {
        this.width    = width;
        this.height   = height;
        this.cellSize = cellSize;
        this.origin   = origin;

        gridArray      = new MyGridObject[width, height];
        debugTextArray = new TextMesh[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++) //initialisierung aller gridobjekte
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y] = createGridObject(this, x, y);
            }
        }

        //grid wird gezeichnet und beschriftet --debug
        if (debug)
        {
            for (int i = 0; i < gridArray.GetLength(0); i++)
            {
                for (int j = 0; j < gridArray.GetLength(1); j++)
                {
                    debugTextArray[i, j] = UtilsClass.CreateWorldText(gridArray[i, j]?.ToString(), null, IsoMatrix.Iso(GetWorldPosition(i, j) + new Vector3(cellSize, cellSize) * 0.5f), 20, Color.white, TextAnchor.MiddleCenter);
                    Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(i, j)), IsoMatrix.Iso(GetWorldPosition(i, j + 1)), Color.white, 100f);
                    Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(i, j)), IsoMatrix.Iso(GetWorldPosition(i + 1, j)), Color.white, 100f);
                }
            }
            Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(0, height)), IsoMatrix.Iso(GetWorldPosition(width, height)), Color.white, 100f);
            Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(width, 0)), IsoMatrix.Iso(GetWorldPosition(width, height)), Color.white, 100f);

            //triggert mit dem event eine Änderung des texts im debugarray falls sich ein gridobject geändert hat
            OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) =>
            {
                debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y].ToString();
            };
        }
    }
예제 #21
0
    public GridXZ(int width, int height, float cellSize, Vector3 originPosition, Func <GridXZ <TGridObject>, int, int, TGridObject> createGridObject)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray = new TGridObject[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int z = 0; z < gridArray.GetLength(1); z++)
            {
                gridArray[x, z] = createGridObject(this, x, z);
            }
        }

        bool showDebug = true;

        if (showDebug)
        {
            TextMesh[,] debugTextArray = new TextMesh[width, height];

            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int z = 0; z < gridArray.GetLength(1); z++)
                {
                    debugTextArray[x, z] = UtilsClass.CreateWorldText(gridArray[x, z]?.ToString(), null, GetWorldPosition(x, z) + new Vector3(cellSize, 0, cellSize) * .5f, 15, Color.white, TextAnchor.MiddleCenter, TextAlignment.Center);
                    Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x, z + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x + 1, z), Color.white, 100f);
                }
            }
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

            OnGridObjectChanged += (object sender, OnGridObjectChangedEventArgs eventArgs) => {
                debugTextArray[eventArgs.x, eventArgs.z].text = gridArray[eventArgs.x, eventArgs.z]?.ToString();
            };
        }
    }
예제 #22
0
    public PathGrid(int width, int height, float cellSize, Vector3 origin, Func <PathGrid <TPathGridObject>, int, int, TPathGridObject> createGridObject)
    {
        this.width    = width;
        this.height   = height;
        this.cellSize = cellSize;
        this.origin   = origin;

        pathGridArray = new TPathGridObject[width, height];

        for (int x = 0; x < pathGridArray.GetLength(0); x++)
        {
            for (int y = 0; y < pathGridArray.GetLength(1); y++)
            {
                pathGridArray[x, y] = createGridObject(this, x, y);
            }
        }

        bool showDebug = false;

        if (showDebug)
        {
            TextMesh[,] debugTextArray = new TextMesh[width, height];

            for (int x = 0; x < pathGridArray.GetLength(0); x++)
            {
                for (int y = 0; y < pathGridArray.GetLength(1); y++)
                {
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(pathGridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, (int)(5 * cellSize), Color.white, TextAnchor.MiddleCenter);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);

            OnPathGridObjectChanged += (object sender, OnPathGridObjectChangedEventArgs eventArgs) => {
                debugTextArray[eventArgs.x, eventArgs.y].text = pathGridArray[eventArgs.x, eventArgs.y]?.ToString();
            };
        }
    }
예제 #23
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.height         = height;
        this.width          = width;
        this.cellSize       = cellSize;
        gridArray           = new int[width, height];
        debugTextArray      = new TextMesh[width, height];
        this.originPosition = originPosition;


        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.clear, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.black, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.black, 100f);
            }
        }
        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.black, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.black, 100f);
    }
예제 #24
0
    public Grid(int width, int height, float cellSize)
    {
        this.width    = width;
        this.height   = height;
        this.cellSize = cellSize;

        gridArray      = new int[width, height];
        debugTextArray = new TextMesh[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosistion(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 5, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosistion(x, y), GetWorldPosistion(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosistion(x, y), GetWorldPosistion(x + 1, y), Color.white, 100f);
            }
        }
        Debug.DrawLine(GetWorldPosistion(0, height), GetWorldPosistion(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosistion(width, 0), GetWorldPosistion(width, height), Color.white, 100f);

        SetValue(2, 1, 56);
    }
예제 #25
0
        public Grid(int width, int height, float cellSize, Vector3 originPosition)
        {
            _width          = width;
            _height         = height;
            _cellSize       = cellSize;
            _originPosition = originPosition;

            _gridArray      = new int [width, height];
            _debugTextArray = new TextMesh[width, height];

            Debug.Log($"Grid - width: {width} height: {height}");

            for (var x = 0; x < _gridArray.GetLength(0); ++x)
            {
                for (var y = 0; y < _gridArray.GetLength(1); ++y)
                {
                    // Debug.Log($"x:  {x} y: {y}");

                    _debugTextArray[x, y] =
                        UtilsClass.CreateWorldText(
                            _gridArray[x, y].ToString(),
                            null,
                            GetWorldPosition(x, y) + new Vector3(_cellSize, _cellSize) * 0.5f,
                            20,
                            Color.white,
                            TextAnchor.MiddleCenter);

                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100.0f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100.0f);
                }
            }

            Debug.DrawLine(GetWorldPosition(0, _height), GetWorldPosition(_width, _height), Color.white, 100.0f);
            Debug.DrawLine(GetWorldPosition(_width, 0), GetWorldPosition(_width, _height), Color.white, 100.0f);

            SetValue(2, 1, 56);
        }
예제 #26
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray      = new TGridObject[width, height];
        debugTextArray = new TextMesh[width, height];
        // Debug.Log(width + "" + height);

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y] = createGridObject(this, x, y);
            }
        }
        // set to true to display graphical information
        bool showDebug = true;

        if (showDebug)
        {
            for (int x = 0; x < gridArray.GetLength(0); x++)
            {
                for (int y = 0; y < gridArray.GetLength(1); y++)
                {
                    debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 40, Color.white, TextAnchor.MiddleCenter);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.black, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.black, 100f);
                }
            }
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.black, 100f);
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.black, 100f);
        }
        // SetValue(2, 1, 56);
    }
예제 #27
0
    // Start is called before the first frame update
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray      = new int[width, height];
        debugTextArray = new TextMesh[width, height];

        Debug.Log(width + " " + height);

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int z = 0; z < gridArray.GetLength(1); z++)
            {
                debugTextArray[x, z] = UtilsClass.CreateWorldText(gridArray[x, z].ToString(), null, GetWorldPosition(x, z) + new Vector3(cellSize, 0, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x, z + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, z), GetWorldPosition(x + 1, z), Color.white, 100f);
            }
        }
        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }
예제 #28
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;

        gridArray      = new Cell[width, height];
        debugTextArray = new TextMesh[width, height];


        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y]      = new Cell(Cell.CellType.Grass, x, y, true); //初始地形默认为草地
                debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].GetValue().ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 8, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
            }
        }
        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }
예제 #29
0
    public Grid(int width, int height, float cellSize, Vector3 originPosition)
    {
        this.height         = height;
        this.width          = width;
        this.originPosition = originPosition;
        this.cellSize       = cellSize;

        gridArray      = new int[width, height];
        debugTextArray = new TextMesh[width, height];

        for (int i = 0; i < gridArray.GetLength(0); i++)
        {
            for (int z = 0; z < gridArray.GetLength(1); z++)
            {
                debugTextArray[i, z] = UtilsClass.CreateWorldText(gridArray[i, z].ToString(), null, getWorldPosition(i, z) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(getWorldPosition(i, z), getWorldPosition(i, z + 1), Color.white, 100f);
                Debug.DrawLine(getWorldPosition(i, z), getWorldPosition(i + 1, z), Color.white, 100f);
            }
        }
        Debug.DrawLine(getWorldPosition(0, height), getWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(getWorldPosition(width, 0), getWorldPosition(width, height), Color.white, 100f);

        // setValue(2, 1, 56);
    }
예제 #30
0
파일: Grid.cs 프로젝트: iliescu6/MazeTest
    public Grid(int width, int height, GameObject prefab, float cellSize, Transform originPosition, Func <Grid <Template>, int, int, Template> createGridObject)
    {
        this.width         = width;
        this.height        = height;
        this.cellSize      = cellSize;
        this.originPostion = originPostion;
        gridArray          = new Template[width, height];

        debugGrid = new TextMeshPro[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y] = createGridObject(this, x, y);//default(Template);
                GameObject.Instantiate(prefab, GetWorldPosition(x, y), Quaternion.identity);
                debugGrid[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
            }
        }
        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }