예제 #1
0
 //! Returns true if this inventory slot requires network updates in multiplayer games.
 private bool ShouldDoNetworkUpdate()
 {
     return(gameObject.tag != "Player" &&
            PlayerPrefsX.GetPersistentBool("multiplayer") == true &&
            pendingNetworkUpdate == true &&
            networkCoroutineBusy == false);
 }
예제 #2
0
 //! Removes recently placed blocks.
 private IEnumerator RemoveRecent()
 {
     runningUndo = true;
     foreach (Block block in undoBlocks)
     {
         if (block.blockObject != null)
         {
             if (block.blockObject.activeInHierarchy)
             {
                 Destroy(block.blockObject);
                 player.playerInventory.AddItem(block.blockType, 1);
                 if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                 {
                     Vector3    pos = block.blockObject.transform.position;
                     Quaternion rot = block.blockObject.transform.rotation;
                     UpdateNetwork(1, block.blockType, pos, rot);
                 }
                 player.PlayCraftingSound();
             }
         }
         yield return(null);
     }
     undoBlocks.Clear();
     runningUndo = false;
 }
    //! Drops a stack of items on the ground.
    public void DropItem(InventorySlot slot)
    {
        Vector3    dropPos     = mCam.transform.position + mCam.transform.forward * 10;
        GameObject droppedItem = Instantiate(item, dropPos, mCam.transform.rotation);

        float   x          = Mathf.Round(dropPos.x);
        float   y          = Mathf.Round(dropPos.y);
        float   z          = Mathf.Round(dropPos.z);
        Vector3 roundedPos = new Vector3(x, y, z);

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            while (networkItemLocations.Contains(roundedPos))
            {
                roundedPos.y++;
            }
            networkItemLocations.Add(roundedPos);
        }

        droppedItem.GetComponent <Item>().startPosition = roundedPos;
        droppedItem.GetComponent <Item>().type          = slot.typeInSlot;
        droppedItem.GetComponent <Item>().amount        = slot.amountInSlot;

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            networkController.networkSend.SendItemData(0, slot.typeInSlot, slot.amountInSlot, roundedPos);
        }

        slot.typeInSlot   = "nothing";
        slot.amountInSlot = 0;
        PlayCraftingSound();
    }
 // Adds an item to a specific inventory slot.
 public void AddItemToSlot(string type, int amount, int slot)
 {
     inventory[slot].typeInSlot    = type;
     inventory[slot].amountInSlot += amount;
     if (PlayerPrefsX.GetPersistentBool("multiplayer") == true && gameObject.tag != "Player")
     {
         inventory[slot].pendingNetworkUpdate = true;
         inventory[slot].networkWaitTime      = 0;
     }
 }
 //! Saves inventory data.
 public void SaveData()
 {
     if (GetComponent <PlayerController>() != null && PlayerPrefsX.GetPersistentBool("multiplayer") == true)
     {
         SaveDataToPrefs();
     }
     else
     {
         SaveDataToFile();
     }
 }
 //! Loads saved inventory data.
 private void Initialize()
 {
     if (GetComponent <PlayerController>() != null && PlayerPrefsX.GetPersistentBool("multiplayer") == true)
     {
         LoadDataFromPrefs();
     }
     else
     {
         LoadDataFromFile();
     }
 }
예제 #7
0
    //! Network functions called once per frame.
    public void NetworkFrame()
    {
        serverURL = PlayerPrefs.GetString("serverURL");

        string commandLineOptions = Environment.CommandLine;

        if (commandLineOptions.Contains("-batchmode"))
        {
            if (dedicatedServerCoroutineBusy == false)
            {
                dedicatedServerCoroutine = playerController.StartCoroutine(DedicatedServerCoroutine());
            }
        }

        if (sendNetworkPlayerCoroutineBusy == false)
        {
            sendNetworkPlayerCoroutine = playerController.StartCoroutine(SendNetworkPlayerInfo());
        }

        if (getNetworkPlayersCoroutineBusy == false)
        {
            getNetworkPlayersCoroutine = playerController.StartCoroutine(GetNetworkPlayers());
        }

        if (playerMovementCoroutineBusy == false)
        {
            networkMovementCoroutine = playerController.StartCoroutine(MoveNetworkPlayers());
        }

        if (networkBlockCoroutineBusy == false)
        {
            networkBlockCoroutineBusy = true;
            networkBlockCoroutine     = playerController.StartCoroutine(UpdateNetworkBlocks());
        }

        if (networkItemCoroutineBusy == false)
        {
            networkItemCoroutineBusy = true;
            networkItemCoroutine     = playerController.StartCoroutine(UpdateNetworkItems());
        }

        if (announceCoroutineBusy == false && PlayerPrefsX.GetPersistentBool("hosting") == true && PlayerPrefsX.GetPersistentBool("announce") == true)
        {
            announceCoroutineBusy = true;
            announceCoroutine     = playerController.StartCoroutine(networkSend.Announce());
        }

        if (checkForBanCoroutineBusy == false && PlayerPrefsX.GetPersistentBool("hosting") == false)
        {
            checkForBanCoroutineBusy = true;
            checkForBanCoroutine     = playerController.StartCoroutine(networkReceive.CheckForBan());
        }
    }
 //! Moves the player to their previous location when a game is loaded.
 private void MovePlayerToSavedLocation()
 {
     if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
     {
         transform.position = PlayerPrefsX.GetPersistentVector3(stateManager.worldName + "playerPosition");
         money = PlayerPrefs.GetInt(stateManager.worldName + "money");
     }
     else
     {
         transform.position = PlayerPrefsX.GetVector3(stateManager.worldName + "playerPosition");
         money = FileBasedPrefs.GetInt(stateManager.worldName + "money");
     }
     movedPlayer = true;
 }
예제 #9
0
    //! Begins dragging an item from an inventory slot.
    public void DragItemFromSlot(int index, InventorySlot dragSlot, InventoryManager destination)
    {
        bool flag = false;

        dragSlotIndex = index;
        if (playerController.storageGUIopen == true)
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                flag = true;
                for (int i = 0; i < destination.inventory.Length; i++)
                {
                    InventorySlot slot = destination.inventory[i];
                    if (CanTransfer(dragSlot, slot))
                    {
                        destination.AddItem(dragSlot.typeInSlot, dragSlot.amountInSlot);
                        dragSlot.typeInSlot   = "nothing";
                        dragSlot.amountInSlot = 0;
                        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true && networkTransferCoroutineBusy == false)
                        {
                            networkTransferCoroutine = playerController.StartCoroutine(NetworkTransferItemCoroutine(i, index, slot, dragSlot, destination));
                        }
                    }
                }
            }
        }
        if (flag == false)
        {
            playerController.draggingItem = true;
            itemToDrag       = dragSlot.typeInSlot;
            slotDraggingFrom = dragSlot;
            if (Input.GetKey(KeyCode.LeftShift))
            {
                if (dragSlot.amountInSlot > 1)
                {
                    amountToDrag = dragSlot.amountInSlot / 2;
                }
                else if (dragSlot.amountInSlot > 0)
                {
                    amountToDrag = dragSlot.amountInSlot;
                }
            }
            else if (dragSlot.amountInSlot > 0)
            {
                amountToDrag = dragSlot.amountInSlot;
            }
        }
    }
예제 #10
0
    //! Prepares cursor for free block placement, ie: not attached to another block.
    private void SetupFreePlacement(RaycastHit hit)
    {
        Vector3 placementPoint = new Vector3(hit.point.x, (hit.point.y + 2.4f), hit.point.z);

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            placementPoint = new Vector3(Mathf.Round(hit.point.x), Mathf.Round(hit.point.y + 2.4f), Mathf.Round(hit.point.z));
        }
        Quaternion placementRotation = playerController.buildObject.transform.rotation;

        playerController.buildObject.transform.position = placementPoint;
        playerController.buildObject.transform.rotation = placementRotation;
        dirLine.SetPosition(0, playerController.buildObject.transform.position);
        Vector3 dirVector = playerController.buildObject.transform.position + playerController.buildObject.transform.forward * 4;

        dirLine.SetPosition(1, dirVector);
    }
    //! Saves the player's location and money.
    public void SavePlayerData()
    {
        playerInventory.SaveData();
        GameObject.Find("LanderCargo").GetComponent <InventoryManager>().SaveData();
        FileBasedPrefs.SetBool(stateManager.worldName + "oldWorld", true);

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            PlayerPrefsX.SetPersistentVector3(stateManager.worldName + "playerPosition", transform.position);
            PlayerPrefs.SetInt(stateManager.worldName + "money", money);
        }
        else
        {
            PlayerPrefsX.SetVector3(stateManager.worldName + "playerPosition", transform.position);
            FileBasedPrefs.SetInt(stateManager.worldName + "money", money);
        }
    }
 //! Used to handle picking up items.
 public void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.GetComponent <Item>() != null)
     {
         Item colItem = collision.gameObject.GetComponent <Item>();
         playerInventory.AddItem(colItem.type, colItem.amount);
         if (playerInventory.itemAdded)
         {
             Destroy(collision.gameObject);
             if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
             {
                 networkController.networkSend.SendItemData(1, colItem.type, colItem.amount, colItem.startPosition);
                 networkController.networkReceive.itemDatabaseDelay = 0;
             }
             PlayCraftingSound();
         }
     }
 }
예제 #13
0
    //! Called once per frame by unity engine.
    public void Update()
    {
        if (PlayerPrefsX.GetPersistentBool("multiplayer") == false || playerController.stateManager.worldLoaded == false)
        {
            return;
        }

        if (networkController != null)
        {
            chatNetTimer += 1 * Time.deltaTime;
            if (chatNetTimer >= Random.Range(0.75f, 1.0f))
            {
                chatDataCoroutine = StartCoroutine(networkController.networkReceive.ReceiveChatData());
                chatNetTimer      = 0;
            }
        }
        else
        {
            networkController = playerController.networkController;
        }
    }
예제 #14
0
 //! Toggles the paint gun.
 public void TogglePaintGun()
 {
     if (PlayerPrefsX.GetPersistentBool("multiplayer") == false)
     {
         if (playerController.building == true || playerController.destroying == true)
         {
             if (playerController.gameManager.working == false)
             {
                 playerController.stoppingBuildCoRoutine = true;
                 meshManager.CombineBlocks();
                 playerController.separatedBlocks = false;
                 playerController.building        = false;
                 playerController.destroying      = false;
             }
             else
             {
                 playerController.requestedBuildingStop = true;
             }
         }
         if (playerController.paintGunActive == false)
         {
             playerController.paintGunActive = true;
             playerController.paintGun.SetActive(true);
             playerController.laserCannon.SetActive(false);
             playerController.laserCannonActive = false;
             playerController.scanner.SetActive(false);
             playerController.scannerActive = false;
         }
         else
         {
             playerController.paintGun.SetActive(false);
             playerController.paintGunActive     = false;
             playerController.paintColorSelected = false;
         }
     }
 }
 //! Adds an item to the inventory.
 public void AddItem(string type, int amount)
 {
     itemAdded = false;
     foreach (InventorySlot slot in inventory)
     {
         if (slot != null && itemAdded == false)
         {
             if (slot.typeInSlot == "nothing" || slot.typeInSlot == type || slot.typeInSlot == "")
             {
                 if (slot.amountInSlot <= maxStackSize - amount)
                 {
                     slot.typeInSlot    = type;
                     slot.amountInSlot += amount;
                     itemAdded          = true;
                     if (PlayerPrefsX.GetPersistentBool("multiplayer") == true && gameObject.tag != "Player")
                     {
                         slot.pendingNetworkUpdate = true;
                         slot.networkWaitTime      = 0;
                     }
                 }
             }
         }
     }
 }
예제 #16
0
    //! Called by unity engine for rendering and handling GUI events.
    public void OnGUI()
    {
        // STYLE
        GUI.skin = thisGUIskin;

        // ASPECT RATIO
        float ScreenHeight = Screen.height;
        float ScreenWidth  = Screen.width;

        if (ScreenWidth / ScreenHeight < 1.7f)
        {
            ScreenHeight = (ScreenHeight * 0.75f);
        }
        if (ScreenHeight < 700)
        {
            GUI.skin.label.fontSize = 10;
        }

        if (playerController.stateManager.worldLoaded == true && GetComponent <MainMenu>().finishedLoading == true)
        {
            // BUILD ITEM HUD AT TOP RIGHT OF SCREEN
            if (playerController.displayingBuildItem == true)
            {
                GUI.Label(guiCoordinates.topRightInfoRect, "\n\nBuild item set to " + playerController.buildType);

                if (textureDictionary.dictionary.ContainsKey(playerController.previousBuildType + "_Icon"))
                {
                    GUI.DrawTexture(guiCoordinates.previousBuildItemTextureRect, textureDictionary.dictionary[playerController.previousBuildType + "_Icon"]);
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.previousBuildItemTextureRect, textureDictionary.dictionary[playerController.previousBuildType]);
                }

                if (textureDictionary.dictionary.ContainsKey(playerController.buildType + "_Icon"))
                {
                    GUI.DrawTexture(guiCoordinates.buildItemTextureRect, textureDictionary.dictionary[playerController.buildType + "_Icon"]);
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.buildItemTextureRect, textureDictionary.dictionary[playerController.buildType]);
                }

                if (textureDictionary.dictionary.ContainsKey(playerController.buildType + "_Icon"))
                {
                    GUI.DrawTexture(guiCoordinates.currentBuildItemTextureRect, textureDictionary.dictionary[playerController.buildType + "_Icon"]);
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.currentBuildItemTextureRect, textureDictionary.dictionary[playerController.buildType]);
                }

                GUI.DrawTexture(guiCoordinates.buildItemTextureRect, textureDictionary.dictionary["Selection Box"]);

                if (textureDictionary.dictionary.ContainsKey(playerController.nextBuildType + "_Icon"))
                {
                    GUI.DrawTexture(guiCoordinates.nextBuildItemTextureRect, textureDictionary.dictionary[playerController.nextBuildType + "_Icon"]);
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.nextBuildItemTextureRect, textureDictionary.dictionary[playerController.nextBuildType]);
                }

                int buildItemCount = 0;
                foreach (InventorySlot slot in playerInventory.inventory)
                {
                    if (slot.typeInSlot.Equals(playerController.buildType))
                    {
                        buildItemCount += slot.amountInSlot;
                    }
                }
                GUI.Label(guiCoordinates.buildItemCountRect, "" + buildItemCount);
            }

            // METEOR SHOWER WARNINGS
            if (TabletNotificationRequired())
            {
                GUI.Label(guiCoordinates.topLeftInfoRect, "Urgent message received! Check your tablet for more information.");
            }

            // TABLET
            if (playerController.tabletOpen == true)
            {
                int    day        = GameObject.Find("Rocket").GetComponent <Rocket>().day;
                int    hour       = (int)GameObject.Find("Rocket").GetComponent <Rocket>().gameTime;
                string hourString = "";
                if (hour < 10)
                {
                    hourString = "000" + hour;
                }
                else if (hour >= 10 && hour < 100)
                {
                    hourString = "00" + hour;
                }
                else if (hour >= 100 && hour < 1000)
                {
                    hourString = "0" + hour;
                }
                else if (hour >= 1000)
                {
                    hourString = "" + hour;
                }
                GUI.DrawTexture(guiCoordinates.tabletBackgroundRect, textureDictionary.dictionary["Tablet"]);
                GUI.Label(guiCoordinates.tabletMessageRect, playerController.currentTabletMessage);
                GUI.Label(guiCoordinates.tabletTimeRect, "\nDay: " + day + " Hour: " + hourString + ", Income: $" + playerController.money.ToString("N0"));
                if (GUI.Button(guiCoordinates.tabletButtonRect, "CLOSE"))
                {
                    Cursor.visible              = false;
                    Cursor.lockState            = CursorLockMode.Locked;
                    playerController.tabletOpen = false;
                    playerController.PlayButtonSound();
                }
            }

            // OPTIONS/EXIT MENU
            if (playerController.escapeMenuOpen == true)
            {
                if (MenuAvailable())
                {
                    GUI.DrawTexture(guiCoordinates.escapeMenuRect, textureDictionary.dictionary["Menu Background"]);
                    if (GUI.Button(guiCoordinates.escapeButton1Rect, "Resume"))
                    {
                        Cursor.visible   = false;
                        Cursor.lockState = CursorLockMode.Locked;
                        gameObject.GetComponent <MSCameraController>().enabled = true;
                        playerController.escapeMenuOpen    = false;
                        playerController.optionsGUIopen    = false;
                        playerController.helpMenuOpen      = false;
                        playerController.videoMenuOpen     = false;
                        playerController.schematicMenuOpen = false;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton2Rect, "Save"))
                    {
                        playerController.requestedSave = true;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton3Rect, "Options"))
                    {
                        playerController.optionsGUIopen = true;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton4Rect, "Help"))
                    {
                        playerController.helpMenuOpen = true;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton5Rect, "Exit"))
                    {
                        playerController.exiting       = true;
                        playerController.requestedSave = true;
                        playerController.PlayButtonSound();
                    }
                }
                else
                {
                    if (SavingMessageRequired())
                    {
                        int current = stateManager.saveManager.currentObject;
                        int total   = stateManager.saveManager.totalObjects;
                        GUI.DrawTexture(guiCoordinates.saveMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        if (total > 0)
                        {
                            GUI.Label(guiCoordinates.saveMessageRect, "Saving world... " + current + "/" + total);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.saveMessageRect, "Saving world... " + "preparing");
                        }
                    }
                }
            }

            // HELP MENU
            if (playerController.helpMenuOpen == true)
            {
                if (playerController.videoMenuOpen == false && playerController.schematicMenuOpen == false)
                {
                    GUI.DrawTexture(guiCoordinates.escapeMenuRect, textureDictionary.dictionary["Menu Background"]);
                    if (GUI.Button(guiCoordinates.escapeButton1Rect, "Videos"))
                    {
                        playerController.videoMenuOpen = true;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton2Rect, "Schematics"))
                    {
                        playerController.schematicMenuOpen = true;
                        playerController.PlayButtonSound();
                    }
                    if (GUI.Button(guiCoordinates.escapeButton4Rect, "BACK"))
                    {
                        playerController.helpMenuOpen = false;
                        playerController.PlayButtonSound();
                    }
                }
                if (playerController.videoMenuOpen == true)
                {
                    if (playerController.mCam.GetComponent <UnityEngine.Video.VideoPlayer>().isPlaying == false)
                    {
                        GUI.DrawTexture(guiCoordinates.videoMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);
                    }
                    if (playerController.mCam.GetComponent <UnityEngine.Video.VideoPlayer>().isPlaying == false)
                    {
                        if (GUI.Button(guiCoordinates.helpButton1Rect, "Intro"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("Guide.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton2Rect, "Dark Matter"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("DarkMatter.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton3Rect, "Universal Extractor"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("Extractor.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton4Rect, "Heat Exchanger"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("HeatExchanger.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton5Rect, "Alloy Smelter"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("AlloySmelter.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton6Rect, "Hazards"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("Hazards.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton7Rect, "Rail Carts"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("RailCarts.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton8Rect, "Storage Computers"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("StorageComputers.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton9Rect, "Nuclear Reactors"))
                        {
                            Cursor.visible   = false;
                            Cursor.lockState = CursorLockMode.Locked;
                            videoPlayer.GetComponent <VP>().PlayVideo("NuclearReactors.webm", false, 0.5f);
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton10Rect, "BACK"))
                        {
                            playerController.videoMenuOpen = false;
                            playerController.PlayButtonSound();
                        }
                    }

                    if (playerController.mCam.GetComponent <UnityEngine.Video.VideoPlayer>().isPlaying == false)
                    {
                        Cursor.visible   = true;
                        Cursor.lockState = CursorLockMode.None;
                        videoPlayer.GetComponent <VP>().StopVideo();
                    }
                    if (playerController.mCam.GetComponent <UnityEngine.Video.VideoPlayer>().isPlaying == true && Input.anyKey)
                    {
                        Cursor.visible   = true;
                        Cursor.lockState = CursorLockMode.None;
                        videoPlayer.GetComponent <VP>().StopVideo();
                    }
                }
                if (playerController.schematicMenuOpen == true)
                {
                    if (!SchematicActive())
                    {
                        GUI.DrawTexture(guiCoordinates.schematicsMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);
                        if (GUI.Button(guiCoordinates.helpButton1Rect, "Dark Matter"))
                        {
                            if (schematic1 == false)
                            {
                                schematic1 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton2Rect, "Plates"))
                        {
                            if (schematic2 == false)
                            {
                                schematic2 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton3Rect, "Wires"))
                        {
                            if (schematic3 == false)
                            {
                                schematic3 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton4Rect, "Gears"))
                        {
                            if (schematic4 == false)
                            {
                                schematic4 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton5Rect, "Steel"))
                        {
                            if (schematic5 == false)
                            {
                                schematic5 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton6Rect, "Bronze"))
                        {
                            if (schematic6 == false)
                            {
                                schematic6 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton7Rect, "Heat Exchangers"))
                        {
                            if (schematic7 == false)
                            {
                                schematic7 = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.helpButton8Rect, "BACK"))
                        {
                            playerController.schematicMenuOpen = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (schematic1 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Dark Matter Schematic"]);
                    }
                    if (schematic2 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Plate Schematic"]);
                    }
                    if (schematic3 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Wire Schematic"]);
                    }
                    if (schematic4 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Gear Schematic"]);
                    }
                    if (schematic5 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Steel Schematic"]);
                    }
                    if (schematic6 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Bronze Schematic"]);
                    }
                    if (schematic7 == true)
                    {
                        GUI.DrawTexture(new Rect(0, 0, ScreenWidth, ScreenHeight), textureDictionary.dictionary["Heat Exchanger Schematic"]);
                    }
                    if (SchematicActive())
                    {
                        if (GUI.Button(guiCoordinates.schematicCloseRect, "CLOSE") || Input.GetKeyDown(KeyCode.Escape))
                        {
                            ClearSchematic();
                            playerController.PlayButtonSound();
                        }
                    }
                }
                else
                {
                    ClearSchematic();
                }
            }

            // OPTIONS MENU
            if (playerController.optionsGUIopen == true)
            {
                Vector2 mousePos = Event.current.mousePosition;
                if (controlsMenuOpen == false && graphicsMenuOpen == false)
                {
                    GUI.DrawTexture(guiCoordinates.optionsMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);
                    if (GUI.Button(guiCoordinates.optionsButton1Rect, "Graphics"))
                    {
                        graphicsMenuOpen = true;
                        playerController.PlayButtonSound();
                    }

                    if (GUI.Button(guiCoordinates.optionsButton2Rect, "Controls"))
                    {
                        controlsMenuOpen = true;
                        playerController.PlayButtonSound();
                    }

                    GUI.Label(guiCoordinates.sliderLabel1Rect, "Audio Volume");

                    GUI.Label(guiCoordinates.sliderLabel2Rect, "Chunk Size " + "(" + gameManager.chunkSize + ")");

                    int simSpeed = (int)(gameManager.simulationSpeed * 5000);
                    GUI.Label(guiCoordinates.sliderLabel3Rect, "Simulation Speed " + "(" + simSpeed + "%)");

                    AudioListener.volume = GUI.HorizontalSlider(guiCoordinates.optionsButton4Rect, AudioListener.volume, 0, 5);
                    GetComponent <MSCameraController>().cameras[0].volume = AudioListener.volume;

                    gameManager.chunkSize = (int)GUI.HorizontalSlider(guiCoordinates.optionsButton5Rect, gameManager.chunkSize, 20, 100);

                    if (guiCoordinates.optionsButton5Rect.Contains(mousePos))
                    {
                        GUI.DrawTexture(guiCoordinates.craftingInfoBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.craftingInfoRect, descriptions.chunkSize);
                    }

                    gameManager.simulationSpeed = GUI.HorizontalSlider(guiCoordinates.optionsButton6Rect, gameManager.simulationSpeed, 0.0051f, 0.1f);

                    if (guiCoordinates.optionsButton6Rect.Contains(mousePos))
                    {
                        GUI.DrawTexture(guiCoordinates.craftingInfoBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.craftingInfoRect, descriptions.simulationSpeed);
                    }

                    string blockPhysicsDisplay = gameManager.blockPhysics == true ? "ON" : "OFF";
                    if (GUI.Button(guiCoordinates.optionsButton7Rect, "Block Physics: " + blockPhysicsDisplay))
                    {
                        if (PlayerPrefsX.GetPersistentBool("multiplayer") == false)
                        {
                            gameManager.blockPhysics = !gameManager.blockPhysics;
                        }
                        playerController.PlayButtonSound();
                    }

                    if (guiCoordinates.optionsButton7Rect.Contains(mousePos))
                    {
                        GUI.DrawTexture(guiCoordinates.craftingInfoBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.craftingInfoRect, descriptions.blockPhysics);
                    }

                    string hazardsEnabledDisplay = gameManager.hazardsEnabled == true ? "ON" : "OFF";
                    if (GUI.Button(guiCoordinates.optionsButton8Rect, "Hazards: " + hazardsEnabledDisplay))
                    {
                        if (PlayerPrefsX.GetPersistentBool("multiplayer") == false)
                        {
                            gameManager.hazardsEnabled = !gameManager.hazardsEnabled;
                        }
                        else if (PlayerPrefsX.GetPersistentBool("hosting") == true)
                        {
                            gameManager.hazardsEnabled = !gameManager.hazardsEnabled;
                            playerController.networkController.networkSend.SendHazardData(gameManager.hazardsEnabled);
                        }
                        playerController.PlayButtonSound();
                    }

                    if (guiCoordinates.optionsButton8Rect.Contains(mousePos))
                    {
                        GUI.DrawTexture(guiCoordinates.craftingInfoBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.craftingInfoRect, descriptions.hazards);
                    }

                    if (GUI.Button(guiCoordinates.optionsButton9Rect, "BACK"))
                    {
                        playerController.ApplySettings();
                        playerController.optionsGUIopen = false;
                        playerController.PlayButtonSound();
                    }
                }

                if (controlsMenuOpen == true && cGUI.showingInputGUI == false)
                {
                    GUI.DrawTexture(guiCoordinates.optionsSubMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);
                    if (GUI.Button(guiCoordinates.optionsButton1Rect, "Bindings"))
                    {
                        cGUI.ToggleGUI();
                        playerController.PlayButtonSound();
                    }

                    MSACC_SettingsCameraFirstPerson csInverted = GetComponent <MSCameraController>().CameraSettings.firstPerson;
                    string invertYInput = csInverted.invertYInput == true ? "ON" : "OFF";
                    if (GUI.Button(guiCoordinates.optionsButton2Rect, "Invert Y Axis: " + invertYInput))
                    {
                        csInverted.invertYInput = !csInverted.invertYInput;
                        playerController.PlayButtonSound();
                    }

                    GUI.Label(guiCoordinates.sliderLabel1Rect, "X sensitivity");
                    GUI.Label(guiCoordinates.sliderLabel2Rect, "Y sensitivity");

                    MSACC_SettingsCameraFirstPerson csSensitivity = GetComponent <MSCameraController>().CameraSettings.firstPerson;
                    csSensitivity.sensibilityX = GUI.HorizontalSlider(guiCoordinates.optionsButton4Rect, csSensitivity.sensibilityX, 0, 10);
                    csSensitivity.sensibilityY = GUI.HorizontalSlider(guiCoordinates.optionsButton5Rect, csSensitivity.sensibilityY, 0, 10);

                    if (GUI.Button(guiCoordinates.optionsButton8Rect, "BACK"))
                    {
                        controlsMenuOpen = false;
                        playerController.PlayButtonSound();
                        playerController.PlayButtonSound();
                    }
                }

                if (graphicsMenuOpen == true)
                {
                    GUI.DrawTexture(guiCoordinates.optionsSubMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);
                    string fogDisplay = RenderSettings.fog == true ? "ON" : "OFF";
                    if (GUI.Button(guiCoordinates.optionsButton1Rect, "Fog: " + fogDisplay))
                    {
                        if (!SceneManager.GetActiveScene().name.Equals("QE_World"))
                        {
                            RenderSettings.fog = !RenderSettings.fog;
                        }
                        else
                        {
                            RenderSettings.fog = false;
                        }
                        playerController.PlayButtonSound();
                    }

                    GUI.Label(guiCoordinates.sliderLabel0Rect, "Fog Density");
                    GUI.Label(guiCoordinates.sliderLabel1Rect, "FOV");
                    GUI.Label(guiCoordinates.sliderLabel2Rect, "Draw Distance");
                    GUI.Label(guiCoordinates.sliderLabel3Rect, "Graphics Quality " + "(" + QualitySettings.names[(int)playerController.graphicsQuality] + ")");

                    RenderSettings.fogDensity          = GUI.HorizontalSlider(guiCoordinates.optionsButton3Rect, RenderSettings.fogDensity, 0.00025f, 0.025f);
                    playerController.mCam.fieldOfView  = GUI.HorizontalSlider(guiCoordinates.optionsButton4Rect, playerController.mCam.fieldOfView, 60, 80);
                    playerController.mCam.farClipPlane = GUI.HorizontalSlider(guiCoordinates.optionsButton5Rect, playerController.mCam.farClipPlane, 1000, 10000);
                    playerController.graphicsQuality   = GUI.HorizontalSlider(guiCoordinates.optionsButton6Rect, playerController.graphicsQuality, 0, QualitySettings.names.Length - 1);

                    string vsyncDisplay = QualitySettings.vSyncCount == 1 ? "ON" : "OFF";
                    if (GUI.Button(guiCoordinates.optionsButton7Rect, "Vsync: " + vsyncDisplay))
                    {
                        QualitySettings.vSyncCount = QualitySettings.vSyncCount == 0 ? 1 : 0;
                        playerController.PlayButtonSound();
                    }

                    if (GUI.Button(guiCoordinates.optionsButton8Rect, "BACK"))
                    {
                        graphicsMenuOpen = false;
                        playerController.PlayButtonSound();
                    }
                }
            }
            else
            {
                graphicsMenuOpen = false;
                controlsMenuOpen = false;
            }
            //END OPTIONS MENU

            if (playerController.cannotCollect == true)
            {
                if (playerController.cannotCollectTimer < 3)
                {
                    GUI.DrawTexture(guiCoordinates.midMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.midMessageRect, "No space in inventory.");
                    playerController.cannotCollectTimer += 1 * Time.deltaTime;
                }
                else
                {
                    playerController.cannotCollect      = false;
                    playerController.cannotCollectTimer = 0;
                }
            }

            if (playerController.invalidAugerPlacement == true)
            {
                if (playerController.invalidAugerPlacementTimer < 3)
                {
                    GUI.DrawTexture(guiCoordinates.lowMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.lowMessageRect, "Invalid location.");
                    playerController.invalidAugerPlacementTimer += 1 * Time.deltaTime;
                }
                else
                {
                    playerController.invalidAugerPlacement      = false;
                    playerController.invalidAugerPlacementTimer = 0;
                }
            }

            if (playerController.autoAxisMessage == true)
            {
                if (playerController.autoAxisMessageTimer < 3)
                {
                    if (GetComponent <BuildController>().autoAxis == true)
                    {
                        GUI.DrawTexture(guiCoordinates.lowMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.lowMessageRect, "Auto Axis Snap");
                    }
                    else
                    {
                        GUI.DrawTexture(guiCoordinates.lowMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.lowMessageRect, "Manual Axis Snap");
                    }
                    playerController.autoAxisMessageTimer += 1 * Time.deltaTime;
                }
                else
                {
                    playerController.autoAxisMessage      = false;
                    playerController.autoAxisMessageTimer = 0;
                }
            }

            if (playerController.invalidRailCartPlacement == true)
            {
                if (playerController.invalidRailCartPlacementTimer < 3)
                {
                    GUI.DrawTexture(guiCoordinates.lowMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.lowMessageRect, "Invalid location.");
                    playerController.invalidRailCartPlacementTimer += 1 * Time.deltaTime;
                }
                else
                {
                    playerController.invalidRailCartPlacement      = false;
                    playerController.invalidRailCartPlacementTimer = 0;
                }
            }

            if (playerController.stoppingBuildCoRoutine == true || playerController.requestedBuildingStop == true)
            {
                GUI.DrawTexture(guiCoordinates.buildingMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                GUI.Label(guiCoordinates.buildingMessageRect, "Stopping Build System...");
            }

            if (playerController.blockLimitMessage == true)
            {
                if (playerController.blockLimitMessageTimer < 3)
                {
                    GUI.DrawTexture(guiCoordinates.secondLineHighMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.secondLineHighMessageRect, "World limit exceeded!");
                    playerController.blockLimitMessageTimer += 1 * Time.deltaTime;
                }
                else
                {
                    playerController.blockLimitMessage      = false;
                    playerController.blockLimitMessageTimer = 0;
                }
            }

            // BUILDING INSTRUCTIONS
            if (playerController.building == true && !playerController.GuiOpen())
            {
                if (textureDictionary.dictionary.ContainsKey(playerController.buildType + "_Icon"))
                {
                    GUI.DrawTexture(guiCoordinates.currentBuildItemTextureRect, textureDictionary.dictionary[playerController.buildType + "_Icon"]);
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.currentBuildItemTextureRect, textureDictionary.dictionary[playerController.buildType]);
                }

                int buildItemCount = 0;
                foreach (InventorySlot slot in playerInventory.inventory)
                {
                    if (slot.typeInSlot.Equals(playerController.buildType))
                    {
                        buildItemCount += slot.amountInSlot;
                    }
                }

                if (IsStandardBlock(playerController.buildType))
                {
                    GUI.Label(guiCoordinates.buildItemCountRect, "" + buildItemCount + "\nx" + playerController.buildMultiplier);
                }
                else
                {
                    GUI.Label(guiCoordinates.buildItemCountRect, "" + buildItemCount);
                }

                if (playerController.machineInSight == null)
                {
                    GUI.DrawTexture(guiCoordinates.buildInfoRectBG, textureDictionary.dictionary["Interface Background"]);
                    int f = GUI.skin.label.fontSize;
                    GUI.skin.label.fontSize = 16;
                    GUI.Label(guiCoordinates.buildInfoRect, "Right click to place block.\nPress F to collect.\nPress R or Ctrl+R to rotate.\nPress B to stop building.");
                    GUI.skin.label.fontSize = f;
                }
            }

            // PAINT COLOR SELECTION WINDOW
            if (playerController.paintGunActive == true)
            {
                if (playerController.paintColorSelected == false)
                {
                    GUI.DrawTexture(guiCoordinates.paintGunMenuBackgroundRect, textureDictionary.dictionary["Menu Background"]);

                    int f = GUI.skin.label.fontSize;
                    GUI.skin.label.fontSize = 14;

                    GUIStyle style = GUI.skin.box;
                    style.alignment = TextAnchor.MiddleCenter;
                    GUIContent content   = new GUIContent("Paint Gun");
                    Vector2    size      = style.CalcSize(content);
                    Rect       titleRect = new Rect((Screen.width / 2) - (size.x / 2.5f), ScreenHeight * 0.05f, size.x, size.y);
                    GUI.Label(titleRect, "Paint Gun");

                    GUIStyle style2 = GUI.skin.box;
                    style2.alignment = TextAnchor.MiddleCenter;
                    GUIContent content2   = new GUIContent("Select Color");
                    Vector2    size2      = style2.CalcSize(content2);
                    Rect       titleRect2 = new Rect((Screen.width / 2) - (size2.x / 2.5f), ScreenHeight * 0.11f, size2.x, size2.y);
                    GUI.Label(titleRect2, "Select Color");

                    GUI.skin.label.fontSize = f;

                    GUI.Label(guiCoordinates.sliderLabel2Rect, "Red");
                    GUI.Label(guiCoordinates.sliderLabel3Rect, "Green");
                    GUI.Label(guiCoordinates.sliderLabel4Rect, "Blue");

                    playerController.paintRed   = GUI.HorizontalSlider(guiCoordinates.optionsButton5Rect, playerController.paintRed, 0, 1);
                    playerController.paintGreen = GUI.HorizontalSlider(guiCoordinates.optionsButton6Rect, playerController.paintGreen, 0, 1);
                    playerController.paintBlue  = GUI.HorizontalSlider(guiCoordinates.optionsButton7Rect, playerController.paintBlue, 0, 1);

                    Color paintcolor = new Color(playerController.paintRed, playerController.paintGreen, playerController.paintBlue);

                    Material tankMat     = playerController.paintGunTank.GetComponent <Renderer>().material;
                    Material adjTankMat  = playerController.adjustedPaintGunTank.GetComponent <Renderer>().material;
                    Material adjTank2Mat = playerController.adjustedPaintGunTank2.GetComponent <Renderer>().material;

                    tankMat.color     = paintcolor;
                    adjTankMat.color  = paintcolor;
                    adjTank2Mat.color = paintcolor;

                    GUI.color = paintcolor;
                    GUI.DrawTexture(guiCoordinates.optionsButton3Rect, paintSelectionTexture);
                    GUI.color = Color.white;

                    if (GUI.Button(guiCoordinates.optionsButton8Rect, "DONE"))
                    {
                        playerController.paintColorSelected = true;
                        Cursor.visible   = false;
                        Cursor.lockState = CursorLockMode.Locked;
                        gameObject.GetComponent <MSCameraController>().enabled = true;
                        playerController.PlayButtonSound();
                    }
                }
                else if (playerController.lookingAtCombinedMesh == true)
                {
                    GUI.DrawTexture(guiCoordinates.twoLineHighMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.highMessageRect, "Left click to paint.\nRight click to stop.");
                }
                else
                {
                    GUI.DrawTexture(guiCoordinates.longHighMessageBackgroundRect, textureDictionary.dictionary["Interface Background"]);
                    GUI.Label(guiCoordinates.longHighMessageRect, "Only structures can be painted...");
                }
            }

            // BUILD SETTINGS
            if (playerController.buildSettingsGuiOpen)
            {
                GUI.DrawTexture(guiCoordinates.buildSettingsRect, textureDictionary.dictionary["Menu Background"]);
                int f = GUI.skin.label.fontSize;
                GUI.skin.label.fontSize = 14;
                Vector2 size       = GetStringSize("Build Settings");
                Rect    messagePos = new Rect((Screen.width / 2) - (size.x / 2.2f), ScreenHeight * 0.14f, size.x, size.y);
                GUI.Label(messagePos, "Build Settings");
                GUI.skin.label.fontSize = f;

                GUI.Label(guiCoordinates.optionsButton3Rect, "Build Multiplier");

                string amountString = GUI.TextField(guiCoordinates.buildAmountTextFieldRect, playerController.buildMultiplier.ToString(), 3);
                try
                {
                    playerController.buildMultiplier = int.Parse(amountString);
                }
                catch
                {
                    // NOOP
                }

                int i = playerController.buildMultiplier;
                i = i > 100 ? 100 : i;
                playerController.buildMultiplier = i;

                GUI.Label(guiCoordinates.sliderLabel3Rect, "Machine Range " + "(" + (double)playerController.defaultRange / 10 + " meters" + ")");
                playerController.defaultRange = (int)GUI.HorizontalSlider(guiCoordinates.optionsButton6Rect, playerController.defaultRange, 10, 120);

                if (GUI.Button(guiCoordinates.optionsButton7Rect, "OK"))
                {
                    Cursor.visible   = false;
                    Cursor.lockState = CursorLockMode.Locked;
                    playerController.buildSettingsGuiOpen = false;
                    playerController.PlayButtonSound();
                }
            }

            // DOOR SETTINGS
            if (playerController.doorGUIopen)
            {
                GUI.DrawTexture(guiCoordinates.doorSettingsRect, textureDictionary.dictionary["Menu Background"]);
                int f = GUI.skin.label.fontSize;
                GUI.skin.label.fontSize = 12;
                GUI.Label(guiCoordinates.doorTitleRect, "Door Settings");
                GUI.skin.label.fontSize = f;

                if (GUI.Button(guiCoordinates.doorTextureRect, "Material"))
                {
                    Door door = playerController.doorToEdit;

                    if (door.textureIndex < door.textures.Length - 1)
                    {
                        door.textureIndex++;
                    }
                    else
                    {
                        door.textureIndex = 0;
                    }

                    door.material = door.textures[door.textureIndex];
                    gameManager.meshManager.SetMaterial(door.closedObject, door.material);
                    door.edited = true;
                    playerController.PlayButtonSound();
                }

                if (GUI.Button(guiCoordinates.doorSoundRect, "Sound"))
                {
                    Door door = playerController.doorToEdit;

                    if (door.audioClip < door.audioClips.Length - 1)
                    {
                        door.audioClip++;
                    }
                    else
                    {
                        door.audioClip = 0;
                    }

                    door.GetComponent <AudioSource>().clip = door.audioClips[door.audioClip];
                    door.GetComponent <AudioSource>().Play();
                }

                if (GUI.Button(guiCoordinates.doorCloseRect, "OK"))
                {
                    Cursor.visible               = false;
                    Cursor.lockState             = CursorLockMode.Locked;
                    playerController.doorGUIopen = false;
                    playerController.PlayButtonSound();
                }
            }

            // CROSSHAIR
            if (ShowCrosshair() == true)
            {
                GUIContent content = new GUIContent(Resources.Load("Crosshair") as Texture2D);
                GUIStyle   style   = GUI.skin.box;
                style.alignment = TextAnchor.MiddleCenter;
                Vector2 size = style.CalcSize(content);
                size.x = size.x / 3.5f;
                size.y = size.y / 4;
                Rect crosshairRect = new Rect((Screen.width / 2) - (size.x / 2), (Screen.height / 2) - (size.y / 2), size.x, size.y);
                GUI.DrawTexture(crosshairRect, textureDictionary.dictionary["Crosshair"]);
            }
        }
    }
예제 #17
0
    //! Called by unity engine for rendering and handling GUI events.
    public void OnGUI()
    {
        if (PlayerPrefsX.GetPersistentBool("multiplayer") == false || playerController.stateManager.worldLoaded == false || playerController.GuiOpen())
        {
            return;
        }

        GUI.skin = ChatGUIskin;

        int ScreenHeight = Screen.height;
        int ScreenWidth  = Screen.width;

        Rect textFieldRect = new Rect(0, (ScreenHeight * 0.80f), (ScreenWidth * 0.15f), (ScreenHeight * 0.03f));

        scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.Width(ScreenWidth * 0.4f), GUILayout.Height(ScreenHeight * 0.65f));
        GUILayout.Label(messages);
        GUILayout.EndScrollView();

        if (playerController.building == false && playerController.machineInSight == null)
        {
            GUI.SetNextControlName("textfield");
            inputMsg = GUI.TextField(textFieldRect, inputMsg, 300);

            if (GUI.GetNameOfFocusedControl() != "textfield")
            {
                GUI.color = new Color(0.2824f, 0.7882f, 0.9569f);
                GUI.Label(textFieldRect, "  Press backspace to chat.");
                GUI.color = Color.white;
            }

            Event ev = Event.current;
            if (ev.keyCode == KeyCode.Backspace)
            {
                GUI.FocusControl("textfield");
            }

            Event e = Event.current;
            if (e.keyCode == KeyCode.Return)
            {
                if (inputMsg != "")
                {
                    if (inputMsg == "/list" || inputMsg == "/players")
                    {
                        NetworkPlayer[] allPlayers = FindObjectsOfType <NetworkPlayer>();
                        playerCount = allPlayers.Length + 1;
                        List <string> nameList = new List <string>();
                        nameList.Add(PlayerPrefs.GetString("UserName"));
                        foreach (NetworkPlayer player in allPlayers)
                        {
                            nameList.Add(player.gameObject.name);
                        }
                        playersOnline  = string.Join("\n", nameList.ToArray());
                        playersVisible = true;
                    }
                    else
                    {
                        networkController.networkSend.SendChatMessage(inputMsg);
                    }
                    inputMsg = "";
                }
                GUIUtility.keyboardControl = 0;
            }

            if (playersVisible == true)
            {
                messages      += "\n\n" + playerCount + " players online.";
                messages      += "\n" + playersOnline + "\n\n";
                playersVisible = false;
            }
        }

        if (messages.Length >= 500)
        {
            messages = "";
        }

        scrollPosition.y += 1000;
    }
예제 #18
0
    //! Places standard building blocks in the world.
    private IEnumerator BuildBlockCoroutine(string type)
    {
        bool canBuild = true;

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            canBuild = CanBuild();
        }

        if (canBuild == true)
        {
            bool foundItems = false;
            foreach (InventorySlot slot in playerController.playerInventory.inventory)
            {
                if (foundItems == false)
                {
                    if (slot.amountInSlot >= playerController.buildMultiplier)
                    {
                        if (slot.typeInSlot.Equals(type))
                        {
                            foundItems = true;
                            int        h                   = 0;
                            Vector3    origin              = playerController.buildObject.transform.position;
                            string     direction           = playerController.cubeloc;
                            Quaternion rotation            = playerController.buildObject.transform.rotation;
                            Vector3    multiBuildPlacement = playerController.buildObject.transform.position;
                            slot.amountInSlot -= playerController.buildMultiplier;
                            for (int i = 0; i < playerController.buildMultiplier; i++)
                            {
                                if (direction == "up")
                                {
                                    multiBuildPlacement = new Vector3(origin.x, origin.y + h, origin.z);
                                }
                                if (direction == "down")
                                {
                                    multiBuildPlacement = new Vector3(origin.x, origin.y - h, origin.z);
                                }
                                if (direction == "left")
                                {
                                    multiBuildPlacement = new Vector3(origin.x + h, origin.y, origin.z);
                                }
                                if (direction == "right")
                                {
                                    multiBuildPlacement = new Vector3(origin.x - h, origin.y, origin.z);
                                }
                                if (direction == "front")
                                {
                                    multiBuildPlacement = new Vector3(origin.x, origin.y, origin.z + h);
                                }
                                if (direction == "back")
                                {
                                    multiBuildPlacement = new Vector3(origin.x, origin.y, origin.z - h);
                                }
                                h += 5;
                                GameObject obj = Instantiate(blockDictionary.blockDictionary[type], multiBuildPlacement, rotation);
                                if (obj.GetComponent <ModBlock>() != null)
                                {
                                    obj.GetComponent <ModBlock>().blockName = type;
                                }
                                obj.transform.parent = builtObjects.transform;
                                gameManager.undoBlocks.Add(new GameManager.Block(type, obj));
                                playerController.builderSound.clip = playerController.buildMultiplier > 1 ? multiBuildClip : singleBuildClip;
                                playerController.builderSound.Play();
                                if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                {
                                    UpdateNetwork(0, type, obj.transform.position, obj.transform.rotation);
                                }
                                yield return(null);
                            }
                        }
                        if (slot.amountInSlot == 0)
                        {
                            slot.typeInSlot = "nothing";
                        }
                    }
                }
            }
            if (foundItems == false)
            {
                playerController.PlayMissingItemsSound();
            }
        }
        else
        {
            playerController.PlayMissingItemsSound();
        }
    }
예제 #19
0
    //! Called by unity engine for rendering and handling GUI events.
    public void OnGUI()
    {
        // STYLE
        GUI.skin = GetComponent <PlayerGUI>().thisGUIskin;

        // ASPECT RATIO
        float ScreenHeight = Screen.height;
        float ScreenWidth  = Screen.width;

        if (ScreenWidth / ScreenHeight < 1.7f)
        {
            ScreenHeight = (ScreenHeight * 0.75f);
        }
        if (ScreenHeight < 700)
        {
            GUI.skin.label.fontSize = 10;
        }

        if (!playerController.stateManager.Busy() && GetComponent <MainMenu>().finishedLoading == true)
        {
            // MACHINE CONTROL GUI
            if (playerController.inventoryOpen == false && playerController.machineGUIopen == true && playerController.objectInSight != null)
            {
                GameObject obj = playerController.objectInSight;

                if (obj.GetComponent <PowerConduit>() != null)
                {
                    bool         netFlag      = false;
                    PowerConduit powerConduit = obj.GetComponent <PowerConduit>();
                    if (powerConduit.connectionFailed == false)
                    {
                        GUI.DrawTexture(guiCoordinates.FourButtonSpeedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.outputLabelRect, "Range");
                        powerConduit.range = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, powerConduit.range, 6, 120);
                        if (GUI.Button(guiCoordinates.outputControlButton3Rect, "Dual Output: " + powerConduit.dualOutput))
                        {
                            if (powerConduit.dualOutput == true)
                            {
                                powerConduit.dualOutput = false;
                            }
                            else
                            {
                                powerConduit.dualOutput = true;
                            }
                            playerController.PlayButtonSound();
                        }
                        if (GUI.Button(guiCoordinates.outputControlButton4Rect, "Close"))
                        {
                            playerController.machineGUIopen = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    else
                    {
                        GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            powerConduit.connectionAttempts = 0;
                            powerConduit.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        bool rangeDeSync  = powerConduit.range != playerController.networkedConduitRange;
                        bool outputDeSync = powerConduit.dualOutput != playerController.networkedDualPower;
                        if (rangeDeSync || outputDeSync || netFlag)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = powerConduit.gameObject.transform.position;
                            updateNetworkConduitCoroutine          = StartCoroutine(net.SendPowerData(location, powerConduit.range, powerConduit.dualOutput));
                            playerController.networkedConduitRange = powerConduit.range;
                            playerController.networkedDualPower    = powerConduit.dualOutput;
                        }
                    }
                }

                if (obj.GetComponent <RailCartHub>() != null)
                {
                    bool        netFlag = false;
                    RailCartHub hub     = obj.GetComponent <RailCartHub>();
                    if (hub.connectionFailed == false)
                    {
                        if (hubStopWindowOpen == false)
                        {
                            GUI.DrawTexture(guiCoordinates.FiveButtonSpeedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                            GUI.Label(guiCoordinates.railCartHubCircuitLabelRect, "Circuit");
                            int    circuit       = hub.circuit;
                            string circuitString = GUI.TextField(guiCoordinates.railCartHubCircuitRect, circuit.ToString(), 3);
                            try
                            {
                                hub.circuit = int.Parse(circuitString);
                            }
                            catch
                            {
                                // NOOP
                            }
                            GUI.Label(guiCoordinates.outputLabelRect, "Range");
                            hub.range = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, hub.range, 6, 120);
                            if (GUI.Button(guiCoordinates.outputControlButton3Rect, "Stop Settings"))
                            {
                                hubStopWindowOpen = true;
                                playerController.PlayButtonSound();
                            }
                            if (GUI.Button(guiCoordinates.outputControlButton4Rect, "Close"))
                            {
                                playerController.machineGUIopen = false;
                                hubStopWindowOpen = false;
                                playerController.PlayButtonSound();
                            }
                        }
                        else
                        {
                            GUI.DrawTexture(guiCoordinates.FiveButtonSpeedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                            GUI.Label(guiCoordinates.longOutputLabelRect, "Stop Time");
                            if (GUI.Button(guiCoordinates.outputControlButton0Rect, "Stop: " + hub.stop))
                            {
                                if (hub.stop == true)
                                {
                                    hub.stop = false;
                                }
                                else
                                {
                                    hub.stop = true;
                                }
                                playerController.PlayButtonSound();
                            }
                            hub.stopTime = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, hub.stopTime, 0, 600);
                            if (GUI.Button(guiCoordinates.outputControlButton3Rect, "Range Settings"))
                            {
                                hubStopWindowOpen = false;
                                playerController.PlayButtonSound();
                            }
                            if (GUI.Button(guiCoordinates.outputControlButton4Rect, "Close"))
                            {
                                playerController.machineGUIopen = false;
                                hubStopWindowOpen = false;
                                playerController.PlayButtonSound();
                            }
                        }
                    }
                    else
                    {
                        GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            hub.connectionAttempts = 0;
                            hub.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        bool circuitDeSync = hub.circuit != playerController.networkedHubCircuit;
                        bool rangeDeSync   = hub.range != playerController.networkedHubRange;
                        bool stopDeSync    = hub.stop != playerController.networkedHubStop;
                        bool timeDeSync    = (int)hub.stopTime != (int)playerController.networkedHubStopTime;
                        if (circuitDeSync || rangeDeSync || stopDeSync || timeDeSync || netFlag)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = hub.gameObject.transform.position;
                            updateNetworkConduitCoroutine         = StartCoroutine(net.SendHubData(location, hub.circuit, hub.range, hub.stop, hub.stopTime));
                            playerController.networkedHubCircuit  = hub.circuit;
                            playerController.networkedHubRange    = hub.range;
                            playerController.networkedHubStop     = hub.stop;
                            playerController.networkedHubStopTime = hub.stopTime;
                        }
                    }
                }

                if (obj.GetComponent <Retriever>() != null)
                {
                    bool      netFlag   = false;
                    Retriever retriever = obj.GetComponent <Retriever>();
                    if (retriever.connectionFailed == false)
                    {
                        GUI.DrawTexture(guiCoordinates.FourButtonSpeedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        if (retriever.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            retriever.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, retriever.speed, 0, retriever.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                        if (GUI.Button(guiCoordinates.outputControlButton3Rect, "Choose Items"))
                        {
                            if (obj.GetComponent <InventoryManager>().initialized == true)
                            {
                                playerController.inventoryOpen  = true;
                                playerController.storageGUIopen = true;
                                playerController.machineGUIopen = false;
                                playerController.PlayButtonSound();
                            }
                        }
                        if (GUI.Button(guiCoordinates.outputControlButton4Rect, "Close"))
                        {
                            playerController.machineGUIopen = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    else
                    {
                        GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            retriever.connectionAttempts = 0;
                            retriever.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (retriever.speed != playerController.networkedConduitRange || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = retriever.gameObject.transform.position;
                            updateNetworkConduitCoroutine          = StartCoroutine(net.SendConduitData(location, retriever.speed));
                            playerController.networkedConduitRange = retriever.speed;
                        }
                    }
                }

                if (obj.GetComponent <AutoCrafter>() != null)
                {
                    bool        netFlag     = false;
                    AutoCrafter autoCrafter = obj.GetComponent <AutoCrafter>();
                    if (autoCrafter.connectionFailed == false)
                    {
                        GUI.DrawTexture(guiCoordinates.FourButtonSpeedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        if (autoCrafter.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            autoCrafter.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, autoCrafter.speed, 0, autoCrafter.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                        if (GUI.Button(guiCoordinates.outputControlButton3Rect, "Choose Item"))
                        {
                            if (obj.GetComponent <InventoryManager>().initialized == true)
                            {
                                playerController.inventoryOpen  = true;
                                playerController.storageGUIopen = true;
                                playerController.machineGUIopen = false;
                                playerController.PlayButtonSound();
                            }
                        }
                        if (GUI.Button(guiCoordinates.outputControlButton4Rect, "Close"))
                        {
                            playerController.machineGUIopen = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    else
                    {
                        GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            autoCrafter.connectionAttempts = 0;
                            autoCrafter.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (autoCrafter.speed != playerController.networkedConduitRange || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = autoCrafter.gameObject.transform.position;
                            updateNetworkConduitCoroutine          = StartCoroutine(net.SendConduitData(location, autoCrafter.speed));
                            playerController.networkedConduitRange = autoCrafter.speed;
                        }
                    }
                }

                if (obj.GetComponent <UniversalConduit>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    UniversalConduit conduit = obj.GetComponent <UniversalConduit>();
                    if (conduit.connectionFailed == false)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Range");
                        conduit.range = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, conduit.range, 6, 120);
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            conduit.connectionAttempts = 0;
                            conduit.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (conduit.range != playerController.networkedConduitRange || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = conduit.gameObject.transform.position;
                            updateNetworkConduitCoroutine          = StartCoroutine(net.SendConduitData(location, conduit.range));
                            playerController.networkedConduitRange = conduit.range;
                        }
                    }
                }

                if (obj.GetComponent <DarkMatterConduit>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    DarkMatterConduit conduit = obj.GetComponent <DarkMatterConduit>();
                    if (conduit.connectionFailed == false)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Range");
                        conduit.range = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, conduit.range, 6, 120);
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            conduit.connectionAttempts = 0;
                            conduit.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (conduit.range != playerController.networkedConduitRange || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = conduit.gameObject.transform.position;
                            updateNetworkConduitCoroutine          = StartCoroutine(net.SendConduitData(location, conduit.range));
                            playerController.networkedConduitRange = conduit.range;
                        }
                    }
                }

                if (obj.GetComponent <HeatExchanger>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    HeatExchanger hx = obj.GetComponent <HeatExchanger>();
                    if (hx.inputObject != null)
                    {
                        if (hx.inputObject.GetComponent <UniversalConduit>() != null)
                        {
                            if (hx.connectionFailed == false)
                            {
                                GUI.Label(guiCoordinates.outputLabelRect, "Output");
                                hx.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, hx.speed, 0, playerController.hxAmount);
                            }
                            else
                            {
                                GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                                if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                                {
                                    netFlag = true;
                                    hx.connectionAttempts = 0;
                                    hx.connectionFailed   = false;
                                    playerController.PlayButtonSound();
                                }
                            }
                            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                            {
                                if (hx.speed != playerController.networkedMachineSpeed || netFlag == true)
                                {
                                    NetworkSend net      = playerController.networkController.networkSend;
                                    Vector3     location = hx.gameObject.transform.position;
                                    updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, hx.speed));
                                    playerController.networkedMachineSpeed = hx.speed;
                                }
                            }
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Input");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "No Input");
                    }
                }

                if (obj.GetComponent <PowerSource>() != null)
                {
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    PowerSource powerSource = obj.GetComponent <PowerSource>();
                    if (powerSource.connectionFailed == true)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            powerSource.connectionAttempts = 0;
                            powerSource.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Online");
                    }
                }

                if (obj.GetComponent <Auger>() != null)
                {
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    Auger auger = obj.GetComponent <Auger>();
                    if (auger.power > 0)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Output");
                        auger.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, auger.speed, 0, auger.power);
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (auger.speed != playerController.networkedMachineSpeed)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = auger.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, auger.speed));
                            playerController.networkedMachineSpeed = auger.speed;
                        }
                    }
                }

                if (obj.GetComponent <UniversalExtractor>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    UniversalExtractor extractor = obj.GetComponent <UniversalExtractor>();
                    if (extractor.connectionFailed == false)
                    {
                        if (extractor.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            extractor.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, extractor.speed, 0, extractor.power);
                        }
                        else
                        {
                            GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            extractor.connectionAttempts = 0;
                            extractor.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (extractor.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = extractor.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, extractor.speed));
                            playerController.networkedMachineSpeed = extractor.speed;
                        }
                    }
                }
                if (obj.GetComponent <DarkMatterCollector>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    DarkMatterCollector collector = obj.GetComponent <DarkMatterCollector>();
                    if (collector.connectionFailed == false)
                    {
                        if (collector.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            collector.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, collector.speed, 0, collector.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            collector.connectionAttempts = 0;
                            collector.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (collector.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = collector.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, collector.speed));
                            playerController.networkedMachineSpeed = collector.speed;
                        }
                    }
                }

                if (obj.GetComponent <Smelter>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    Smelter smelter = obj.GetComponent <Smelter>();
                    if (smelter.connectionFailed == false)
                    {
                        if (smelter.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            smelter.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, smelter.speed, 0, smelter.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            smelter.connectionAttempts = 0;
                            smelter.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (smelter.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = smelter.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, smelter.speed));
                            playerController.networkedMachineSpeed = smelter.speed;
                        }
                    }
                }

                if (obj.GetComponent <AlloySmelter>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    AlloySmelter alloySmelter = obj.GetComponent <AlloySmelter>();
                    if (alloySmelter.connectionFailed == false)
                    {
                        if (alloySmelter.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            alloySmelter.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, alloySmelter.speed, 0, alloySmelter.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            alloySmelter.connectionAttempts = 0;
                            alloySmelter.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (alloySmelter.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = alloySmelter.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, alloySmelter.speed));
                            playerController.networkedMachineSpeed = alloySmelter.speed;
                        }
                    }
                }

                if (obj.GetComponent <Press>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    Press press = obj.GetComponent <Press>();
                    if (press.connectionFailed == false)
                    {
                        if (press.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            press.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, press.speed, 0, press.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            press.connectionAttempts = 0;
                            press.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (press.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = press.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, press.speed));
                            playerController.networkedMachineSpeed = press.speed;
                        }
                    }
                }

                if (obj.GetComponent <Extruder>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    Extruder extruder = obj.GetComponent <Extruder>();
                    if (extruder.connectionFailed == false)
                    {
                        if (extruder.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            extruder.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, extruder.speed, 0, extruder.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            extruder.connectionAttempts = 0;
                            extruder.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (extruder.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = extruder.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, extruder.speed));
                            playerController.networkedMachineSpeed = extruder.speed;
                        }
                    }
                }

                if (obj.GetComponent <ModMachine>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    ModMachine modMachine = obj.GetComponent <ModMachine>();
                    if (modMachine.connectionFailed == false)
                    {
                        if (modMachine.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            modMachine.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, modMachine.speed, 0, modMachine.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            modMachine.connectionAttempts = 0;
                            modMachine.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (modMachine.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = modMachine.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, modMachine.speed));
                            playerController.networkedMachineSpeed = modMachine.speed;
                        }
                    }
                }

                if (obj.GetComponent <Turret>() != null)
                {
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    Turret turret = obj.GetComponent <Turret>();
                    if (turret.power > 0)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Output");
                        if (turret.power < 30)
                        {
                            turret.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, turret.speed, 0, turret.power);
                        }
                        else
                        {
                            turret.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, turret.speed, 0, 30);
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (turret.speed != playerController.networkedMachineSpeed)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = turret.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, turret.speed));
                            playerController.networkedMachineSpeed = turret.speed;
                        }
                    }
                }

                if (obj.GetComponent <MissileTurret>() != null)
                {
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    MissileTurret turret = obj.GetComponent <MissileTurret>();
                    if (turret.power > 0)
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Output");
                        if (turret.power < 30)
                        {
                            turret.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, turret.speed, 0, turret.power);
                        }
                        else
                        {
                            turret.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, turret.speed, 0, 30);
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (turret.speed != playerController.networkedMachineSpeed)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = turret.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, turret.speed));
                            playerController.networkedMachineSpeed = turret.speed;
                        }
                    }
                }

                if (obj.GetComponent <GearCutter>() != null)
                {
                    bool netFlag = false;
                    GUI.DrawTexture(guiCoordinates.speedControlBGRect, textureDictionary.dictionary["Interface Background"]);
                    GearCutter gearCutter = obj.GetComponent <GearCutter>();
                    if (gearCutter.connectionFailed == false)
                    {
                        if (gearCutter.power > 0)
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "Output");
                            gearCutter.speed = (int)GUI.HorizontalSlider(guiCoordinates.outputControlButton2Rect, gearCutter.speed, 0, gearCutter.power);
                        }
                        else
                        {
                            GUI.Label(guiCoordinates.outputLabelRect, "No Power");
                        }
                    }
                    else
                    {
                        GUI.Label(guiCoordinates.outputLabelRect, "Offline");
                        if (GUI.Button(guiCoordinates.outputControlButton2Rect, "Reboot"))
                        {
                            netFlag = true;
                            gearCutter.connectionAttempts = 0;
                            gearCutter.connectionFailed   = false;
                            playerController.PlayButtonSound();
                        }
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        if (gearCutter.speed != playerController.networkedMachineSpeed || netFlag == true)
                        {
                            NetworkSend net      = playerController.networkController.networkSend;
                            Vector3     location = gearCutter.gameObject.transform.position;
                            updateNetworkMachineCoroutine          = StartCoroutine(net.SendMachineData(location, gearCutter.speed));
                            playerController.networkedMachineSpeed = gearCutter.speed;
                        }
                    }
                }
            }
            else
            {
                hubStopWindowOpen = false;
                gameObject.GetComponent <MSCameraController>().enabled = true;
            }
        }
    }
예제 #20
0
    //! Drops an item into an inventory slot.
    public void DropItemInSlot(Vector2 mousePos, bool usingContainer)
    {
        playerController.draggingItem = false;

        if (guiCoordinates.inventoryDropSlotRect.Contains(mousePos))
        {
            playerController.DropItem(slotDraggingFrom);
            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
            {
                NetworkRemoveItem();
            }
            return;
        }

        if (guiCoordinates.inventoryTrashSlotRect.Contains(mousePos))
        {
            slotDraggingFrom.amountInSlot = 0;
            slotDraggingFrom.typeInSlot   = "nothing";
            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
            {
                NetworkRemoveItem();
            }
            playerController.PlayCraftingSound();
            return;
        }

        int inventoryDropSlot = 0;

        foreach (Rect rect in guiCoordinates.inventorySlotRects)
        {
            InventorySlot dropSlot = playerInventory.inventory[inventoryDropSlot];
            if (rect.Contains(mousePos) && slotDraggingFrom != dropSlot)
            {
                if (dropSlot.typeInSlot == "nothing" || dropSlot.typeInSlot == "" || dropSlot.typeInSlot == itemToDrag)
                {
                    if (dropSlot.amountInSlot <= playerInventory.maxStackSize - amountToDrag)
                    {
                        playerInventory.AddItemToSlot(itemToDrag, amountToDrag, inventoryDropSlot);
                        slotDraggingFrom.amountInSlot -= amountToDrag;
                        if (slotDraggingFrom.amountInSlot <= 0)
                        {
                            slotDraggingFrom.typeInSlot = "nothing";
                        }
                    }
                }
                else
                {
                    slotDraggingFrom.typeInSlot   = dropSlot.typeInSlot;
                    slotDraggingFrom.amountInSlot = dropSlot.amountInSlot;
                    dropSlot.typeInSlot           = itemToDrag;
                    dropSlot.amountInSlot         = amountToDrag;
                }
                if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                {
                    bool flag = false;
                    foreach (InventorySlot slot in playerInventory.inventory)
                    {
                        if (slot == slotDraggingFrom)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag == false)
                    {
                        Vector3 pos = playerController.storageInventory.gameObject.transform.position;
                        float   x   = Mathf.Round(pos.x);
                        float   y   = Mathf.Round(pos.y);
                        float   z   = Mathf.Round(pos.z);
                        using (WebClient client = new WebClient())
                        {
                            Uri uri = new Uri(PlayerPrefs.GetString("serverURL") + "/storage");
                            client.UploadStringAsync(uri, "POST", "@" + x + "," + y + "," + z + ":" + dragSlotIndex + ";" + slotDraggingFrom.typeInSlot + "=" + slotDraggingFrom.amountInSlot);
                        }
                    }
                }
            }
            inventoryDropSlot++;
        }

        if (usingContainer == true)
        {
            int storageInventoryDropSlot = 0;
            foreach (Rect rect in guiCoordinates.storageInventorySlotRects)
            {
                InventorySlot dropSlot = playerController.storageInventory.inventory[storageInventoryDropSlot];
                if (rect.Contains(mousePos) && slotDraggingFrom != dropSlot)
                {
                    if (dropSlot.typeInSlot == "nothing" || dropSlot.typeInSlot == "" || dropSlot.typeInSlot == itemToDrag)
                    {
                        if (dropSlot.amountInSlot <= playerController.storageInventory.maxStackSize - amountToDrag)
                        {
                            playerController.storageInventory.AddItemToSlot(itemToDrag, amountToDrag, storageInventoryDropSlot);
                            slotDraggingFrom.amountInSlot -= amountToDrag;
                            if (slotDraggingFrom.amountInSlot <= 0)
                            {
                                slotDraggingFrom.typeInSlot = "nothing";
                            }
                        }
                    }
                    else
                    {
                        slotDraggingFrom.typeInSlot   = dropSlot.typeInSlot;
                        slotDraggingFrom.amountInSlot = dropSlot.amountInSlot;
                        dropSlot.typeInSlot           = itemToDrag;
                        dropSlot.amountInSlot         = amountToDrag;
                    }
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                    {
                        slotDraggingFrom.pendingNetworkUpdate = true;
                        slotDraggingFrom.networkWaitTime      = 0;
                        bool flag = false;
                        foreach (InventorySlot slot in playerInventory.inventory)
                        {
                            if (slot == slotDraggingFrom)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == false && networkContainerCoroutineBusy == false)
                        {
                            string originType   = slotDraggingFrom.typeInSlot;
                            int    originAmount = slotDraggingFrom.amountInSlot;
                            networkContainerCoroutine = playerController.StartCoroutine(NetworkContainerCoroutine(storageInventoryDropSlot, dropSlot, originType, originAmount));
                        }
                    }
                }
                storageInventoryDropSlot++;
            }
        }
    }
예제 #21
0
    //! Called when the player is looking at a storage computer.
    public void InteractWithStorageComputer()
    {
        playerController.machineGUIopen = false;
        playerController.machineInSight = playerController.objectInSight;
        StorageComputer computer = playerController.objectInSight.GetComponent <StorageComputer>();

        playerController.machineID       = computer.ID;
        playerController.machineHasPower = computer.powerON;
        if (cInput.GetKeyDown("Interact"))
        {
            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
            {
                if (!interactionController.CanInteract())
                {
                    return;
                }
            }
            if (playerController.storageGUIopen == false)
            {
                if (computer.powerON == true && computer.initialized == true)
                {
                    bool foundContainer = false;
                    int  containerCount = 0;
                    foreach (InventoryManager manager in computer.computerContainers)
                    {
                        if (foundContainer == false)
                        {
                            if (computer.computerContainers[containerCount] != null)
                            {
                                Cursor.visible   = true;
                                Cursor.lockState = CursorLockMode.None;
                                playerController.storageGUIopen         = true;
                                playerController.craftingGUIopen        = false;
                                playerController.machineGUIopen         = false;
                                playerController.inventoryOpen          = true;
                                playerController.storageInventory       = computer.computerContainers[0];
                                playerController.currentStorageComputer = playerController.objectInSight;
                                playerController.remoteStorageActive    = true;
                                foundContainer = true;
                            }
                            containerCount++;
                        }
                    }
                    if (foundContainer == false)
                    {
                        computer.Reboot();
                    }
                }
            }
            else
            {
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
                playerController.inventoryOpen   = false;
                playerController.craftingGUIopen = false;
                playerController.machineGUIopen  = false;
                playerController.storageGUIopen  = false;
            }
        }
        if (cInput.GetKeyDown("Collect Object"))
        {
            interactionController.CollectObject("Storage Computer");
        }
    }
예제 #22
0
    //! Called when the player is looking at a storage container.
    public void InteractWithStorageContainer()
    {
        playerController.machineGUIopen = false;
        InventoryManager inventory = playerController.objectInSight.GetComponent <InventoryManager>();

        if (cInput.GetKeyDown("Interact"))
        {
            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
            {
                if (!interactionController.CanInteract())
                {
                    return;
                }
            }
            if (playerController.storageGUIopen == false)
            {
                if (inventory.initialized == true)
                {
                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                    playerController.storageGUIopen      = true;
                    playerController.craftingGUIopen     = false;
                    playerController.machineGUIopen      = false;
                    playerController.inventoryOpen       = true;
                    playerController.storageInventory    = inventory;
                    playerController.remoteStorageActive = false;
                }
            }
            else
            {
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
                playerController.inventoryOpen   = false;
                playerController.craftingGUIopen = false;
                playerController.machineGUIopen  = false;
                playerController.storageGUIopen  = false;
            }
        }
        if (cInput.GetKeyDown("Collect Object") && inventory.ID != "Rocket" && inventory.ID != "Lander")
        {
            bool spaceAvailable = false;
            foreach (InventorySlot slot in playerController.playerInventory.inventory)
            {
                if (slot.typeInSlot.Equals("nothing") || slot.typeInSlot.Equals("Storage Container") && slot.amountInSlot < 1000)
                {
                    spaceAvailable = true;
                }
            }
            if (spaceAvailable == true)
            {
                InventoryManager thisContainer = inventory;
                foreach (InventorySlot slot in thisContainer.inventory)
                {
                    slot.typeInSlot   = "nothing";
                    slot.amountInSlot = 0;
                }
                thisContainer.SaveData();
                if (playerController.objectInSight.GetComponent <RailCart>() != null)
                {
                    interactionController.CollectObject("Rail Cart");
                }
                else
                {
                    interactionController.CollectObject("Storage Container");
                }
                Object.Destroy(playerController.objectInSight);
                playerController.PlayCraftingSound();
            }
            else
            {
                playerController.cannotCollect = true;
                playerController.PlayCraftingSound();
            }
        }
    }
예제 #23
0
    //! Called once per frame by unity engine.
    public void Update()
    {
        if (FileBasedPrefs.initialized == true)
        {
            if (FileBasedPrefs.GetBool(GetComponent <StateManager>().worldName + "Initialized") == false)
            {
                if (lander.GetComponent <InventoryManager>().initialized == true)
                {
                    lander.GetComponent <InventoryManager>().AddItem("Solar Panel", 9);
                    lander.GetComponent <InventoryManager>().AddItem("Universal Conduit", 8);
                    lander.GetComponent <InventoryManager>().AddItem("Storage Container", 4);
                    lander.GetComponent <InventoryManager>().AddItem("Smelter", 3);
                    lander.GetComponent <InventoryManager>().AddItem("Universal Extractor", 2);
                    lander.GetComponent <InventoryManager>().AddItem("Dark Matter Conduit", 1);
                    lander.GetComponent <InventoryManager>().AddItem("Dark Matter Collector", 1);
                    FileBasedPrefs.SetBool(GetComponent <StateManager>().worldName + "Initialized", true);
                }
            }
            else
            {
                if (loadedBlockPhysics == false)
                {
                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == false)
                    {
                        blockPhysics = PlayerPrefsX.GetPersistentBool("blockPhysics");
                    }
                    else
                    {
                        blockPhysics = false;
                    }
                    loadedBlockPhysics = true;
                }
                if (loadedHazardsEnabled == false)
                {
                    hazardsEnabled       = PlayerPrefsX.GetPersistentBool("hazardsEnabled");
                    loadedHazardsEnabled = true;
                }
                if (loadedMeteorTimer == false)
                {
                    meteorShowerTimer = FileBasedPrefs.GetFloat(GetComponent <StateManager>().worldName + "meteorShowerTimer");
                    loadedMeteorTimer = true;
                }
                if (loadedPirateTimer == false)
                {
                    pirateAttackTimer = FileBasedPrefs.GetFloat(GetComponent <StateManager>().worldName + "pirateAttackTimer");
                    loadedPirateTimer = true;
                }
            }

            // A save game request is pending.
            if (dataSaveRequested == true)
            {
                if (GetComponent <StateManager>().saving == false && GetComponent <StateManager>().AddressManagerBusy() == false)
                {
                    UnityEngine.Debug.Log("Saving world...");
                    GetComponent <StateManager>().SaveData();
                    dataSaveRequested = false;
                }
                else if (GetComponent <StateManager>().AddressManagerBusy() == true)
                {
                    if (GetComponent <GameManager>().simulationSpeed < 0.1f)
                    {
                        userSimSpeed  = GetComponent <GameManager>().simulationSpeed;
                        resetSimSpeed = true;
                    }
                    GetComponent <GameManager>().simulationSpeed = 0.1f;
                }
            }
            else if (resetSimSpeed == true)
            {
                GetComponent <GameManager>().simulationSpeed = userSimSpeed;
                resetSimSpeed = false;
            }

            // Used to ensure components are removed before combining meshes.
            if (replacingMeshFilters == true)
            {
                mfDelay += 1 * Time.deltaTime;
                if (mfDelay > 1)
                {
                    meshManager.CombineMeshes();
                    mfDelay = 0;
                    replacingMeshFilters = false;
                }
            }

            if (GetComponent <StateManager>().worldLoaded == true)
            {
                hazardManager.UpdateHazards();
            }

            if (memoryCoroutineBusy == false)
            {
                memoryCoroutine = StartCoroutine(ManageMemory());
            }
        }
    }
예제 #24
0
    //! Places a machine in the world.
    private void BuildMachine(string type, RaycastHit hit)
    {
        bool canBuild = true;

        if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
        {
            canBuild = CanBuild();
        }
        else
        {
            canBuild = playerController.buildType != "Protection Block";
        }

        if (canBuild == true)
        {
            bool foundItems = false;
            gameManager.undoBlocks.Clear();
            foreach (InventorySlot slot in playerController.playerInventory.inventory)
            {
                if (foundItems == false)
                {
                    if (slot.amountInSlot > 0)
                    {
                        if (slot.typeInSlot.Equals(type))
                        {
                            foundItems = true;
                            bool flag = true;
                            if (type.Equals("Rail Cart"))
                            {
                                if (hit.collider.gameObject.GetComponent <RailCartHub>() != null)
                                {
                                    flag = true;
                                }
                                else
                                {
                                    playerController.invalidRailCartPlacement = true;
                                    flag = false;
                                }
                            }
                            else if (type.Equals("Auger"))
                            {
                                if (hit.collider.gameObject.tag.Equals("Landscape"))
                                {
                                    flag = true;
                                }
                                else
                                {
                                    playerController.invalidAugerPlacement = true;
                                    flag = false;
                                }
                            }
                            if (flag == true)
                            {
                                GameObject t   = blockDictionary.machineDictionary[type];
                                Vector3    pos = playerController.buildObject.transform.position;
                                Quaternion rot = playerController.buildObject.transform.rotation;
                                GameObject obj = Instantiate(t, pos, rot);
                                if (obj.GetComponent <RailCart>() != null)
                                {
                                    obj.GetComponent <RailCart>().target        = hit.collider.gameObject;
                                    obj.GetComponent <RailCart>().startPosition = pos;
                                }
                                if (obj.GetComponent <ModMachine>() != null)
                                {
                                    obj.GetComponent <ModMachine>().machineName = type;
                                }
                                if (obj.GetComponent <UniversalConduit>() != null)
                                {
                                    obj.GetComponent <UniversalConduit>().range = playerController.defaultRange;
                                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                    {
                                        NetworkSend net      = playerController.networkController.networkSend;
                                        Vector3     location = obj.transform.position;
                                        updateNetworkCoroutine = StartCoroutine(net.SendConduitData(location, playerController.defaultRange));
                                    }
                                }
                                if (obj.GetComponent <PowerConduit>() != null)
                                {
                                    obj.GetComponent <PowerConduit>().range = playerController.defaultRange;
                                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                    {
                                        NetworkSend net        = playerController.networkController.networkSend;
                                        Vector3     location   = obj.transform.position;
                                        int         range      = playerController.defaultRange;
                                        bool        dualOutput = obj.GetComponent <PowerConduit>().dualOutput;
                                        updateNetworkCoroutine = StartCoroutine(net.SendPowerData(location, range, dualOutput));
                                    }
                                }
                                if (obj.GetComponent <DarkMatterConduit>() != null)
                                {
                                    obj.GetComponent <DarkMatterConduit>().range = playerController.defaultRange;
                                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                    {
                                        NetworkSend net      = playerController.networkController.networkSend;
                                        Vector3     location = obj.transform.position;
                                        updateNetworkCoroutine = StartCoroutine(net.SendConduitData(location, playerController.defaultRange));
                                    }
                                }
                                if (obj.GetComponent <RailCartHub>() != null)
                                {
                                    obj.GetComponent <RailCartHub>().range = playerController.defaultRange;
                                    if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                    {
                                        NetworkSend net      = playerController.networkController.networkSend;
                                        RailCartHub hub      = obj.GetComponent <RailCartHub>();
                                        Vector3     location = obj.transform.position;
                                        int         range    = playerController.defaultRange;
                                        updateNetworkCoroutine = StartCoroutine(net.SendHubData(location, hub.circuit, hub.range, hub.stop, hub.stopTime));
                                    }
                                }
                                gameManager.undoBlocks.Add(new GameManager.Block(type, obj));
                                slot.amountInSlot -= 1;
                                playerController.builderSound.clip = singleBuildClip;
                                playerController.builderSound.Play();
                                if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                                {
                                    UpdateNetwork(0, type, pos, obj.transform.rotation);
                                }
                            }
                        }
                        if (slot.amountInSlot == 0)
                        {
                            slot.typeInSlot = "nothing";
                        }
                    }
                }
            }
            if (foundItems == false)
            {
                playerController.PlayMissingItemsSound();
            }
        }
        else
        {
            playerController.PlayMissingItemsSound();
        }
    }
    // Called by unity engine on start up to initialize variables.
    public void Start()
    {
        // Reference to the game manager and state manager.
        gameManager  = GameObject.Find("GameManager").GetComponent <GameManager>();
        stateManager = GameObject.Find("GameManager").GetComponent <StateManager>();


        // Initialize component classes.
        playerInventory = GetComponent <InventoryManager>();
        laserController = new LaserController(this, gameManager);

        // Load mouse settings.
        Cursor.visible   = true;
        Cursor.lockState = CursorLockMode.None;
        if (PlayerPrefs.GetFloat("xSensitivity") != 0)
        {
            GetComponent <MSCameraController>().CameraSettings.firstPerson.sensibilityX = PlayerPrefs.GetFloat("xSensitivity");
        }
        if (PlayerPrefs.GetFloat("ySensitivity") != 0)
        {
            GetComponent <MSCameraController>().CameraSettings.firstPerson.sensibilityY = PlayerPrefs.GetFloat("ySensitivity");
        }
        GetComponent <MSCameraController>().CameraSettings.firstPerson.invertYInput = PlayerPrefsX.GetPersistentBool("mouseInverted");

        // Loading volume settings.
        if (PlayerPrefs.GetFloat("volume") > 0)
        {
            AudioListener.volume = PlayerPrefs.GetFloat("volume");
            GetComponent <MSCameraController>().cameras[0].volume = AudioListener.volume;
        }
        else
        {
            GetComponent <MSCameraController>().cameras[0].volume = 2.5f;
        }

        // Audio source for placing blocks.
        builderSound = builder.GetComponent <AudioSource>();

        // Audio source for GUI related sounds.
        guiSound = guiObject.GetComponent <AudioSource>();

        // Graphics quality.
        if (PlayerPrefsX.GetPersistentBool("changedGraphicsQuality") == true)
        {
            QualitySettings.SetQualityLevel(PlayerPrefs.GetInt("graphicsQuality"));
        }
        graphicsQuality = QualitySettings.GetQualityLevel();

        // Vsync.
        QualitySettings.vSyncCount = PlayerPrefs.GetInt("vSyncCount");

        int range = PlayerPrefs.GetInt("defaultRange");

        defaultRange = range >= 10 ? range : 10;

        // Fog and Scanner color for atmospheric worlds.
        if (SceneManager.GetActiveScene().name.Equals("QE_World_Atmo"))
        {
            scannerFlash.GetComponent <Light>().color     = Color.white;
            scannerFlash.GetComponent <Light>().intensity = 1;
        }

        if (!SceneManager.GetActiveScene().name.Equals("QE_World"))
        {
            float fogDensity = PlayerPrefs.GetFloat("fogDensity");
            RenderSettings.fogDensity = fogDensity > 0 ? fogDensity : 0.00025f;
            RenderSettings.fog        = PlayerPrefsX.GetPersistentBool("fogEnabled");
        }

        inputManager         = new InputManager(this);
        blockSelector        = new BlockSelector(this);
        networkController    = new NetworkController(this);
        networkItemLocations = new List <Vector3>();
    }
    //! Called once per frame by unity engine.
    public void Update()
    {
        if (addedModBlocks == false)
        {
            if (ReadyToLoadModBlocks())
            {
                BlockDictionary blockDictionary = GetComponent <BuildController>().blockDictionary;
                blockDictionary.AddModBlocks(blockDictionary.blockDictionary);
                blockDictionary.AddModMachines(blockDictionary.machineDictionary);
                blockDictionary.AddModMeshes(blockDictionary.meshDictionary);
                addedModBlocks = true;
            }
        }

        // Get a refrence to the camera.
        if (mCam == null)
        {
            mCam = Camera.main;

            if (PlayerPrefs.GetFloat("FOV") != 0)
            {
                mCam.fieldOfView = PlayerPrefs.GetFloat("FOV");
            }

            if (PlayerPrefs.GetFloat("drawDistance") != 0)
            {
                mCam.farClipPlane = PlayerPrefs.GetFloat("drawDistance");
            }
        }
        else
        {
            // Disable mouse look during main menu sequence.
            gameObject.GetComponent <MSCameraController>().enabled &= gameStarted != false;

            // Get the spawn location, for respawning the player character.
            if (gotPosition == false)
            {
                originalPosition = transform.position;
                gotPosition      = true;
            }

            // The state manager has finished loading the world.
            if (stateManager.worldLoaded == true)
            {
                gameStarted = true;

                if (FileBasedPrefs.GetBool(stateManager.worldName + "oldWorld") == false)
                {
                    OpenTabletOnFirstLoad();
                }
                else if (movedPlayer == false)
                {
                    MovePlayerToSavedLocation();
                }

                if (ShouldShowTabletIntro())
                {
                    ShowTabletIntro();
                }

                if (checkedForCreativeMode == false && stateManager.worldLoaded == true)
                {
                    creativeMode = FileBasedPrefs.GetBool(stateManager.worldName + "creativeMode");
                    if (creativeMode == true)
                    {
                        Debug.Log("World [" + stateManager.worldName + "] running in creative mode.");
                    }
                    else
                    {
                        Debug.Log("World [" + stateManager.worldName + "] running in standard mode.");
                    }
                    checkedForCreativeMode = true;
                }

                // Destruction messages.
                if (destructionMessageActive == true)
                {
                    if (destructionMessageCount > 10)
                    {
                        currentTabletMessage    = "";
                        destructionMessageCount = 0;
                    }
                    if (destructionMessageReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        destructionMessageReceived = true;
                    }
                }
                else
                {
                    destructionMessageCount    = 0;
                    destructionMessageReceived = false;
                }

                // Pirate attack warnings.
                if (pirateAttackWarningActive == true)
                {
                    currentTabletMessage = "Warning! Warning! Warning! Warning! Warning!\n\nIncoming pirate attack!";
                    if (pirateAttackWarningReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        pirateAttackWarningReceived = true;
                    }
                }
                else
                {
                    pirateAttackWarningReceived = false;
                }

                // Meteor shower warnings.
                if (meteorShowerWarningActive == true)
                {
                    currentTabletMessage = "Warning! Warning! Warning! Warning! Warning!\n\nIncoming meteor shower!";
                    if (meteorShowerWarningReceived == false)
                    {
                        tablet.GetComponent <AudioSource>().Play();
                        meteorShowerWarningReceived = true;
                    }
                }
                else
                {
                    meteorShowerWarningReceived = false;
                }

                if (timeToDeliver == true)
                {
                    DisplayDeliveryWarning();
                }
                else
                {
                    timeToDeliverWarningRecieved = false;
                }

                if (destroying == true)
                {
                    ModifyCombinedMeshes();
                }

                if (requestedBuildingStop == true)
                {
                    HandleBuildingStopRequest();
                }

                // The player controller is notified that the game manager finished combining meshes.
                if (stoppingBuildCoRoutine == true && gameManager.working == false)
                {
                    stoppingBuildCoRoutine = false;
                }

                if (requestedChunkLoad == true)
                {
                    HandleChunkLoadRequest();
                }

                // Locking or unlocking the mouse cursor for GUI interaction.
                if (GuiOpen())
                {
                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                    gameObject.GetComponent <MSCameraController>().enabled = false;
                }
                else
                {
                    Cursor.visible   = false;
                    Cursor.lockState = CursorLockMode.Locked;
                    gameObject.GetComponent <MSCameraController>().enabled = true;
                }

                if (requestedSave == true)
                {
                    HandleSaveRequest();
                }

                if (storageInventory != null && storageGUIopen == true)
                {
                    CheckStorageDistance();
                }

                if (stateManager.saving == false)
                {
                    inputManager.HandleInput();
                    EnforceWorldLimits();
                }

                if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
                {
                    networkController.NetworkFrame();

                    if (networkController.networkWorldUpdateCoroutineBusy == false)
                    {
                        networkWorldUpdateCoroutine = StartCoroutine(networkController.NetWorkWorldUpdate());
                    }
                }
            }
        }
    }