コード例 #1
0
        /// <summary>
        /// Initialize awake
        /// </summary>
        public void OnEnable()
        {
            instance = this;

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

                if (unetBuilding != null)
                {
                    entities.Add(unetBuilding);
                    unetBuilding.networkedID = entities.Count;
                }
            };
        }
コード例 #2
0
        public override void DestroyBuilding(BaseBuilding _building, RaycastHit hit)
        {
            PhotonCloudBuilding building = (PhotonCloudBuilding)_building;

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

            var evnt = new UpdateNetworkedBuilding();

            evnt.buildingUID = building.networkedID;
            evnt.health      = 0;
            evnt.SendToServer();
        }
コード例 #3
0
        /// <summary>
        /// Called when the CreateNetworkBuilding event is called
        /// </summary>
        /// <param name="msg">event data</param>
        public void CreateNetworkBuildingEvent(CreateNetworkedBuilding evnt)
        {
            if (PhotonNetwork.isMasterClient)
            {
                GameObject prefab = PrefabDB.instance.GetGO(evnt.prefabID);

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

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

                    building.transform.position = (Vector3)evnt.pos;
                    building.transform.rotation = (Quaternion)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);
            }
        }