/// <summary>
        /// Receive and handle events
        /// </summary>
        public void HandleEvents(byte eventCode, object content, int senderid)
        {
            byte[] data;


            if (eventCode == CreateNetworkedBuilding.MSG)
            {
                data = (byte[])content;
                CreateNetworkedBuilding evnt = CreateNetworkedBuilding.Deserialize(data);

                if (evnt != null)
                {
                    CreateNetworkBuildingEvent(evnt);
                }
            }
            else if (eventCode == UpdateNetworkedBuilding.MSG)
            {
                data = (byte[])content;
                UpdateNetworkedBuilding evnt = UpdateNetworkedBuilding.Deserialize(data);

                if (evnt != null)
                {
                    UpdateNetworkedBuildingEvent(evnt);
                }
            }
        }
        /// <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);

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

                building.LoadData(evnt);
                entities.Add(building);
            }
        }
Esempio n. 3
0
        public void LoadData(CreateNetworkedBuilding data)
        {
            this.transform.position = (Vector3)data.pos;
            this.transform.rotation = (Quaternion)data.rot;

            CallLoad(this);

            this.networkedID = data.id;
            this.placedOn    = PhotonCloudEntitiesManager.GetEntity(data.placedOnID);

            if (placedOn != null)
            {
                this.SnappedTo = placedOn.ReturnSocket(transform.position, this.buildingType);
            }

            this.PlaceBuilding();

            PhotonCloudBuildingPlacer.LocalNetworkedBuildingPlaced(data.requester);

            this.health = data.health;
        }
Esempio n. 4
0
        public CreateNetworkedBuilding PackData(PhotonView requester, bool initiateEvent)
        {
            if (initiateEvent)
            {
                CallPack(this);
            }

            var evnt = new CreateNetworkedBuilding();

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

            evnt.id         = networkedID;
            evnt.placedOnID = networkedPlacedOnID;
            evnt.prefabID   = this.prefabID;

            evnt.health = this.health;

            evnt._requesterID = requester == null ? -1 : requester.viewID;

            return(evnt);
        }
        /// <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);
            }
        }