private void OnAnimalSpawnRequested(Transform obj) { // Someone requested an animal spawn, adjust to put it on top of ground obj.Position.Y = 100; // TODO: see @Utils.Spatial.PositionAboveGround var aboveGround = obj.Position.ToVector3().PositionAboveGround(); obj.Position = aboveGround.Net(); if (double.IsInfinity(obj.Position.Y)) { Debug.LogWarning($"Someone requested an animal spawn outside map"); return; } var packet = new Packet().Basic(obj.Position); obj.Id = _nextId + 1; packet.Spawn = new Spawn { Animal = new Animal { Transform = obj } }; Debug.Log($"S1 requested animal spawn, approving at {obj.Position}"); Mcm.instance.RpcAsync(packet); SpawnAnimal(aboveGround, obj.Rotation.ToQuaternion(), Gm.instance.Experience.AnimalCharacteristics, Gm.instance.Experience.AnimalCharacteristicsMinimumBound, Gm.instance.Experience.AnimalCharacteristicsMaximumBound); }
private void OnTransformUpdated(Transform obj) // TODO: merge spawn and update ? { if (!m_Animals.ContainsKey(obj.Id)) { // Debug.LogError($"Tried to update in-existent animal {obj.Id}"); // TODO: maybe should pass client id return; } m_Animals[obj.Id].transform.position = obj.Position.ToVector3(); m_Animals[obj.Id].transform.rotation = obj.Rotation.ToQuaternion(); }
private void DestroyTree(Transform obj) { if (!m_Trees.ContainsKey(obj.Id)) { // Debug.LogError($"Tried to destroy in-existent tree {obj.Id}"); return; } TreePool.instance.Despawn(m_Trees[obj.Id].gameObject); m_Trees.Remove(obj.Id); }
private Vegetation SpawnTree(Transform obj) { m_NextId = obj.Id; var(go, _) = TreePool.instance.Spawn(obj.Position.ToVector3(), obj.Rotation.ToQuaternion()); m_Trees[obj.Id] = go.GetComponent <Vegetation>(); m_Trees[obj.Id].id = obj.Id; if (SessionManager.instance.isServer) { m_Trees[obj.Id].BringToLife(); } return(m_Trees[obj.Id]); }
private void DestroyAnimal(Transform obj) { if (!m_Animals.ContainsKey(obj.Id)) { // TODO: fix // Debug.LogError($"Tried to destroy in-existent animal {obj.Id}"); return; } Pool.Despawn(m_Animals[obj.Id].gameObject); if (!m_Animals.Remove(obj.Id)) { Debug.LogError($"Failed to remove animal {obj.Id}"); } }
private CommonAnimal SpawnAnimal(Transform obj) { // Debug.Log($"Spawning animal {obj}"); m_NextId = obj.Id; var a = Pool.Spawn(animalPrefab, obj.Position.ToVector3(), obj.Rotation.ToQuaternion()); m_Animals[obj.Id] = a.GetComponent <CommonAnimal>(); m_Animals[obj.Id].id = obj.Id; // Only server handle animal behaviours if (SessionManager.instance.isServer) { m_Animals[obj.Id].BringToLife(); // var tSync = m_Animals[obj.Id].gameObject.AddComponent<TransformSync>(); // tSync.id = obj.Id; } return(m_Animals[obj.Id]); }
private void OnTreeSpawnRequested(Transform obj) { Debug.Log($"S1 requested tree spawn"); // Someone requested a tree spawn, adjust to put it on top of ground obj.Position.Y = 1000; // TODO: see @Utils.Spatial.PositionAboveGround obj.Position = obj.Position.ToVector3().PositionAboveGround().Net(); var packet = new Packet().Basic(obj.Position); obj.Id = ++m_NextId; packet.Spawn = new Spawn { Tree = new Api.Realtime.Tree { Transform = obj } }; MatchCommunicationManager.instance.RpcAsync(packet); SpawnTree(obj); }
private void OnPlantSpawnRequested(Transform obj) { Debug.Log($"S1 requested tree spawn"); // Someone requested a tree spawn, adjust to put it on top of ground obj.Position.Y = 1000; // TODO: see @Utils.Spatial.PositionAboveGround var aboveGround = obj.Position.ToVector3().PositionAboveGround(); obj.Position = aboveGround.Net(); var packet = new Packet().Basic(obj.Position); obj.Id = _nextId + 1; packet.Spawn = new Spawn { Plant = new Api.Realtime.Plant { Transform = obj } }; Mcm.instance.RpcAsync(packet); SpawnPlant(aboveGround, obj.Rotation.ToQuaternion(), Gm.instance.Experience.PlantCharacteristics, Gm.instance.Experience.PlantCharacteristicsMinimumBound, Gm.instance.Experience.PlantCharacteristicsMaximumBound); }
private void OnTreeDestroyRequested(Transform obj) => throw new NotImplementedException();
private void OnTreeDestroyed(Transform obj) => DestroyTree(obj);
private void OnTreeSpawned(Transform obj) => SpawnTree(obj);
private void OnAnimalDestroyed(Transform obj) => DestroyAnimal(obj);
private void OnAnimalSpawned(Transform obj) => SpawnAnimal(obj);
private void OnPlantDestroyed(Transform obj) => DestroyPlant(obj.Id);
private void OnPlantSpawned(Transform obj) => SpawnPlant(obj.Position.ToVector3(), obj.Rotation.ToQuaternion(), Gm.instance.Experience.PlantCharacteristics, Gm.instance.Experience.PlantCharacteristicsMinimumBound, Gm.instance.Experience.PlantCharacteristicsMaximumBound);