void ChangeNick(NetworkPlayer player, string nick) { Player p = NetVars.getPlayer(player); chat += "<GAME> Player " + p.nickname + " changed name to " + nick + "\n"; p.nickname = nick; }
void Awake() { if (NetVars.SinglePlayer()) { Application.LoadLevel(sceneToRedirect); } }
public void RequestMessage(NetworkViewID view, string msg) { if (Network.isServer) { networkView.RPC("OnSendChatMessage", RPCMode.All, NetVars.getPlayer(view.owner).nickname, msg); } }
// Use this for initialization void Start() { speed = startSpeed; camPos = cam.localPosition; Screen.lockCursor = true; player = NetVars.getPlayer(networkView.owner); foreach (Renderer o in reticule.gameObject.GetComponentsInChildren <Renderer>()) { o.material.renderQueue = 4000; //4000+ is overlay } if (!IsMine()) { Destroy(reticule.gameObject); Destroy(cam.gameObject); Destroy(healthBar.gameObject); } else { //Position health bar Ray ray = Camera.main.ScreenPointToRay(new Vector3(100, Screen.height - 100, 0)); Plane plane = new Plane(transform.forward, healthBar.gameObject.transform.position); float d = 0; if (plane.Raycast(ray, out d)) { healthBar.gameObject.transform.position = ray.GetPoint(d); } GameObjectUtils.SetLayerRecursively(gameObject, 9); // Ignore Reticle } }
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { if (stream.isWriting) { float r_velocity = velocity; stream.Serialize(ref r_velocity); NetworkPlayer r_friendlyPlayer = friendlyPlayer.UnityPlayer; stream.Serialize(ref r_friendlyPlayer); } else if (stream.isReading) { float r_velocity = 0; stream.Serialize(ref r_velocity); velocity = r_velocity; NetworkPlayer r_friendlyPlayer = new NetworkPlayer(); stream.Serialize(ref r_friendlyPlayer); if (friendlyPlayer == null || !friendlyPlayer.UnityPlayer.Equals(r_friendlyPlayer)) { friendlyPlayer = NetVars.getPlayer(r_friendlyPlayer); } // else if(!friendlyPlayer.UnityPlayer.Equals(r_friendlyPlayer)) // friendlyPlayer = new Player(r_friendlyPlayer,friendlyPlayer.nickname); } }
void OnTriggerEnter(Collider other) { if (NetVars.Authority()) { Ship ship = other.gameObject.GetComponent <Ship>(); if ((ship == null && !other.gameObject.tag.Equals("Obstacle")) || (ship != null && ship.player.Equals(friendlyPlayer))) { return; } if (ship != null) { if (!ship.IsMine()) { ship.networkView.RPC("Damage", ship.networkView.owner, 0.1f); } else { ship.Damage(0.1f); } } if (enabled) { Network.RemoveRPCs(networkView.viewID); Network.Destroy(gameObject); } } }
void Update() { if (!NetVars.SinglePlayer()) { currentNick = NetVars.getPlayer(Network.player).nickname; } }
void SpawnShip(NetworkPlayer p) { player = NetVars.getPlayer(p); if (!p.Equals(Network.player)) { return; } Debug.Log("Spawning Ship"); Ship ship; ship = (Network.Instantiate(shipPrefab, transform.position, Quaternion.identity, 0) as Transform).GetComponent <Ship>(); ship.guiManager = guiManager; ship.player = player; }
internal static string ReadClassFromPointer(IntPtr entityPointer) { if (entityPointer == IntPtr.Zero) { return(string.Empty); } IntPtr getClassIdPointer = MemoryManager.Function(entityPointer, EntityVTable.GetClientClass); NativeGetClientClass getClassIdFunction = (NativeGetClientClass)Marshal.GetDelegateForFunctionPointer(getClassIdPointer, typeof(NativeGetClientClass)); IntPtr classId = getClassIdFunction(entityPointer); NetVars clientClass = (NetVars)Marshal.PtrToStructure(classId, typeof(NetVars)); return(MemoryManager.ReadString(clientClass.m_ServerName)); }
void OnTriggerEnter(Collider other) { if (!NetVars.Authority()) { return; } if (other.gameObject.CompareTag("Obstacle") && alive) { if (IsMine()) { Kill(); } else { //alive = false; networkView.RPC("Kill", networkView.owner); } } }
void ChatFunction(int windowID) { Vector2 labelSize = GUI.skin.label.CalcSize(new GUIContent(handler.chat)); chatScroll = GUI.BeginScrollView(new Rect(10, 10, 180, chatArea.height - 40), chatScroll, new Rect(0, 0, labelSize.x, labelSize.y)); GUI.Label(new Rect(0, 0, labelSize.x, labelSize.y), handler.chat); // Read-only GUI.EndScrollView(); GUI.SetNextControlName("chatbox"); chatBox = GUI.TextField(new Rect(10, chatArea.height - 30, 180, 20), chatBox); if (GUI.GetNameOfFocusedControl().CompareTo("chatbox") == 0 && (Event.current.isKey && Event.current.keyCode == KeyCode.Return)) { NetworkViewID viewID = Network.AllocateViewID(); if (Network.isClient) { handler.networkView.RPC("RequestMessage", RPCMode.Server, viewID, chatBox); } else if (Network.isServer) { handler.RequestMessage(networkView.viewID, chatBox); } chatBox = ""; } if (currentNick.Equals("")) { currentNick = NetVars.getPlayer(Network.player).nickname; } GUI.SetNextControlName("namebox"); labelSize = GUI.skin.label.CalcSize(new GUIContent("Change Name")); GUI.Label(new Rect(200, 20, chatArea.width - 200, 20), "Change Name"); nickBox = GUI.TextField(new Rect(200, 20 + labelSize.y, chatArea.width - 200, 20), nickBox); if (GUI.GetNameOfFocusedControl().CompareTo("namebox") == 0 && (Event.current.isKey && Event.current.keyCode == KeyCode.Return) && !nickBox.Trim().Equals("")) { handler.networkView.RPC("ChangeNick", RPCMode.AllBuffered, Network.player, nickBox); nickBox = ""; } GUI.Label(new Rect(200, 40 + labelSize.y, chatArea.width - 200, 20), currentNick); GUI.DragWindow(new Rect(0, 0, 100000, 20)); }
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { if (stream.isWriting) { bool r_alive = alive; stream.Serialize(ref r_alive); float r_speed = speed; stream.Serialize(ref r_speed); Vector3 r_rot = rawRot; stream.Serialize(ref r_rot); NetworkPlayer r_player = player.UnityPlayer; stream.Serialize(ref r_player); } else if (stream.isReading) { bool r_alive = false; stream.Serialize(ref r_alive); alive = r_alive; float r_speed = 0; stream.Serialize(ref r_speed); speed = r_speed; Vector3 r_rot = Vector3.zero; stream.Serialize(ref r_rot); rawRot = r_rot; NetworkPlayer r_player = new NetworkPlayer(); stream.Serialize(ref r_player); if (player == null || !player.UnityPlayer.Equals(r_player)) { player = NetVars.getPlayer(r_player); } } }
// Update is called once per frame void Update() { if (!alive || !IsMine()) { if (alive) { transform.Rotate(Vector3.up, rawRot.y, Space.Self); transform.Rotate(Vector3.right, rawRot.x, Space.Self); transform.Rotate(Vector3.forward, rawRot.z, Space.Self); transform.Translate(Vector3.forward * trueSpeed() * Time.deltaTime, Space.Self); // Approximation for high ping } return; } if (health <= 0) { Kill(); return; } if (shield < 1 && Time.time - lastHitTime > shieldRegenWait) { shield = Mathf.Min(1, shield + Time.deltaTime * shieldRegenRate); healthBar.setShield(shield); } float pitchRaw = Input.GetAxis("Pitch"); float yawRaw = Input.GetAxis("Yaw"); float rollRaw = Input.GetAxis("Roll"); float pitch = pitchRaw * pitchSpeed * Time.deltaTime; float yaw = yawRaw * yawSpeed * Time.deltaTime; float roll = rollRaw * rollSpeed * Time.deltaTime; rawRot = new Vector3(pitch, yaw, roll); transform.Rotate(Vector3.up, yaw, Space.Self); transform.Rotate(Vector3.right, pitch, Space.Self); transform.Rotate(Vector3.forward, roll, Space.Self); float throttle = Input.GetAxis("Throttle") * Time.deltaTime; if (throttle > 0) { throttle *= throttleRate; } else if (throttle < 0) { throttle *= descelerateRate; } speed = Mathf.Max(Mathf.Min(speed + throttle, maxSpeed), minSpeed); transform.Translate(Vector3.forward * trueSpeed() * Time.deltaTime, Space.Self); float mousex = Input.GetAxis("Mouse X"); float mousey = Input.GetAxis("Mouse Y"); float joyx = Input.GetAxis("Joystick Aim X"); float joyy = Input.GetAxis("Joystick Aim Y"); reticule.localPosition += new Vector3(mousex, mousey, 0) * aimReticuleSpeed; Vector3 joyLocPos = reticule.localPosition; if (joyx != 0) { joyLocPos.x = joyx * aimRadius; } if (joyy != 0) { joyLocPos.y = joyy * aimRadius; } reticule.localPosition = joyLocPos; float xpos = reticule.localPosition.x; float ypos = reticule.localPosition.y; if (xpos * xpos + ypos * ypos > aimRadius * aimRadius) { float angle = Mathf.Atan2(ypos, xpos); xpos = Mathf.Cos(angle) * aimRadius; ypos = Mathf.Sin(angle) * aimRadius; } reticule.localPosition = new Vector3(xpos, ypos, reticule.localPosition.z); if (Input.GetButton("Fire1") && Time.time - lastFireTime > ((float)fireRate) / 1000f) { lastFireTime = Time.time; Ray ray = new Ray(cam.position, reticule.position - cam.position); RaycastHit hit = new RaycastHit(); Vector3 aim; int mask = ~((1 << 9) | (1 << 2)); if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) { aim = hit.point; } else { aim = ray.GetPoint(1000); } if (NetVars.Authority()) { Shoot(aim); } else { networkView.RPC("Shoot", RPCMode.Server, aim); } } cam.localPosition = camPos; Vector3 retDir = Vector3.Normalize(new Vector3(reticule.localPosition.x, reticule.localPosition.y, 3)) * tilt; cam.localPosition += retDir; }