Example #1
0
        public override void PlaceBuilding()
        {
            ForgeBuilding building = currentBuilding as ForgeBuilding;

            if (building != null)
            {
                var evnt = building.PackData(entity, true);
                evnt.Send(NetworkReceivers.Server);
            }

            DestroyCurrentBuilding();
            ResetBuildingInstance();
        }
Example #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);
            }
        }