Пример #1
0
    /// <summary>
    /// Sets a new level
    /// </summary>
    /// <param name="NextComponent">The ID of the next component to be targetted</param>
    public void NewLevel(int NextComponent)
    {
        // Increment level number
        LevelNumber += 1;

        // Show level ui
        if (NextComponent == 0)
        {
            _LevelUI.ShowingLevelUI = true;
        }

        // First delete the old stuff
        // Delete the gates
        Destroy(Gates.GateParent);

        // Delete the panels
        if (PanelsRoot != null)
        {
            Destroy(PanelsRoot);
        }

        // Setup things
        // Get the component details
        Ship.ShipComponent Component = PlayerShip.AllComponents[NextComponent];

        // Setup inputs and outputs
        _Gates.InputCount  = Component.InputCount;
        _Gates.OutputCount = Component.OutputCount;
        _Gates.Initialise();
        PanelSize = Component.BoardSize;

        // Set labels and descriptions
        for (int i = 0; i < Component.InputLabels.Count; i++)
        {
            _Gates.InputConnections[i].Label       = Component.InputLabels[i];
            _Gates.InputConnections[i].Description = Component.InputDescriptions[i];
        }

        // Set labels and descriptions (outputs)
        for (int i = 0; i < Component.OutputLabels.Count; i++)
        {
            _Gates.OutputConnections[i].Label       = Component.OutputLabels[i];
            _Gates.OutputConnections[i].Description = Component.OutputDescriptions[i];
        }

        // Tell the ship
        PlayerShip.CurrentComponentId = NextComponent;

        // Create a new ship if the current one is set to null
        if (EnemyShip == null)
        {
            SpawnEnemy();
        }

        // Now setup the panels
        // Tidy up a bit
        PanelsRoot = new GameObject();
        PanelsRoot.transform.position = new Vector3(0, 0, 5);
        PanelsRoot.name = "Panel Root Object";

        // Initialise the BG Panel Objects list
        BGPanelObjs = new List <GameObject>();

        // First spawn in the background panels
        BGPanelObjs.Add(Instantiate(PanelBackground));
        BGPanelObjs.Add(Instantiate(PanelBackground, new Vector2(-0.64f, 0), new Quaternion(0, 0, 0, 0)));
        BGPanelObjs.Add(Instantiate(PanelBackground, new Vector2(0.64f, 0), new Quaternion(0, 0, 0, 0)));

        for (int i = 0; i < BGPanelObjs.Count; i++)
        {
            BGPanelObjs[i].transform.parent = PanelsRoot.transform;
        }

        // Then the panel, switch, various other things that depend on panel size
        // Use a switch statement and kill many stones with one bird ;)
        switch (PanelSize)
        {
        case EPanelSize.Large:
            // Create the foreground panel
            FGPanelObj                  = Instantiate(LargePanel);
            FGPanelObj.name             = "large panel";
            FGPanelObj.transform.parent = PanelsRoot.transform;

            // Create the switch
            SwitchObj                  = Instantiate(SwitchPrefab, LargeSwitchPos, new Quaternion(0, 0, 0, 0));
            SwitchObj.name             = "panel switch";
            SwitchObj.transform.parent = PanelsRoot.transform;

            // Setup the player's base positions for inputs+outputs
            ThePlayer.SourceBasePos      = Camera.main.WorldToScreenPoint(new Vector2(-0.24f, 0.19f));
            ThePlayer.OutBasePos         = Camera.main.WorldToScreenPoint(new Vector2(0.22f, 0.19f));
            Camera.main.orthographicSize = 0.3f;

            // Flip the base positions' y-coordinates
            ThePlayer.SourceBasePos.y = Screen.height - ThePlayer.SourceBasePos.y;
            ThePlayer.OutBasePos.y    = Screen.height - ThePlayer.OutBasePos.y;
            break;

        case EPanelSize.Medium:
            // Create the foreground panel
            FGPanelObj                  = Instantiate(MediumPanel);
            FGPanelObj.name             = "medium panel";
            FGPanelObj.transform.parent = PanelsRoot.transform;

            // Create the switch
            SwitchObj                  = Instantiate(SwitchPrefab, MediumSwitchPos, new Quaternion(0, 0, 0, 0));
            SwitchObj.name             = "panel switch";
            SwitchObj.transform.parent = PanelsRoot.transform;

            ThePlayer.SourceBasePos      = Camera.main.WorldToScreenPoint(new Vector2(-0.24f, 0.1f));
            ThePlayer.OutBasePos         = Camera.main.WorldToScreenPoint(new Vector2(0.22f, 0.1f));
            Camera.main.orthographicSize = 0.24f;

            ThePlayer.SourceBasePos.y = Screen.height - ThePlayer.SourceBasePos.y;
            ThePlayer.OutBasePos.y    = Screen.height - ThePlayer.OutBasePos.y;
            break;

        case EPanelSize.Small:
            // Create the foreground panel
            FGPanelObj                  = Instantiate(SmallPanel);
            FGPanelObj.name             = "small panel";
            FGPanelObj.transform.parent = PanelsRoot.transform;

            // Create the switch
            SwitchObj                  = Instantiate(SwitchPrefab, SmallSwitchPos, new Quaternion(0, 0, 0, 0));
            SwitchObj.name             = "panel switch";
            SwitchObj.transform.parent = PanelsRoot.transform;

            // Setup the player's base positions for inputs+outputs
            ThePlayer.SourceBasePos      = Camera.main.WorldToScreenPoint(new Vector2(-0.15f, 0.1f));
            ThePlayer.OutBasePos         = Camera.main.WorldToScreenPoint(new Vector2(0.15f, 0.1f));
            Camera.main.orthographicSize = 0.24f;

            // Flip the base positions' y-coordinates
            ThePlayer.SourceBasePos.y = Screen.height - ThePlayer.SourceBasePos.y;
            ThePlayer.OutBasePos.y    = Screen.height - ThePlayer.OutBasePos.y;
            break;
        }
    }