Exemple #1
0
        /// <summary>
        /// Draws the surface route.
        /// </summary>
        /// <param name="goalPosition">The position of the lemming spawn point.</param>
        /// <param name="route">The surfaces in the route.</param>
        /// <param name="goalPosition">The position of the goal.</param>
        public void DrawRoute(Vector3 startPosition, int[] route, Vector3 goalPosition)
        {
            if (visible)
            {
                if (routeContainer == null)
                {
                    routeContainer = ObjectUtil.CreateNewObject("Route");
                }
                for (int i = -1; i < route.Length; i++)
                {
                    GameObject   lineObject    = ObjectUtil.CreateNewObject("Line", routeContainer);
                    LineRenderer line          = lineObject.AddComponent <LineRenderer>();
                    Vector3      start         = i >= 0 ? GetSurfaceCenter(route[i]) : startPosition;
                    Vector3      end           = i < route.Length - 1 ? GetSurfaceCenter(route[i + 1]) : goalPosition;
                    Vector3[]    linePositions = new Vector3[] { start, end };
                    for (int j = 0; j < linePositions.Length; j++)
                    {
                        line.SetPosition(j, linePositions[j]);
                    }
                    line.SetVertexCount(linePositions.Length);

                    line.material = routeMaterial;
                    line.SetWidth(routeWidth, routeWidth);
                }
            }
        }
        /// <summary>
        /// Initializes the object.
        /// </summary>
        private void Start()
        {
            logger        = LevelLogger.instance;
            pathContainer = ObjectUtil.CreateNewObject("Paths");
            pathMaterial  = new Material(Shader.Find("Particles/Additive"));

            if (logFile != null)
            {
                visible = true;
            }
        }
Exemple #3
0
 /// <summary>
 /// Creates the walls in the level.
 /// </summary>
 /// <param name="wallInput">JSON data for the walls in the level.</param>
 private void CreateWalls(List <WallInput> wallInput)
 {
     wallContainer = ObjectUtil.CreateNewObject("Walls");
     foreach (WallInput wall in wallInput)
     {
         Vector3        direction    = wall.endpoints[1] - wall.endpoints[0];
         Vector3        ortho        = VectorUtil.GetOrthonormal(direction) * wallThickness / 2;
         List <Vector3> wallPoints   = new List <Vector3>(4);
         Vector3        heightOffset = Vector3.up * wallHeight / 2;
         wallPoints.Add(wall.endpoints[0] + ortho + heightOffset);
         wallPoints.Add(wall.endpoints[0] - ortho + heightOffset);
         wallPoints.Add(wall.endpoints[1] - ortho + heightOffset);
         wallPoints.Add(wall.endpoints[1] + ortho + heightOffset);
         PlatformInput wallSurface = new PlatformInput(wallPoints);
         GameObject    wallObject  = CreatePlatform(wallSurface, wallHeight);
         wallObject.layer = LayerMask.NameToLayer("Wall");
         wallObject.name  = "Wall";
         wallObject.GetComponent <Renderer>().material = wallMaterial;
         wallObject.transform.parent = wallContainer.transform;
     }
 }
Exemple #4
0
        /// <summary>
        /// Creates the surface bounding boxes in the level.
        /// </summary>
        /// <param name="surfaceInput">JSON data for the surface bounding boxes.</param>
        private void CreateSurfaces(List <SurfaceInput> surfaceInput)
        {
            surfaceContainer = ObjectUtil.CreateNewObject("Surfaces");

            foreach (SurfaceInput surface in surfaceInput)
            {
                GameObject surfaceObject    = ObjectUtil.CreateNewObject("Surface", surfaceContainer);
                Surface    surfaceComponent = surfaceObject.AddComponent <Surface>();
                SurfaceManager.instance.AddSurface(surfaceComponent);

                Vector3 center      = Vector3.zero;
                int     numVertices = 0;
                foreach (PlatformInput platform in surface.platforms)
                {
                    GameObject platformObject = CreatePlatform(platform, platform.height);
                    platformObject.name = "Platform";
                    platformObject.GetComponent <Renderer>().material = surfaceMaterial;
                    platformObject.transform.parent = surfaceObject.transform;

                    if (surface.isFloor)
                    {
                        platformObject.AddComponent <Lava>();
                    }

                    foreach (Vector3 vertex in platform.vertices)
                    {
                        center += vertex;
                        numVertices++;
                    }
                }

                if (numVertices > 0)
                {
                    center /= numVertices;
                }
                surfaceComponent.center = center;

                surfaceComponent.isFloor = surface.isFloor;
            }
        }
        /// <summary>
        /// Draws a line representing an entity's path.
        /// </summary>
        /// <param name="path">The path to draw.</param>
        /// <param name="color">The color of the path to draw.</param>
        private void DrawLine(List <Vector3> path, Color color, bool isPlayer = false)
        {
            if (path.Count > 0)
            {
                Vector3 lastPosition = path[0];
                for (int i = 1; i < path.Count; i++)
                {
                    if (Vector3.Distance(lastPosition, path[i]) >= distanceThreshold)
                    {
                        GameObject   lineObject    = ObjectUtil.CreateNewObject("Path", pathContainer);
                        LineRenderer line          = lineObject.AddComponent <LineRenderer>();
                        Vector3[]    linePositions = new Vector3[] { lastPosition, path[i] };
                        for (int j = 0; j < linePositions.Length; j++)
                        {
                            float heightOffset;
                            if (isPlayer)
                            {
                                if (playerHeightOffset == 0)
                                {
                                    playerHeightOffset = PlayerMover.instance.height;
                                }
                                heightOffset = playerHeightOffset;
                            }
                            else
                            {
                                heightOffset = Lemming.height;
                            }
                            linePositions[j] += Vector3.down * (heightOffset / 2 - pathWidth * 2);
                            line.SetPosition(j, linePositions[j]);
                        }
                        line.material = pathMaterial;
                        line.SetColors(color, color);
                        line.SetWidth(pathWidth, pathWidth);

                        lastPosition = path[i];
                    }
                }
            }
        }
 /// <summary>
 /// Creates the blocks in the factory.
 /// </summary>
 private void Start()
 {
     blockContainer = ObjectUtil.CreateNewObject("Blocks");
     _numTypes      = blockPrefabs.Length;
     inactiveBlocks = new Queue <Block> [_numTypes];
     blocks         = new List <Block> [_numTypes];
     blockOffsets   = new float[_numTypes];
     for (int i = 0; i < numTypes; i++)
     {
         inactiveBlocks[i] = new Queue <Block>();
         blocks[i]         = new List <Block>(numBlocks[i]);
         for (int j = 0; j < numBlocks[i]; j++)
         {
             Block block = ObjectUtil.Instantiate(blockPrefabs[i]);
             block.gameObject.SetActive(false);
             block.transform.parent = blockContainer.transform;
             block.type             = (BlockType)i;
             inactiveBlocks[i].Enqueue(block);
             blocks[i].Add(block);
         }
         blockOffsets[i] = blockPrefabs[i].transform.localScale.y / 2 * 1.1f;
     }
 }