public void PickupItemInit(double timeBase, float[] inactivePickupsAndTimes) { this.IsWaitingForPickupInit = false; // if there are no inactive pickups, the sender will send a list of 0 items. this is not a problem... for (int i = 0; i < inactivePickupsAndTimes.Length / 2; i++) { int arrayIndex = i * 2; int viewIdOfPickup = (int)inactivePickupsAndTimes[arrayIndex]; float timeUntilRespawnBasedOnTimeBase = inactivePickupsAndTimes[arrayIndex + 1]; PhotonView view = PhotonView.Find(viewIdOfPickup); NetworkItem pi = view.GetComponent <NetworkItem>(); if (timeUntilRespawnBasedOnTimeBase <= 0) { pi.PickedUp(); } else { double timeOfRespawn = timeUntilRespawnBasedOnTimeBase + timeBase; //Debug.Log(view.viewID + " respawn: " + timeOfRespawn + " timeUntilRespawnBasedOnTimeBase:" + timeUntilRespawnBasedOnTimeBase + " SecondsBeforeRespawn: " + pi.secondsBeforeRespawn); double timeBeforeRespawn = timeOfRespawn - PhotonNetwork.Time; if (timeUntilRespawnBasedOnTimeBase <= 0) { timeBeforeRespawn = 0.0f; } pi.timeUntilRespawn = (float)timeBeforeRespawn; pi.PickedUp(); } } }
/// <summary>Summarizes all PickupItem ids and spawn times for new players. Calls RPC "PickupItemInit".</summary> /// <param name="targetPlayer">The player to send the pickup times to. It's a targetted RPC.</param> private void SendPickedUpItems(Player targetPlayer) { if (targetPlayer == null) { Debug.LogWarning("Cant send PickupItem spawn times to unknown targetPlayer."); return; } double now = PhotonNetwork.Time; double soon = now + TimeDeltaToIgnore; NetworkItem[] items = new NetworkItem[NetworkItem.DisabledPickupItems.Count]; NetworkItem.DisabledPickupItems.CopyTo(items); List <float> valuesToSend = new List <float>(items.Length * 2); for (int i = 0; i < items.Length; i++) { NetworkItem pi = items[i]; if (pi.secondsBeforeRespawn <= 0) { valuesToSend.Add(pi.ViewID); valuesToSend.Add((float)0.0f); } else { double timeUntilRespawn = pi.timeOfRespawn - PhotonNetwork.Time; if (pi.timeOfRespawn > soon) { // the respawn of this item is not "immediately", so we include it in the message "these items are not active" for the new player //Debug.Log(pi.ViewID + " respawn: " + pi.timeOfRespawn + " timeUntilRespawn: " + timeUntilRespawn + " (now: " + PhotonNetwork.time + ")"); valuesToSend.Add(pi.ViewID); valuesToSend.Add((float)timeUntilRespawn); } } } //Debug.Log("Sent count: " + valuesToSend.Count + " now: " + now); this.photonView.RPC(INIT, targetPlayer, PhotonNetwork.Time, valuesToSend.ToArray()); }
// INITIALIZERS: ----------------------------------------------------------------------------------------------- private void OnEnable() { if (serializedObject == null) { return; } this.trigger = (NetworkItem)target; this.tabIndex = this.prevTabIndex = EditorPrefs.GetInt(string.Format(KEY_STATE, target.GetHashCode())); this.sectionTrigger = new Section( "Pickup Trigger", "Trigger icon.png", this.Repaint, "Assets/Gizmos/GameCreator/Core"); //this.sectionParameters = new EditorGUIUtils.Section("Parameters", "List.png", this.Repaint); this.sectionStartActions = new Section( "On Start", "On Start.png", this.Repaint, "Assets/Plugins/GameCreator/Extra/Icons/Igniters"); this.sectionEvent = new Section( "On Picked Up", "Pickup.png", this.Repaint); this.spRespawn = serializedObject.FindProperty("secondsBeforeRespawn"); /*if(trigger.actions.Count == 0) * { * trigger.actions.Add(new Actions() { actionsList = trigger.onPickUpActions }); * }*/ SerializedProperty spIgniters = serializedObject.FindProperty("igniters"); this.spIgnitersKeys = spIgniters.FindPropertyRelative("keys"); this.spIgnitersValues = spIgniters.FindPropertyRelative("values"); if (this.spIgnitersKeys.arraySize == 0) { Igniter igniter = this.trigger.gameObject.AddComponent <IgniterTriggerEnter>(); igniter.Setup(this.trigger); igniter.enabled = false; this.spIgnitersKeys.InsertArrayElementAtIndex(0); this.spIgnitersValues.InsertArrayElementAtIndex(0); this.spIgnitersKeys.GetArrayElementAtIndex(0).intValue = Trigger.ALL_PLATFORMS_KEY; this.spIgnitersValues.GetArrayElementAtIndex(0).objectReferenceValue = igniter; this.serializedObject.ApplyModifiedProperties(); this.serializedObject.Update(); } this.UpdateIgnitersPlatforms(); this.ignitersIndex = EditorPrefs.GetInt(KEY_IGNITER_INDEX_PREF, 0); if (this.ignitersIndex >= this.spIgnitersKeys.arraySize) { this.ignitersIndex = this.spIgnitersKeys.arraySize - 1; EditorPrefs.SetInt(KEY_IGNITER_INDEX_PREF, this.ignitersIndex); } this.spMinDistance = serializedObject.FindProperty("minDistance"); this.spMinDistanceToPlayer = serializedObject.FindProperty("minDistanceToPlayer"); }