Exemplo n.º 1
0
        public override void MakeCells <TPoint>(
            IGrid <TPoint, TileCell> grid,
            GridMap <TPoint> map)
        {
            if (Application.isPlaying)
            {
                gameObject.transform.DestroyChildren();
            }
            else
            {
                gameObject.transform.DestroyChildrenImmediate();
            }

            cellStorage = new TileCell[grid.Points.Count()];

            var pointIndex = 0;

            foreach (var point in grid.Points)
            {
                var cell = Instantiate(prefab, gameObject);
                cell.transform.localPosition = map.GridToWorld(point);

                var spriteCellComponent = cell.GetComponent <TileCell>();
                grid[point]             = spriteCellComponent;
                cellStorage[pointIndex] = spriteCellComponent;

                pointIndex++;
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override IEnumerable <Vector3> GetNormals(IExplicitShape <GridPoint3> explicitShape, GridMap <GridPoint3> gridMap, bool flip)
        {
            var normals  = GetCellNormals().ToArray();
            var vertices = GetCellVertices().ToArray();

            return(explicitShape.Points.SelectMany(p => vertices.Select((q, i) => gridMap.GridToWorld(q + gridMap.DeRound(p) + (flip ? -normals[i] : normals[i])).normalized)));
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override IEnumerable <Vector3> GetVertices(IExplicitShape <GridPoint3> shape, GridMap <GridPoint3> map)
        {
            //var triangles = GetCellTriangles().ToArray();
            var vertices = GetCellVertices().ToArray();

            return(shape.Points.SelectMany(p => vertices.Select(q => map.GridToWorld(q + map.DeRound(p)))));
        }
Exemplo n.º 4
0
 public override IEnumerable <Vector3> GetVertices(IExplicitShape <int> shape, GridMap <int> map)
 {
     return(shape
            .Points
            .SelectMany(p => vertices[GLMathf.FloorMod((int)p, colorFunction.x0)]
                        .Select(q => map.GridToWorld(q + map.DeRound(p)))));
 }
Exemplo n.º 5
0
 public override IEnumerable <Vector3> GetVertices(IExplicitShape <GridPoint3> shape, GridMap <GridPoint3> map)
 {
     return(shape
            .Points
            .SelectMany(p => vertices[p.GetColor(colorFunction)]
                        .Select(q => map.GridToWorld(q + map.DeRound(p)))));
 }
Exemplo n.º 6
0
 public override IEnumerable <Vector3> GetNormals(IExplicitShape <GridPoint3> explicitShape, GridMap <GridPoint3> gridMap, bool flip)
 {
     return(explicitShape
            .Points
            .SelectMany(p => vertices[p.GetColor(colorFunction)]
                        .Select((q, i) => gridMap.GridToWorld(q + gridMap.DeRound(p) + (flip ? -normals[p.GetColor(colorFunction)][i] : normals[p.GetColor(colorFunction)][i])).normalized)));
 }
Exemplo n.º 7
0
 public override IEnumerable <Vector3> GetNormals(IExplicitShape <int> shape, GridMap <int> map, bool flip)
 {
     return(shape
            .Points
            .SelectMany(p => vertices[GLMathf.FloorMod(p, colorFunction.x0)]
                        .Select((q, i) => map.GridToWorld(q + map.DeRound(p) + (flip ? -normals[GLMathf.FloorMod(p, colorFunction.x0)][i] : normals[GLMathf.FloorMod(p, colorFunction.x0)][i])).normalized)));
 }
Exemplo n.º 8
0
        private static void UpdateOrientation <TPoint, TCell>(
            IGrid <TPoint, TCell> grid,
            GridMap <TPoint> map,
            TPoint point)

            where TCell : MonoBehaviour
        {
            var cell = grid[point];

            var newForward = map.GridToWorld(map.DeRound(point) + new Vector3(0, 0, 1)) - cell.transform.localPosition;

            cell.transform.forward = newForward;

            var newRight = map.GridToWorld(map.DeRound(point) + new Vector3(1, 0, 0)) - cell.transform.localPosition;

            cell.transform.right = newRight;

            var newUp = map.GridToWorld(map.DeRound(point) + new Vector3(0, 1, 0)) - cell.transform.localPosition;

            cell.transform.right = newUp;
        }
Exemplo n.º 9
0
        private static TCell InitCell <TPoint, TCell>(
            GridMap <TPoint> map,
            TCell cellPrefab,
            GameObject gridRoot,
            Action <TPoint, TCell> initCellAction,
            TPoint point)

            where TCell : MonoBehaviour
        {
            var cell = GLMonoBehaviour.Instantiate(cellPrefab, gridRoot);

            cell.transform.localPosition = map.GridToWorld(point);

            initCellAction(point, cell);

            return(cell);
        }
Exemplo n.º 10
0
 public override IEnumerable <Vector3> GetVertices(IExplicitShape <int> shape, GridMap <int> map)
 {
     return(shape.Points.SelectMany(p => vertices.Select(q => map.GridToWorld(q + map.DeRound(p)))));
 }