Esempio n. 1
0
        /// <summary>
        /// Load an entity
        /// </summary>
        /// <param name="evnt">our event</param>
        public static void LoadEntity(CreateNetworkedBuilding evnt)
        {
            GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

            if (prefab != null)
            {
                var instance = GameObject.Instantiate(prefab);

                ForgeBuilding building = instance.GetComponent <ForgeBuilding>();

                building.LoadData(evnt);
                entities.Add(building);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the CreateNetworkBuilding event is called
        /// </summary>
        /// <param name="evnt">event data</param>
        public void CreateNetworkBuildingEvent(CreateNetworkedBuilding evnt)
        {
            if (Networking.PrimarySocket.IsServer)
            {
                GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

                if (prefab != null && evnt.requester != null)
                {
                    var instance = GameObject.Instantiate(prefab);

                    ForgeBuilding building = instance.GetComponent <ForgeBuilding>();

                    building.transform.position = evnt.pos;
                    building.transform.rotation = evnt.rot;

                    if (!building.CheckConditions()) // check conditions serverside
                    {
                        Destroy(instance);
                        return;
                    }

                    entities.Add(building);

                    evnt.id     = entities.Count;
                    evnt.health = building.maxHealth;

                    building.LoadData(evnt);

                    building.PackData(evnt.requester, false).Send(NetworkReceivers.Others);
                }
            }
            else
            {
                LoadEntity(evnt);
            }
        }