PickupItemInit
How do I use Pickup Item Init
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PickupItemSyncer.cs
Copy
87 private void SendPickedUpItems(PhotonPlayer targtePlayer)
88 {
89 if (targtePlayer == null)
90 {
91 Debug.LogWarning("Cant send PickupItem spawn times to unknown targetPlayer.");
92 return;
93 }
94
95 double now = PhotonNetwork.time;
96 double soon = now + TimeDeltaToIgnore;
97
98
99 PickupItem[] items = new PickupItem[PickupItem.DisabledPickupItems.Count];
100 PickupItem.DisabledPickupItems.CopyTo(items);
101
102 List
103 for (int i = 0; i < items.Length; i++)
104 {
105 PickupItem pi = items[i];
106 if (pi.SecondsBeforeRespawn <= 0)
107 {
108 valuesToSend.Add(pi.ViewID);
109 valuesToSend.Add((float)0.0f);
110 }
111 else
112 {
113 double timeUntilRespawn = pi.TimeOfRespawn - PhotonNetwork.time;
114 if (pi.TimeOfRespawn > soon)
115 {
116 // the respawn of this item is not "immediately", so we include it in the message "these items are not active" for the new player
117 Debug.Log(pi.ViewID + " respawn: " + pi.TimeOfRespawn + " timeUntilRespawn: " + timeUntilRespawn + " (now: " + PhotonNetwork.time + ")");
118 valuesToSend.Add(pi.ViewID);
119 valuesToSend.Add((float)timeUntilRespawn);
120 }
121 }
122 }
123
124 Debug.Log("Sent count: " + valuesToSend.Count + " now: " + now);
125 this.photonView.RPC("PickupItemInit", targtePlayer, PhotonNetwork.time, valuesToSend.ToArray());
126 }
File name: PickupItemSyncer.cs
Copy
130 public void PickupItemInit(double timeBase, float[] inactivePickupsAndTimes)
131 {
132 this.IsWaitingForPickupInit = false;
133
134 // if there are no inactive pickups, the sender will send a list of 0 items. this is not a problem...
135 for (int i = 0; i < inactivePickupsAndTimes.Length / 2; i++)
136 {
137 int arrayIndex = i*2;
138 int viewIdOfPickup = (int)inactivePickupsAndTimes[arrayIndex];
139 float timeUntilRespawnBasedOnTimeBase = inactivePickupsAndTimes[arrayIndex + 1];
140
141
142 PhotonView view = PhotonView.Find(viewIdOfPickup);
143 PickupItem pi = view.GetComponent
144
145 if (timeUntilRespawnBasedOnTimeBase <= 0)
146 {
147 pi.PickedUp(0.0f);
148 }
149 else
150 {
151 double timeOfRespawn = timeUntilRespawnBasedOnTimeBase + timeBase;
152
153 Debug.Log(view.viewID + " respawn: " + timeOfRespawn + " timeUntilRespawnBasedOnTimeBase:" + timeUntilRespawnBasedOnTimeBase + " SecondsBeforeRespawn: " + pi.SecondsBeforeRespawn);
154 double timeBeforeRespawn = timeOfRespawn - PhotonNetwork.time;
155 if (timeUntilRespawnBasedOnTimeBase <= 0)
156 {
157 timeBeforeRespawn = 0.0f;
158 }
159
160 pi.PickedUp((float) timeBeforeRespawn);
161 }
162 }
163 }
PickupItemInit 108 lượt xem
Gõ tìm kiếm nhanh...