Ejemplo n.º 1
0
        public override void PlaceBuilding()
        {
            UNetBuilding building = currentBuilding as UNetBuilding;

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

            DestroyCurrentBuilding();
            ResetBuildingInstance();
        }
Ejemplo n.º 2
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);

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

                building.LoadData(evnt);
                entities.Add(building);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize awake
        /// </summary>
        public void OnEnable()
        {
            instance = this;

            uConstruct.Core.Saving.BuildingGroupSaveData.OnBuildingLoadedEvent += (BaseBuilding building) =>
            {
                UNetBuilding unetBuilding = building as UNetBuilding;

                if (unetBuilding != null)
                {
                    entities.Add(unetBuilding);
                    unetBuilding.networkedID = entities.Count;
                }
            };
        }
Ejemplo n.º 4
0
        public override void DestroyBuilding(BaseBuilding _building, RaycastHit hit)
        {
            UNetBuilding building = (UNetBuilding)_building;

            if (building == null)
            {
                base.DestroyBuilding(building, hit);
                return;
            }

            var evnt = new UpdateNetworkedBuilding();

            evnt.buildingUID = building.networkedID;
            evnt.health      = 0;
            evnt.SendToServer();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when the CreateNetworkBuilding event is called
        /// </summary>
        /// <param name="msg">event data</param>
        public void CreateNetworkBuildingEvent(NetworkMessage msg)
        {
            var evnt = msg.ReadMessage <CreateNetworkedBuilding>();

            if (NetworkServer.active)
            {
                GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

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

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

                    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();
                }
            }
            else
            {
                LoadEntity(evnt);
            }
        }