public void Break(bool front) { if (front) { frontBroken = true; } else { backBroken = true; } // Add extra drag to train tc.AddDrag(dragDelta); // Spawn interactable w/ particles GameObject sparks = Instantiate(sparkPrefab, GameObject.FindGameObjectWithTag("Train").transform); sparks.transform.position = transform.position + sparks.transform.localPosition; if (!front) { sparks.transform.position += new Vector3(0, 0, 7.3f); } WheelInteract wi = sparks.GetComponent <WheelInteract>(); wi.car = gameObject.GetComponent <WheelBreak>(); wi.isFront = front; sparks.GetComponent <TTSID>().Init(); TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(sparks); TTS.ObjectSync os = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>(); os.initBuffer.Add(initMessage); SyncState(); }
void TSSInitGame() { Transform world = GameObject.Find("World").transform; TTSTrainController tc = GameObject.Find("Train").GetComponent <TTSTrainController>(); int i = 0, loopPos = 0; foreach (IClient c in darkRiftServer.Server.ClientManager.GetAllClients()) { if ((i % 4) == 0) { tc.trainCars.Add(tc.additionalLoop[loopPos]); loopPos = (loopPos + 1) % (tc.additionalLoop.Count - 1); } i++; } GameObject.Find("Train").GetComponent <TTSTrainController>().BuildTrain(); // Instantiate players SpawnPlayer(65000); foreach (IClient c in darkRiftServer.Server.ClientManager.GetAllClients()) { SpawnPlayer(c.ID); } // Sync all gameObjects IEnumerable <TTS.GameObjectInitMessage> oInitIter = from c in InOrderChildren(world) where c != world select new TTS.GameObjectInitMessage(c.gameObject); TTS.ObjectSync os = GetComponent <TTS.ObjectSync>(); foreach (TTS.GameObjectInitMessage m in oInitIter) { os.initBuffer.Add(m); } os.TriggerBufferSync(); // Tell clients to associate w) their respective NetworkPlayers Dictionary <ushort, ushort> clientPlayerMap = GameObject.FindGameObjectWithTag("Network") .GetComponent <TTSServer>().clientPlayerMap; foreach (IClient c in darkRiftServer.Server.ClientManager.GetAllClients()) { using (DarkRiftWriter w = DarkRiftWriter.Create()) { w.Write(clientPlayerMap[c.ID]); using (Message m = Message.Create((ushort)TTS.MessageType.PLAYER_ASSOC, w)) c.SendMessage(m, SendMode.Reliable); } } }
public override void AfterUse() { //spawn food object here Debug.Log("Spawn food object"); GameObject food = Instantiate(foods[Random.Range(0, foods.Length)], gameObject.transform.position + new Vector3(-1, 1.55f, 0), Quaternion.identity); food.transform.parent = GameObject.FindGameObjectWithTag("Train").transform; food.GetComponent <TTSID>().Init(); TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(food); TTS.ObjectSync os = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>(); os.initBuffer.Add(initMessage); inUse = false; }
public override void AfterUse() { //spawn food object here Debug.Log("Spawn coal"); interactTransform.GetComponent <TTSPlayerAnimator>().SetBool(9, false); GameObject coal = Instantiate(coalPrefabs[Random.Range(0, coalPrefabs.Length)], gameObject.transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity); coal.transform.parent = GameObject.FindGameObjectWithTag("Train").transform; coal.GetComponent <TTSID>().Init(); TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(coal); TTS.ObjectSync os = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>(); os.initBuffer.Add(initMessage); inUse = false; }
private void Start() { isServer = GameObject.FindGameObjectWithTag("Network") .GetComponent <XmlUnityServer>() != null; if (isServer) { Init(); TTS.ObjectSync os = GameObject.FindGameObjectWithTag("Network") .GetComponent <TTS.ObjectSync>(); movementBuffer = os.movementBuffer; trackedDataBuffer = os.trackedDataBuffer; lastSyncedPosition = transform.localPosition; lastSyncedRotation = transform.localRotation; } else { Destroy(GetComponent <Rigidbody>()); if (GetComponent <BoxCollider>() != null) { Destroy(GetComponent <BoxCollider>()); } } }
public override void AfterUse() { interactTransform.GetComponent <TTSPlayerAnimator>().SetBool(7, false); if (interactTransform.GetComponentInChildren <PickupVolume>().potentialPickups.Contains(toCook.transform)) { interactTransform.GetComponentInChildren <PickupVolume>().potentialPickups.Remove(toCook.transform); } string prefabTag = toCook.transform.GetChild(1).name; toCook.GetComponent <TTSID>().Remove(); GameObject foodPrefab = Resources.Load($"Prefabs/{prefabTag}", typeof(GameObject)) as GameObject; GameObject cookedFood = GameObject.Instantiate(foodPrefab, transform.position + Vector3.up * 2, Quaternion.identity, GameObject.FindGameObjectWithTag("Train").transform); cookedFood.GetComponent <TTSID>().Init(); TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(cookedFood); TTS.ObjectSync os = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>(); os.initBuffer.Add(initMessage); toCook = null; inUse = false; }