public PlayerView(PlayerMove parent, bool setOwner) { if (setOwner) { // Set some static variables. IMPORTANT! OptionsMenu.classSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); createViewModelPlayer(parent); parent.predictionErrorTest = new PredictionErrorTest(); GameObject.Find("DeathCamera").GetComponent <Camera> ().enabled = false; GameObject.Find("DeathCamera").GetComponent <AudioListener> ().enabled = false; parent.mainCamera = (GameObject)MonoBehaviour.Instantiate(parent.mainCamera, Vector3.zero, Quaternion.identity); parent.mainCamera.transform.parent = parent.transform; parent.mainCamera.transform.localPosition = parent.GetMainCameraLocalPos(); // Don't render the world player to the main camera: setGunsToNotRender(parent.transform.Find("Armature").Find("Pelvis")); parent.transform.Find("PersonModelObject").gameObject.layer = 11; // Mirror see only foreach (Transform child in parent.transform) { if (child.name.Contains("Armor") || child.name.Contains("Cube") || child.name.Contains("Cylinder") || child.name.Contains("Curve") || child.name.Contains("PhaseThroughIndicator")) { child.gameObject.layer = 11; // Mirror see only } } parent.lastPlayerPosition = parent.transform.position; } }
void OnGUI() { if (!started) { ipAddress = GUI.TextField(new Rect(Screen.width / 2 - 150, Screen.height / 2 + 110, 300, 40), ipAddress); port = GUI.TextField(new Rect(Screen.width / 2 - 150, Screen.height / 2 + 160, 300, 40), port); if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height / 2 + 120, 100, 20), "Start Server")) { // Server if (Input.GetKey(KeyCode.S)) { // This is NOT where you uncomment to run server on linux as OnGUI doesn't run there! StartServer(); // It'll be pretty obvious: Player.thisPlayer.team = 2; // Spectator (Never spawns.) PlayerInformation.steamName = "Test Server"; GameObject.Find("DeathCamera").GetComponent <Camera>().enabled = false; //ClassSelectionMenu.classSelectionMenuOpen = false; } else { StartServer(); } } if (GUI.Button(new Rect(Screen.width / 2 - 150, Screen.height / 2 + 60, 300, 40), "Connect")) { started = true; myClient = new ClientPerson(ipAddress, port); myClient.StartClient(); } else if (GUI.Button(new Rect(Screen.width / 2 - 300, Screen.height / 2 + 150, 100, 20), "Watch Demo")) { // This will fail on the frame it happens if no demo file: (Or it's too big?) if (File.Exists("TestDemo.dem")) { OperationNetwork.dataToReadIn = File.ReadAllBytes("TestDemo.dem"); } Debug.LogError("Watching Demo"); started = true; // timeStartedAt = Time.time; // Demo time is simply, "Time.time - timeStartedAt" currently. Basically, it reads the input data until time is after demoTime. OperationNetwork.isDemo = true; Player.myID = 32767; OperationNetwork.timeStartedAt = Time.time; OperationNetwork.currentByte = 0; // Implies maximum of 2gb. OperationNetwork.timeReceivedForDemo = false; // Demo watcher doesn't get a player. OptionsMenu.classSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); } } }
// Update is called once per frame void Update() { if (OperationNetwork.connected && Input.GetKeyDown(KeyCode.C)) { // For now, classSelectionMenuOpen doesn't work when alive. classSelectionMenuOpen = !classSelectionMenuOpen; OptionsMenu.ChangeLockState(); } if (!optionsMenuOpen && Input.GetKeyDown(KeyCode.Escape)) { // This for loop is not necessary. for (int n = 0; n < numBinds; n++) { settingBind[n] = false; } isSettingBind = false; optionsMenuOpen = !optionsMenuOpen; ChangeLockState(); } // This is because unity captures the escape button and sets "lockState" to none. Note that the player needs to click to get this to work.. if (IsLockState()) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } if (isSettingBind) { if (Input.anyKeyDown) { foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(vKey) && vKey != KeyCode.Mouse0 && vKey != KeyCode.Mouse1) { for (int i = 0; i < numBinds; i++) { if (settingBind[i]) { binds[i] = vKey; isSettingBind = false; settingBind[i] = false; break; } } break; } } } } }
public void SelectTeam() { if (OperationNetwork.connected && Player.thisPlayer != null) { OperationView opView = Player.thisPlayer.GetComponent <OperationView> (); if (opView != null && num != Player.thisPlayer.team) { opView.RPC("switchTeam", OperationNetwork.ToServer, num, Player.thisPlayer.classNum); if (num == 2) { OptionsMenu.classSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); } } } }
public override void OnDeath() { // Death is a necessary process regardless of if the ragdoll should spawn, or even if the deathCamera will be used. if (OperationNetwork.isServer && GameManager.PlayerExists(playerOwner)) { GameManager.GetPlayer(playerOwner).StartRespawnTimer(); GameManager.GetPlayer(playerOwner).serverPlayerTimeSave = playerTime; GameManager.GetPlayer(playerOwner).timeSavedAt = Time.time; } // DEATH LOGIC: if (GetComponent <PlayerMove> ().thisIsMine) { Player.thisPlayer.playerObject = null; OptionsMenu.ChangeLockState(); Player.thisPlayer.playerCamera = GameObject.Find("DeathCamera"); GameObject.Find("DeathCamera").GetComponent <Camera> ().enabled = true; GameObject.Find("DeathCamera").GetComponent <AudioListener> ().enabled = true; GameObject.Find("DeathCamera").transform.position = GetComponent <PlayerMove> ().mainCamera.transform.position; GameObject.Find("DeathCamera").transform.rotation = GetComponent <PlayerMove> ().mainCamera.transform.rotation; // Destroys player made objects that haven't been placed, essentially: Transform clientSideOnly = GameObject.Find("ClientSideOnly").transform; foreach (Transform child in clientSideOnly) { Destroy(child.gameObject); } } // Create ragdoll: (And plays death sound within ragdoll) // if facade, teleport to facade: GetComponent <Combat>().die(Vector3.zero); if (GameManager.PlayerExists(playerOwner)) { GameManager.AddToKillFeed(GameManager.GetPlayer(playerOwner).killedByPlayer, playerOwner); } }
public override void AfterFirstInterp() { // First should check if player doesn't exist in case of double RPC send: GameManager.AddPlayer(playerOwner, this); if (playerOwner == myID) { Player.thisPlayer = this; // Set time picked last trap: // .. // Gives you a trap right away; actually. OptionsMenu.classSelectionMenuOpen = true; OptionsMenu.ChangeLockState(); // Player camera is set: if (Player.thisPlayer.playerCamera == null) { Player.thisPlayer.playerCamera = GameObject.Find("DeathCamera"); } } }
// Update is called once per frame void Update() { for (int i = chatAge.Count - 1; i >= 0; i--) { chatAge[i] += Time.deltaTime; if (chatAge[i] > 15) { chatMessages.RemoveAt(i); chatAge.RemoveAt(i); } } timeSinceLastMessageSent += Time.deltaTime; if (!typing && Input.GetKeyUp(KeyCode.Y)) { typing = true; message = ""; OptionsMenu.ChangeLockState(); } }
void OnGUI() { for (int i = chatAge.Count - 1; i >= 0; i--) { if (i >= chatAge.Count - maxMessages) { int height = Screen.height - 300 + (chatAge.Count - i - 1) * 15; GUI.color = Color.black; GUI.Label(new Rect(Screen.width - 400, height, 390, 24), chatMessages[i]); } } if (typing) { Event e = Event.current; if (e.keyCode == KeyCode.Return) { // Send message: typing = false; if (message.Length > 0 && timeSinceLastMessageSent >= 0.3f) // Up to ~3 messages per second max. { GetComponent <OperationView>().RPC("Chat", OperationNetwork.ToServer, message); timeSinceLastMessageSent = 0; } message = ""; OptionsMenu.ChangeLockState(); return; } GUI.color = Color.white; GUI.SetNextControlName("ChatBox"); message = GUI.TextField(new Rect(Screen.width - 400, Screen.height - 130, 200, 24), message, 26); // Constantly set control: GUI.FocusControl("ChatBox"); } }
// This does NOT go through prediction error, as it never fails this. public void PlayerAndServer(PlayerInput pI, bool runEffects) // runEffects is true when player does its first prediction run, but not when predictione error is done. It is also set to true on server (as it deals with animation) { // Player Input can suggest changes in weapon, which has been premodified to be reasonable. // Thus, this does NOT use "canEnable" check, it assumes the playerInput is valid. byte ust = pI.unlockSwitchTo; if (pI.cancelKey) { if (runEffects && PlayerHud.isTrapSelectionMenuOpen) { if (PlayerHud.whichGroupTypeSelecting == -1) { PlayerHud.isTrapSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); ust = 0; } else { PlayerHud.whichGroupTypeSelecting = -1; } } else { ust = 0; } } if (ust != 255) { if (ust == OptionsMenu.PRIMARY_1 || ust == OptionsMenu.PRIMARY_2 || ust == OptionsMenu.PRIMARY_3) { ust = OptionsMenu.PRIMARY_1; } else if (ust == OptionsMenu.TRAP_1 || ust == OptionsMenu.TRAP_2) { ust = OptionsMenu.TRAP_1; } if (ust < OptionsMenu.NUM_SWITCH_TO_BINDS) { if (getUnlocks() [ust] != null) // Trap binds are set / unset as before { byte nextUnlock = getUnlocks() [ust].getUnlockType(); if (classNum == 1 && ust == OptionsMenu.PRIMARY_1) { ((Pistol)getUnlocks()[ust]).UpdatePistolMode(pI); } if (ust == OptionsMenu.TRAP_1 && runEffects) { if (pI.unlockSwitchTo == OptionsMenu.TRAP_1) { ((PlaceTrap)getUnlocks() [ust]).trapPlacing = 0; } else { ((PlaceTrap)getUnlocks() [ust]).trapPlacing = 1; } } if (!isSwitching() && getUnlocks() [ust].canEnable() && canDisable()) { if (getUnlockEquipped() != getUnlocks() [ust]) { // This assumes switching is possible. It is neccesary that the check for switching is done in PlayerInput to maintain consistency. SetNextUnlock(nextUnlock, runEffects, true); } } } } } switchCheck(); // This needs to go before isSwitching. for (int i = 0; i < UnlocksEquipped.Length; i++) { if (UnlocksEquipped [i] != null) { UnlocksEquipped [i].PlayerAndServerAlways(pI, !isSwitching() && getUnlockEquipped() == UnlocksEquipped[i]); } } if (!isSwitching()) // Switching is handled by "InterpAll" { Unlock usingUnlock = getUnlockEquipped(); if (usingUnlock != null) // This happens on spawn currently ..-> doesn't have to. { usingUnlock.UpdateServerAndPlayer(pI, runEffects); } else { // Because of how placePlayerMade work, fireKey needs to be set to false because of issues.. pI.fireKey = false; } } if (GetComponent <PlayerMove> ().thisIsMine) { updateHud(); } }
void HudUpdate() { GameManager.UpdateKillFeed(); HealthBarUpdate(); UpdateTrapSelectionZoneMenu(); for (int i = 0; i < trapsHud.Length; i++) { trapsHud [i].SetActive(isTrapSelectionMenuOpen); } respawnHud.transform.parent.gameObject.SetActive(Player.thisPlayer != null && Player.thisPlayer.playerObject == null); if (Player.thisPlayer != null && Player.thisPlayer.playerObject == null) { respawnHud.fillAmount = Mathf.Clamp01(1 - Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer()); respawnHud.transform.parent.GetComponent <Image>().fillAmount = Mathf.Clamp01(Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer()); int respawnTimer = (int)(Player.thisPlayer.getRespawnTimer() + 1); if (respawnTimer == 1) { respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in 1 second."; } else { respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in " + respawnTimer + " seconds."; } } // Class Selection Hud gets priority if (Player.thisPlayer && Player.thisPlayer.team == 1 && !OptionsMenu.classSelectionMenuOpen) { bool needTrap = false; for (int i = 0; i < Player.thisPlayer.trapTypes.Length; i++) { if (Player.thisPlayer.trapTypes [i] == 255) { needTrap = true; } } if (needTrap && !PlayerHud.isTrapSelectionMenuOpen) { PlayerHud.isTrapSelectionMenuOpen = true; OptionsMenu.ChangeLockState(); } else if (!needTrap && PlayerHud.isTrapSelectionMenuOpen) { PlayerHud.isTrapSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); } } if (Player.thisPlayer && PlayerHud.isTrapSelectionMenuOpen) { for (int x = 0; x < trapsChoices.GetLength(0); x++) { for (int y = 0; y < trapsChoices.GetLength(1); y++) { trapsChoices [x, y].transform.Find("Text").GetComponent <Text> ().text = BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[Player.thisPlayer.myRandomTrapChoices[x * trapsChoices.GetLength(1) + y]]]; trapsChoices [x, y].GetComponent <BuyNewTrap> ().buyId = Player.thisPlayer.myRandomTrapChoices [x * trapsChoices.GetLength(1) + y]; trapsChoices [x, y].GetComponent <BuyNewTrap> ().rowID = (byte)x; } } } // This is how HUD should work for all unlocks: if (Player.thisPlayer) { for (int i = 0; i < displayTraps.Length; i++) { byte actual = Player.thisPlayer.trapTypes [i]; if (Player.thisPlayer.team != 1) { actual = 255; } if (displayTraps [i] != actual) { displayTraps [i] = actual; if (displayTraps [i] == 255 || Player.thisPlayer.team != 1) { trapPlayerHudTypes [i].SetActive(false); } else { trapPlayerHudTypes [i].SetActive(true); trapPlayerHudTypes [i].transform.Find("Text").GetComponent <Text> ().text = "(" + OptionsMenu.getBindString(OptionsMenu.binds [OptionsMenu.TRAP_1 + i]) + ") " + BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[displayTraps [i]]]; } } if (displayTraps[i] != 255 && Player.thisPlayer.playerObject) { int trapTypeIndex = BuyNewTrap.trapIndecies[Player.thisPlayer.trapTypes [i]]; PlacePlayerMade.setCharge(trapPlayerHudTypes [i], Mathf.Clamp01((Player.thisPlayer.playerObject.GetComponent <SyncPlayer>().playerTime - Player.thisPlayer.trapCoolDownsStartedAt [i]) / (float)(BuyNewTrap.baseTrapCosts [trapTypeIndex] * BuyNewTrap.maxTrapsLoaded[trapTypeIndex] * Time.fixedDeltaTime)), 1f / BuyNewTrap.maxTrapsLoaded[trapTypeIndex]); } } } if (OperationNetwork.connected) { if (Time.time - lastNetworkSettingsRead > 1) { if (OperationNetwork.isServer) { dataSentPerSecond = OperationNetwork.getClient(32767).dataSent / (Time.time - lastNetworkSettingsRead); OperationNetwork.getClient(32767).dataSent = 0; networkSettings.GetComponent <Text> ().text = (int)(dataSentPerSecond / 100) / 10.0f + " KB/s"; } else { dataSentPerSecond = RunGame.myClient.dataOutRate / (Time.time - lastNetworkSettingsRead); RunGame.myClient.dataOutRate = 0; float dataRecievedPerSecond = RunGame.myClient.dataInRate / (Time.time - lastNetworkSettingsRead); RunGame.myClient.dataInRate = 0; networkSettings.GetComponent <Text> ().text = "Sent: " + (int)(dataSentPerSecond / 100) / 10.0f + " KB/s Recieved: " + (int)(dataRecievedPerSecond / 100) / 10.0f + " KB/s"; } lastNetworkSettingsRead = Time.time; } } if (OperationNetwork.connected && Player.thisPlayer != null && Player.thisPlayer.playerObject != null) { PlayerMove pMove = Player.thisPlayer.playerObject.GetComponent <PlayerMove> (); float touchPercent = DamageCircle.isTouchingDamageCircle(pMove.timeSinceTouchingDamageCircle); if (touchPercent > 0) { buffHud.transform.parent.GetComponent <Image> ().enabled = true; buffHud.enabled = true; buffHud.fillAmount = touchPercent; } else { // Disable the rendering of it: buffHud.transform.parent.GetComponent <Image> ().enabled = false; buffHud.enabled = false; } healthHud.enabled = true; healthHud.transform.parent.GetComponent <Image> ().enabled = true; healthHudText.enabled = true; healthHud.transform.parent.GetComponent <Image> ().fillAmount = 1 - pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth; healthHud.fillAmount = pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth; healthHudText.text = (short)pMove.GetComponent <Combat> ().health + " HP"; if (Player.thisPlayer.playerObject != playerObjectHudLoaded) { playerObjectHudLoaded = Player.thisPlayer.playerObject; float origNum = getHudHeightUsed(classHud.transform); // Unload old hud: foreach (Transform t in classHud.transform) { if (t.name != "AdjacentClassHud") { Destroy(t.gameObject); } } foreach (Transform t in classHud.transform.Find("AdjacentClassHud")) { Destroy(t.gameObject); } // Create new hud: foreach (Unlock unlock in Player.thisPlayer.playerObject.GetComponent <ClassControl>().getUnlocks()) { if (unlock != null) { unlock.setHudElement(classHud.transform, origNum); } } int classLoaded = Player.thisPlayer.playerObject.GetComponent <ClassControl> ().classNum; // Phase through & Speed Boost are not unlocks, despite having some similar qualities: (Like the HUD) if (classLoaded == 0) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Phase Shift", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum); Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement2 = Unlock.setHudElement(classHud.transform, "Armor", "Armor", OptionsMenu.MAIN_ABILITY, null, origNum); } else if (classLoaded == 3) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Speed Boost", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum); } else if (classLoaded == 4) { if (OptionsMenu.hudPanels.ContainsKey("Healthtaken")) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Healthtaken", "Health Taken", OptionsMenu.ULTIMATE_ABILITY, null, origNum); } } // The updating for the HUD is handled within the unlocks / class itself } } else { // Hide hud completely: buffHud.transform.parent.GetComponent <Image> ().enabled = false; buffHud.enabled = false; healthHud.enabled = false; healthHud.transform.parent.GetComponent <Image> ().enabled = false; healthHudText.enabled = false; } // SCOREBOARD: if (Input.GetKey(KeyCode.Tab)) { scoreBoard.SetActive(true); for (byte team = 0; team < 2; team++) { List <Player> players = GameManager.getPlayersOnTeam(team); for (int i = 0; i < scoreBoardPlayers[team].Count; i++) { if (i < players.Count) { scoreBoardPlayers [team] [i].SetActive(true); scoreBoardPlayers [team] [i].transform.Find("Text").GetComponent <Text> ().text = players [i].playerName; Color c = scoreBoardPlayers [team] [i].GetComponent <Image> ().color; if (players [i].playerObject != null) { scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 1f); } else { scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 0.2f); } scoreBoardKills [team] [i].text = "" + players[i].kills; scoreBoardDeaths [team] [i].text = "" + players[i].deaths; } else { scoreBoardPlayers [team] [i].SetActive(false); scoreBoardKills [team] [i].text = ""; scoreBoardDeaths [team] [i].text = ""; } } } } else { scoreBoard.SetActive(false); } // Display kill feed: for (int i = 0; i < killFeed.Count; i++) { if (GameManager.recentPlayerKillers.Count > i) { killFeed [i].parent.gameObject.SetActive(true); string killDisplay = ""; if (GameManager.PlayerExists(GameManager.recentPlayerKillers [i])) { killDisplay = GameManager.GetPlayer(GameManager.recentPlayerKillers [i]).playerName + " killed "; } if (GameManager.PlayerExists(GameManager.recentPlayerDeaths [i])) { killFeed [i].GetComponent <Text> ().text = killDisplay + GameManager.GetPlayer(GameManager.recentPlayerDeaths [i]).playerName; } } else { killFeed [i].parent.gameObject.SetActive(false); } } // Class Selection Menu: if (OptionsMenu.classSelectionMenuOpen && Player.thisPlayer != null) { classSelectionMenu.SetActive(true); Color color; if (Player.thisPlayer.team == 0) { color = new Color(0, 0, 1f, 0.5f); } else if (Player.thisPlayer.team == 1) { color = new Color(1f, 0, 0, 0.5f); } else { color = new Color(1f, 1f, 1f, 0.5f); } classSelectionMenu.GetComponent <Image> ().color = color; for (byte i = 0; i < classSelectionTeams.Length; i++) { if (Player.thisPlayer.team == i) { classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 1f); } else { classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 0.6f); } } for (byte i = 0; i < classTypes.Count; i++) { if (Player.thisPlayer.team == 0) { classTypes [i].gameObject.SetActive(true); if (Player.thisPlayer.classNum == i) { classTypes [i].color = new Color(0.2f, 0.2f, 1f, 1f); } else { classTypes [i].color = new Color(0.7f, 0.7f, 1f, 0.8f); } } else if (Player.thisPlayer.team == 1) { classTypes [i].gameObject.SetActive(true); if (Player.thisPlayer.classNum == i) { classTypes [i].color = new Color(1f, 0.2f, 0.2f, 1f); } else { classTypes [i].color = new Color(1f, 0.7f, 0.7f, 0.8f); } } else { classTypes [i].gameObject.SetActive(false); } } } else { classSelectionMenu.SetActive(false); } }