Beispiel #1
0
        /// <summary>
        /// Static factory to correctly create a cursor game object.
        /// </summary>
        /// <param name="terrain">The grid mesh to be a cursor over.</param>
        /// <param name="material">The material to use on the cursor.</param>
        /// <param name="parent">The parent game object of the cursor.</param>
        /// <returns>The newly minted cursor.</returns>
        public static GridCursor Create(GridMesh terrain, Material material)
        {
            GameObject cursorObject = new GameObject("GridCursor");

            cursorObject.transform.parent = terrain.GameObject.transform;

            var cursor = cursorObject.AddComponent <GridCursor>();

            cursor.Terrain        = terrain;
            cursor.CursorMaterial = material;
            cursor.Initialize();

            return(cursor);
        }
        /// <summary>
        /// Instantiates an instance of a SafeTerrainEditor.
        /// </summary>
        /// <param name="terrain">The terrain</param>
        public SafeTerrainEditor(GridMesh terrain)
        {
            _terrain = terrain;

            // Anchor all corners, otherwise start unanchored
            _vertexAnchored = new bool[_terrain.CountX + 1, _terrain.CountZ + 1];
            for (int i = 0; i <= _terrain.CountX; ++i)
            {
                for (int j = 0; j <= _terrain.CountZ; ++j)
                {
                    _vertexAnchored[i, j] = (i == 0 || j == 0 || i == _terrain.CountX - 1 || j == _terrain.CountZ - 1) ? true : false;
                }
            }

            // All grid squares start unanchored
            _gridAnchored = new bool[_terrain.CountX, _terrain.CountZ];
            for (int i = 0; i < _terrain.CountX; ++i)
            {
                for (int j = 0; j < _terrain.CountZ; ++j)
                {
                    _gridAnchored[i, j] = false;
                }
            }
        }