void Start() { //Enable Background Running Application.runInBackground = true; //Enable custom log CustomLogger.LogIt("Start Logging"); //Application.dataPath Debug.Log(Application.dataPath); //Connect to the DarkRift Server using the Ip specified (will hang until connected or timeout) DarkRiftAPI.Connect(serverIP, serverPort); //Setup a receiver so we can create players when told to. DarkRiftAPI.onDataDetailed += ReceiveData; //Tell others that we've entered the game and to instantiate a player object for us. if (DarkRiftAPI.isConnected) { Debug.Log("Connected to the Server!"); //Get everyone else to tell us to spawn them a player (this doesn't need the data field so just put whatever) DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi"); //Then tell them to spawn us a player! (this time the data is the spawn position) DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, new Vector3(0f, 0f, 0f)); } else { Debug.LogError("Failed to connect to DarkRift Server!"); } }
void LateUpdate() { if (!aimHead) { return; } if (components.pokemon.networkID == DarkRiftAPI.id) { desiredRotation = Quaternion.Euler(Camera.main.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, 0.0f); if (transform.rotation != desiredRotation) { DarkRiftAPI.SendMessageToOthers(TagIndex.PokemonUpdate, TagIndex.PokemonUpdateSubjects.AimHead, desiredRotation); } transform.rotation = desiredRotation; return; } else { transform.rotation = desiredRotation; } }
private void OnInitiatedMelee() { if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.MeleeAttack, "pepitogrillo"); } }
// Update is called once per frame void Update() { if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID) { //Serialize if the position or rotation changes if (Vector3.Distance(lastPosition, transform.position) >= 1) { //DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position); SerialisePosA(transform.position); lastPosition = transform.position; } if (Quaternion.Angle(lastRotation, transform.rotation) > 45) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation); } //SerializeAnim(); //Update stuff lastRotation = transform.rotation; } //Animation Settings anim.SetBool("IsRunning", plValues.running); anim.SetBool("IsGrounded", plValues.grounded); anim.SetInteger("State", plValues.state); anim.SetFloat("Speed", plValues.speed); anim.SetFloat("Horizontal", plValues.hor); anim.SetFloat("Vertical", plValues.ver); }
void SerialisePosRot(Vector3 pos, Quaternion rot, ushort ID, bool isVarKinematic) { //Here is where we actually serialise things manually. To do this we need to add //any data we want to send to a DarkRiftWriter. and then send this as we would normally. //The advantage of custom serialisation is that you have a much smaller overhead than when //the default BinaryFormatter is used, typically about 50 bytes. using (DarkRiftWriter writer = new DarkRiftWriter()) { //Next we write any data to the writer writer.Write(isVarKinematic); writer.Write(pos.x); writer.Write(pos.y); writer.Write(pos.z); writer.Write(rot.x); writer.Write(rot.y); writer.Write(rot.z); writer.Write(rot.w); DarkRiftAPI.SendMessageToOthers(TagIndexVRTK.ObjectUpdate, ID, writer); if (DEBUG) { Debug.Log("Data sent: " + pos.ToString("F4") + " " + rot.ToString("F6")); } } }
void Update() { //Only send data if we're connected and we own this player if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID) { //We're going to use a tag of 1 for movement messages //If we're conencted and have moved send our position with subject 0. if (transform.position != lastPosition) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position); } //Then send our rotation with subject 1 if we've rotated. if (transform.rotation != lastRotation) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation); } //Update stuff lastPosition = transform.position; lastRotation = transform.rotation; //if ( Input.GetAxis("Fire1") > 0) if (Input.GetKeyDown("left ctrl")) { Debug.Log("fire1 axis down"); string tmpstr = "EMOTION1"; DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerMessage, TagIndex.PlayerMessageSubjects.Emotion, tmpstr); } } }
public static void RetrySendData() { if (DarkRiftAPI.isConnected) { DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.PlayerUpdate, prevUpdate); DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.PlayerUpdate, currUpdate); } }
IEnumerator UpdatePosition() { while (true) { // DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.ChangeBlockToNonMovable, currentTilePos); DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.UpdatePostion, ourTransform.position); yield return(WaitForUpdate); } }
public static void SerialiseAnimBool(byte tagIndex, ushort subject, string stateName, bool value) { using (DarkRiftWriter writer = new DarkRiftWriter()) { writer.Write(stateName); writer.Write(value); DarkRiftAPI.SendMessageToOthers(tagIndex, subject, writer); } }
void MineExplosion() { theSrc.Play(theClipToPlayWhenExplode); DigSpawnTile(x, y, BombPower); DigSpawnTile(x + 1, y, BombPower); DigSpawnTile(x - 1, y, BombPower); DigSpawnTile(x, y + 1, BombPower); DigSpawnTile(x, y - 1, BombPower); DarkRiftAPI.SendMessageToOthers(NetworkingTags.Misc, NetworkingTags.MiscSubjects.MineExplode, Pos); Lean.LeanPool.Despawn(this.gameObject); }
public static void SendData(byte tag, ushort subject, object data) { if (DarkRiftAPI.isConnected) { if (data is UnitUpdate) { (data as UnitUpdate).index = ++messageIndex; prevUpdate = currUpdate; currUpdate = (data as UnitUpdate); } DarkRiftAPI.SendMessageToOthers(tag, subject, data); } }
public void TryToConnect() { if (DarkRiftAPI.isConnected) { return; } string sd = GameObject.Find("InputField").GetComponentsInChildren <Text>()[1].text; if (sd == "") { sd = serverIP; } if (!DarkRiftAPI.Connect(sd, 4296)) { return; } GameObject go = GameObject.Find("Name1"); //go.GetComponent<UnityEngine.UI.InputField>().text = "chiucken"; Application.runInBackground = true; DarkRiftAPI.onDataDetailed += ReceiveData; DontDestroyOnLoad(transform.gameObject); if (DarkRiftAPI.isConnected) { DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi"); DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, new Vector3(0.0f, 0.0f, 0.0f)); int index = DarkRiftAPI.id - 1; GameObject.Find("Canvas").GetComponentsInChildren <Image>()[index].color = Color.white; if (DarkRift.DarkRiftAPI.id != 1) { GameObject.Find("Button").GetComponentsInChildren <Button>()[index].interactable = false; } } else { Debug.Log("Failed to connect to DarkRift Server!"); } int id = playerNumber = DarkRiftAPI.id; if (id > playerCount) { playerCount = id; } SendData(TagIndex.Controller, TagIndex.PlayerUpdate, factions[DarkRiftAPI.id - 1]); }
void SerializeAnim() { using (DarkRiftWriter writer = new DarkRiftWriter()) { writer.Write(anim.GetBool("IsRunning")); writer.Write(anim.GetBool("IsGrounded")); writer.Write(anim.GetInteger("State")); writer.Write(anim.GetFloat("Speed")); writer.Write(anim.GetFloat("Horizontal")); writer.Write(anim.GetFloat("Vertical")); Debug.Log("Serialize"); DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Animation, writer); } }
void SerialisePos(Vector3 pos) { //Here is where we actually serialise things manually. To do this we need to add //any data we want to send to a DarkRiftWriter. and then send this as we would normally. //The advantage of custom serialisation is that you have a much smaller overhead than when //the default BinaryFormatter is used, typically about 50 bytes. using (DarkRiftWriter writer = new DarkRiftWriter()) { //Next we write any data to the writer, as we never change the z pos there's no need to //send it. writer.Write(pos.x); writer.Write(pos.y); DarkRiftAPI.SendMessageToOthers(0, (ushort)cubeID, writer); } }
private void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) { hud.loadingPanel.SetActive(false); if (DarkRiftAPI.isConnected) { DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi"); DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, trainerData.lastPosition); } else { Debug.LogWarning("There is no connection to the server right now."); } SceneManager.sceneLoaded -= OnLevelFinishedLoading; }
void Start() { //Connect to the DarkRift Server using the Ip specified (will hang until connected or timeout) DarkRiftAPI.Connect(serverIP); //Setup a reciever so we can create players when told to. DarkRiftAPI.onDataDetailed += RecieveData; //Tell others that we've entered the game and to instantiate a player object for us. if (DarkRiftAPI.isConnected) { //Get everyone else to tell us to spawn them a player (this doesnt need the data field so just put whatever) DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "hi"); //Then tell them to spawn us a player! (this time the data is the spawn position) DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, new Vector3(0f, 0f, 0f)); } }
void Start() { if (DarkRiftAPI.isConnected) { //Recieve Data DarkRiftAPI.onDataDetailed += ReceiveData; //Get everyone else to tell us to spawn them a player DarkRiftAPI.SendMessageToOthers(TagIndex.Controller, TagIndex.ControllerSubjects.JoinMessage, "New Player Joined"); //Spawn the player DarkRiftAPI.SendMessageToAll(TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, Vars.lobby); //Instantiate(playerObject, Vars.lobby, Quaternion.identity); } else { Debug.LogWarning("Failed to connect to DarkRift Server!"); SceneManager.LoadScene(0); } }
void Update() { DarkRiftAPI.Receive(); if (localPlayer) { if (transform.position != lastPosition) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position); } if (transform.rotation != lastRotation) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation); } lastPosition = transform.position; lastRotation = transform.rotation; } }
void OnMouseDrag() { //When draged we need to tell everyone else what's happening so... if (DarkRiftAPI.isConnected) { //First get it's new position... Vector3 pos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(10); //Move it to that position on our screen transform.position = new Vector3(pos.x, pos.y, 0f); //Then send it to the others if we've moved enough if (Vector3.Distance(lastPos, pos) > 0.05f) { DarkRiftAPI.SendMessageToOthers(0, (ushort)cubeID, new Vector3(pos.x, pos.y, 0f)); lastPos = pos; } } }
public void MinusHealthPoints(int damage, ushort explosionid) { if (!invul) { StartCoroutine(InvulCoolDown()); CurrentHealthPoints -= damage; UpdateHealth(CurrentHealthPoints); ourPlayerHealthBar.RunDamagedImage(); if (CurrentHealthPoints <= 0) { //we lose. Lean.LeanPool.Despawn(this.transform.root); //tell controller to check who wins, if any. DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.PlayerDied, explosionid); Debug.Log("Adding kill player " + this.id + " explosion id " + explosionid); KillTrackSystem.Instance.AddKill((ushort)this.player_id, explosionid); } } }
void Update() { //Only send data if we're connected and we own this player if (DarkRiftAPI.isConnected && DarkRiftAPI.id == networkID) { //We're going to use a tag of 1 for movement messages //If we're conencted and have moved send our position with subject 0. if (transform.position != lastPosition) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, transform.position); } //Then send our rotation with subject 1 if we've rotated. if (transform.rotation != lastRotation) { DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Rotation, transform.rotation); } //Update stuff lastPosition = transform.position; lastRotation = transform.rotation; } }
void Update() { if (DarkRiftAPI.isConnected) { DarkRiftAPI.Receive(); } if (networkID == DarkRiftAPI.id) { if (transform.position != lastPosition) { DarkRiftAPI.SendMessageToOthers(TagIndex.PokemonUpdate, TagIndex.PokemonUpdateSubjects.Position, transform.position); } if (transform.rotation != lastRotation) { DarkRiftAPI.SendMessageToOthers(TagIndex.PokemonUpdate, TagIndex.PokemonUpdateSubjects.Rotation, transform.rotation); } lastPosition = transform.position; lastRotation = transform.rotation; } }
void SerialisePosA(Vector3 pos) { //Serialise Position and Animation Values using (DarkRiftWriter writer = new DarkRiftWriter()) { //Next we write any data to the writer writer.Write(pos.x); writer.Write(pos.y); writer.Write(pos.z); SerializeAnim(); /* * writer.Write(anim.GetBool("IsRunning")); * writer.Write(anim.GetBool("IsGrounded")); * writer.Write(anim.GetInteger("State")); * writer.Write(anim.GetFloat("Speed")); * writer.Write(anim.GetFloat("Horizontal")); * writer.Write(anim.GetFloat("Vertical"));*/ Debug.Log("Serialize"); DarkRiftAPI.SendMessageToOthers(TagIndex.PlayerUpdate, TagIndex.PlayerUpdateSubjects.Position, writer); } }
protected override void OnMouseButtonDown(MouseButtons button, int id, int theItemID) { if (id == player_id) { if (button == MouseButtons.left) { if (theTileMap.theMap.GetTileAt(currentTilePos) is Noblock || theTileMap.theMap.GetTileAt(currentTilePos) is InvisibleWallBlock) { if (TheCurrentItem is GrenadeData) { GrenadeData grenade = (GrenadeData)TheCurrentItem; grenade.SetDirection(ourDirection); } GameObject obj = TheCurrentItem.PlayerSpawnBomb(theTileMap.ConvertTileToWorld(currentTilePos)); if (obj != null) { RemoteBomb remote = obj.GetComponent <RemoteBomb>(); if (remote != null) { remote.id = id; } if (DarkRiftAPI.isConnected) { DarkRiftAPI.SendMessageToOthers(NetworkingTags.Events, NetworkingTags.EventSubjects.leftMouseButton, TheCurrentItem.OrderID); } obj.GetComponent <BombsParent>().ID = id; } } } else if (button == MouseButtons.right) { ActivateRemote(DarkRiftAPI.id); if (DarkRiftAPI.isConnected) { DarkRiftAPI.SendMessageToOthers(NetworkingTags.Events, NetworkingTags.EventSubjects.rightMouseButton, DarkRiftAPI.id); } } else if (button == MouseButtons.ScrollDown) { bool Changed = false; for (int i = TheCurrentItem.OrderID + 1; i < theEquipments.Count; i++) { if (theEquipments[i].Amount > 0) { TheCurrentItem = theEquipments[i]; Changed = true; break; } } if (!Changed) { TheCurrentItem = theEquipments[0]; } } else if (button == MouseButtons.ScrollUp) { bool Changed = false; if (TheCurrentItem.OrderID == 0) { for (int i = theEquipments.Count - 1; i >= 0; i--) { if (theEquipments[i].Amount > 0) { TheCurrentItem = theEquipments[i]; Changed = true; break; } } } else { for (int i = TheCurrentItem.OrderID - 1; i >= 0; i--) { if (theEquipments[i].Amount > 0) { TheCurrentItem = theEquipments[i]; Changed = true; break; } } } if (!Changed) { TheCurrentItem = theEquipments[0]; } } } UpdateUI(TheCurrentItem); }
protected override void OnButtonPressed(Direction theDirection, int id) { //We make sure this is talking to us if (id == player_id) { switch (theDirection) { case Direction.Up: if (sp.sprite != null) { Offset = sp.sprite.bounds.extents; Offset -= Offset * 0.1f; } MoveDirection = new Vector2(0, 1); theAnimator.SetTrigger("Move Up"); break; case Direction.Down: if (sp.sprite != null) { Offset = -sp.sprite.bounds.extents; Offset -= Offset * 0.1f; } MoveDirection = new Vector2(0, -1); theAnimator.SetTrigger("Move Down"); break; case Direction.Left: if (sp.sprite != null) { Offset = -sp.sprite.bounds.extents; Offset -= Offset * 0.1f; } MoveDirection = new Vector2(-1, 0); theAnimator.SetTrigger("MoveLeft"); break; case Direction.Right: if (sp.sprite != null) { Offset = sp.sprite.bounds.extents; Offset -= Offset * 0.1f; } MoveDirection = new Vector2(1, 0); theAnimator.SetTrigger("MoveRight"); break; case Direction.Stop: MoveDirection = new Vector2(0, 0); theAnimator.SetTrigger("Stop"); break; } ourDirection = theDirection; DarkRiftAPI.SendMessageToOthers(NetworkingTags.Player, NetworkingTags.PlayerSubjects.ChangeDir, theDirection); if (LastDirection != MoveDirection) { if (Mathf.Abs(LastDirection.x - MoveDirection.x) != 0) { ourTransform.position = theTileMap.ConvertTileToWorld(theTileMap.ConvertWorldToTile(ourTransform.position)); ourTransform.position = new Vector3(ourTransform.position.x, ourTransform.position.y, -1); } else if (Mathf.Abs(LastDirection.y - MoveDirection.y) != 0) { ourTransform.position = theTileMap.ConvertTileToWorld(theTileMap.ConvertWorldToTile(ourTransform.position)); ourTransform.position = new Vector3(ourTransform.position.x, ourTransform.position.y, -1); } LastDirection = MoveDirection; } } }