Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        private void Start()
        {
            JNet.Init("Project B");

            // TODO move to somewhere more sensible, such as 'game manager'
            Spawnables.NetRegisterAll();

            UI.AddDrawer(DrawUI);
        }
Ejemplo n.º 4
0
        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);
                    }
                }
            }
        }