Exemple #1
0
 // Switches the current level
 public void SwitchLevel(WaypointManager.Level changeLevel)
 {
     if (level == WaypointManager.Level.ABOVE_GROUND && changeLevel == WaypointManager.Level.ABOVE_GROUND)
     {
         spriteRenderer.enabled = true;
     }
     else if (level == WaypointManager.Level.ABOVE_GROUND && changeLevel == WaypointManager.Level.UNDER_GROUND)
     {
         spriteRenderer.enabled = false;
     }
     else if (level == WaypointManager.Level.UNDER_GROUND && changeLevel == WaypointManager.Level.UNDER_GROUND)
     {
         spriteRenderer.enabled = true;
     }
     else if (level == WaypointManager.Level.UNDER_GROUND && changeLevel == WaypointManager.Level.ABOVE_GROUND)
     {
         spriteRenderer.enabled = false;
     }
 }
Exemple #2
0
 // Sets the types for the waypoint and connected waypoints
 public void SetUpWaypointTypes(WaypointManager.WaypointType typeToSet, WaypointManager.Level levelToSet)
 {
     type  = typeToSet;
     level = levelToSet;
 }
Exemple #3
0
    // Spawns a new Waypoint
    public Waypoint SpawnWaypoint(
        WaypointManager.WaypointType waypointType,
        WaypointManager.Level waypointLevel,
        List <Waypoint> connectedWaypoints,
        Vector3 spawnLocation)
    {
        // Spawn it
        GameObject newWaypointGameObject = Instantiate(waypointPrefab, spawnLocation, new Quaternion(0, 0, 0, 0), transform);

        if (newWaypointGameObject == null)
        {
            Debug.Log("Failed to spawn a " + waypointType);
            return(null);
        }

        // Get Waypoint object
        Waypoint newWaypointClass = newWaypointGameObject.GetComponent <Waypoint>();

        if (newWaypointClass == null)
        {
            Debug.Log("Failed to get waypoint class");
            return(null);
        }

        // Assign connected waypoints
        newWaypointClass.SetUpWaypointTypes(waypointType, waypointLevel);

        // Connect everything else
        if (connectedWaypoints.Count > 0)
        {
            foreach (Waypoint w in connectedWaypoints)
            {
                if (w == null)
                {
                    Debug.Log("Failed to get connected waypoints");
                    return(null);
                }
                w.AddAConnectedWaypoint(newWaypointClass);
                newWaypointClass.AddAConnectedWaypoint(w);
                WaypointBridge newBridge = new WaypointBridge(w, newWaypointClass);
                if (newBridge == null)
                {
                    Debug.Log("Failed to create a new bridge for " + waypointType);
                    return(null);
                }
                bridgeSet.Add(newBridge);
                curentAntsInBridges.Add(newBridge, 0);
                maxAntsAllowedBetweenWaypoints.Add(newBridge, maxAntsOnStart);
                flowBetweenWaypoints.Add(newBridge, 0);

                LineRenderer newLine = new GameObject().AddComponent <LineRenderer>();
                newLine.transform.parent = transform;
                newLine.gameObject.name  = "LineRenderer";
                newLine.material         = lineMaterial;
                newLine.startWidth       = lineWidth;
                newLine.endWidth         = lineWidth;
                newLine.numCapVertices   = 5;
                newLine.SetPosition(0, w.GetComponent <Transform>().position);
                newLine.SetPosition(1, newWaypointGameObject.transform.position);
                newLine.sortingOrder = -1;
                if (waypointLevel == Level.ABOVE_GROUND && w.CurrentLevel() == Level.ABOVE_GROUND && GameManager.main.currentView == GameManager.CurrentView.UNDER_GROUND)
                {
                    newLine.enabled = false;
                }
                else if (waypointLevel == Level.UNDER_GROUND && w.CurrentLevel() == Level.UNDER_GROUND && GameManager.main.currentView == GameManager.CurrentView.SURFACE)
                {
                    newLine.enabled = false;
                }
                else if (waypointLevel == Level.UNDER_GROUND && w.CurrentLevel() == Level.ABOVE_GROUND)
                {
                    newLine.enabled = false;
                }
                else if (waypointLevel == Level.ABOVE_GROUND && w.CurrentLevel() == Level.UNDER_GROUND)
                {
                    newLine.enabled = false;
                }
                waypointLines.Add(newBridge, newLine);

                // Connect to flow manager
                FlowManager.main.NewRoad(newWaypointClass, w, newLine);
            }
        }

        // Add to type list
        switch (waypointType)
        {
        case WaypointType.FARM_SITE:
            farmWaypoints.Add(newWaypointClass);
            LeafManager.main.NewFarmWaypoint(newWaypointClass);
            newWaypointClass.AssignSprite(farmingSprite);
            break;

        case WaypointType.ENTRANCE:
            entranceWaypoints.Add(newWaypointClass);
            newWaypointClass.AssignSprite(enterSprite);
            break;

        case WaypointType.LEAF_SITE:
            leafWaypoints.Add(newWaypointClass);
            LeafManager.main.NewLeafSite(newWaypointClass);
            newWaypointClass.AssignSprite(leafSprite);
            break;

        case WaypointType.NURSERY_SITE:
            nurseryWaypoints.Add(newWaypointClass);
            newWaypointClass.AssignSprite(nurserySprite);
            break;

        case WaypointType.TRANSITION:
            transitionWaypoints.Add(newWaypointClass);
            newWaypointClass.AssignSprite(transitionSprite);
            break;

        case WaypointType.TRASH_SITE:
            trashSitesWaypoint.Add(newWaypointClass);
            TrashManager.main.AddTrashWaypoint(newWaypointClass);
            newWaypointClass.AssignSprite(trashSprite);
            break;

        case WaypointType.EXIT:
            trashSitesWaypoint.Add(newWaypointClass);
            newWaypointClass.AssignSprite(exitSprite);
            break;

        default:
            Debug.Log("Failed to assign waypoint type");
            return(null);
        }

        // Add to all
        allWaypoints.Add(newWaypointClass);

        return(newWaypointClass);
    }