private void Awake() { map = new SortedDictionary <string, Object>(); autoDestroyMap = new Dictionary <ushort, AutoDestroy>(); ushort nID = 0; foreach (var item in Objects) { if (item != null) { string name = item.name.Trim().ToLowerInvariant(); map.Add(name, item); Debug.Log($"Registered '{name}' as {item.GetType().Name}."); if (item is GameObject) { var go = item as GameObject; var autoDestroy = go.GetComponent <AutoDestroy>(); if (autoDestroy != null) { autoDestroy.NetSpawnID = nID; nID++; autoDestroyMap.Add(autoDestroy.NetSpawnID, autoDestroy); Debug.Log($"It is autodestroy mapped to ID {autoDestroy.NetSpawnID}"); } } } } Instance = this; }
public static void ProcessMessage(NetIncomingMessage msg) { ushort id = msg.ReadUInt16(); Vector2 pos = msg.ReadVector2(); var spawned = PoolObject.Spawn(Spawnables.GetAutoDestroy(id)); spawned.transform.position = pos; }
private void Start() { JNet.Init("Project B"); // TODO move to somewhere more sensible, such as 'game manager' Spawnables.NetRegisterAll(); UI.AddDrawer(DrawUI); }
private void UponPartHealthChanged(HealthPart part, float change) { if (part.IsVital) { if (part.Health == 0f) { Debug.Log($"Damn we dead. Died because {part.Name} was destroyed."); IsDead = true; if (ExplodeUponDeath) { var spawned = PoolObject.Spawn(Spawnables.Get <PoolObject>("ExplosionEffect")); spawned.transform.position = this.transform.position; spawned.GetComponent <AutoDestroy>().NetSpawn(); Destroy(this.gameObject); } } } }