private void Awake() { rb = GetComponentInParent <Rigidbody>(); rb2d = GetComponentInParent <Rigidbody2D>(); _hasRigidBody = rb || rb2d; needsSnapshot = !_hasRigidBody || (rb && rb.isKinematic) || (rb2d && rb2d.isKinematic); localContactTrigger = GetComponent <IContactTrigger>(); /// Register timing callbacks with Master. /// TODO: We likely should slave timings off of the owner if (needsSnapshot) { NetMaster.RegisterCallbackInterfaces(this); } /// No need for the interpolation callback if we are using forces. if (_hasRigidBody) { NetMaster.onPreUpdates.Remove(this); } /// Find interfaces for termination callbacks GetComponents(onHit); GetComponents(onTerminate); }
protected virtual void OnDisable() { if (preventRepeats) { NetMaster.RegisterCallbackInterfaces(this, false, true); } }
private void LateUpdate() { int cnt = onPostLateUpdateCallbacksCached.Count; for (int i = 0; i < cnt; ++i) { onPostLateUpdateCallbacksCached[i].OnPostLateUpdate(); } NetMaster.ApplyQueuedRegistrations(); }
protected virtual void OnEnable() { if (preventRepeats) { NetMaster.RegisterCallbackInterfaces(this); triggeringHitscans.Clear(); triggeringEnters.Clear(); triggeringStays.Clear(); } }
public static void EnsureExistsInScene() { /// Some basic singleton enforcement GameObject go = null; if (single) { go = single.gameObject; } else { /// Use NetMasterLate go if that singleton exists (this will be rare or never, but just here to cover all cases) if (NetMasterLate.single) { go = NetMasterLate.single.gameObject; } single = FindObjectOfType <NetMaster>(); if (single) { go = single.gameObject; } else { // No singletons exist... make a new GO if (!go) { go = new GameObject("Net Master"); } single = go.AddComponent <NetMaster>(); } } // Enforce singleton for NetMasterLate if (!NetMasterLate.single) { NetMasterLate.single = FindObjectOfType <NetMasterLate>(); if (!NetMasterLate.single) { NetMasterLate.single = go.AddComponent <NetMasterLate>(); } } // cached values that don't change frameCount = SimpleSyncSettings.FrameCount; frameCountBits = SimpleSyncSettings.FrameCountBits; sendEveryXTick = SimpleSyncSettings.SendEveryXTick; NetMsgCallbacks.RegisterCallback(ReceiveMessage); }
private void OnEnable() { #if PUN_2_OR_NEWER PhotonNetwork.AddCallbackTarget(this); #endif NetMaster.RegisterCallbackInterfaces(this, true); activeNetObjs.Add(this); /// OnPostEnable Callbacks int cnt = onEnableCallbacks.Count; for (int i = 0; i < cnt; ++i) { onEnableCallbacks[i].OnPostEnable(); } }
private void Awake() { if (single && single != this) { /// If a singleton already exists, destroy the old one - TODO: Not sure about this behaviour yet. Allows for settings changes with scene changes. Destroy(single); } single = this; DontDestroyOnLoad(this); _prevFrameId = frameCount - 1; _prevSubFrameId = sendEveryXTick - 1; }
private void OnDisable() { #if PUN_2_OR_NEWER PhotonNetwork.RemoveCallbackTarget(this); #endif NetMaster.RegisterCallbackInterfaces(this, false); if (activeNetObjs.Contains(this)) { activeNetObjs.Remove(this); } /// OnPostDisable Callback int cnt = onDisableCallbacks.Count; for (int i = 0; i < cnt; ++i) { onDisableCallbacks[i].OnPostDisable(); } }
public void OnDeserialize(int sourceFrameId, int originFrameId, int localframeId, byte[] buffer, ref int bitposition, bool hasData) { #if SNS_WARNINGS bufferAddTime[localframeId] = Time.time; #endif SerializationFlags flags = SerializationFlags.None; if (hasData) { #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 111) { Debug.LogError("Failed Integrity check pre PackObjs."); } #endif FrameArrival arrival = NetMaster.CheckFrameArrival(localframeId); /// Deserialize Pack Objects //int prevFrameId = ((localframeId == 0) ? SimpleSyncSettings.FrameCount : localframeId) - 1; int pcnt = packObjRecords.Count; for (int i = 0; i < pcnt; ++i) { var p = packObjRecords[i]; var pframe = p.packFrames[localframeId]; int mcnt = p.info.fieldCount; for (int m = 0; m < mcnt; ++m) { pframe.mask[m] = buffer.ReadBool(ref bitposition); } int maskOffset = 0; Debug.Log("PRE"); var flag = p.info.UnpackFrameFromBuffer(pframe, ref pframe.mask, ref pframe.isCompleteMask, ref maskOffset, buffer, ref bitposition, originFrameId, SerializationFlags.None); flags |= flag; //Debug.Log(localframeId + " Des READY? flg: " + flag + " " + p.readyMask.AllAreTrue + " " + p.readyMask.PrintMask(null) + " " // + p.readyMask.Seg1 + ":" + p.readyMask.AllTrue1 + " " + p.readyMask.Seg2 + ":" + p.readyMask.AllTrue2); /// Experimental - Apply valid values as they arrive if pack object isn't fully ready. Ensure even a late arriving full update counts toward Ready if (!p.readyMask.AllAreTrue /*&& (flag & SerializationFlags.IsComplete) != 0*/) { /// Add any always ready bits (Triggers) p.readyMask.OR(p.info.defaultReadyMask); p.readyMask.OR(pframe.isCompleteMask); /// Only write to syncvars that are not already marked as valid FastBitMask128 newchangesmask = !p.readyMask & pframe.isCompleteMask; maskOffset = 0; p.info.CopyFrameToObj(pframe, p.component, ref newchangesmask, ref maskOffset); Debug.Log(localframeId + "<b> Des PRE COMPLETE? </b>" + p.readyMask.AllAreTrue + " " + p.readyMask.PrintMask(null) + " " + p.readyMask.Seg1 + ":" + p.readyMask.AllTrue1 + " " + p.readyMask.Seg2 + ":" + p.readyMask.AllTrue2); } } packObjValidMask[localframeId] = true; #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 123) { Debug.LogError(name + " Failed Integrity check post PackObjs. " + localframeId); } #endif /// Deserialize SyncObjs int cnt = onNetDeserializeCallbacks.Count; for (int i = 0; i < cnt; ++i) { var flag = onNetDeserializeCallbacks[i].OnNetDeserialize(originFrameId, localframeId, buffer, ref bitposition, arrival); flags |= flag; /// Experimental - immediately apply complete frames to unready sync objects. //if (arrival == FrameArrival.IsLate && (flag & SerializationFlags.IsComplete) != 0 && !syncObjReadyMask[i]) // Debug.Log("Call an early Apply here when a method exists for that."); } #if SNS_WARNINGS /// Integrity check if (buffer.Read(ref bitposition, 8) != 234) { Debug.LogError(name + " Failed Integrity check post SyncObjs. " + localframeId); } #endif } }
private void OnDestroy() { NetMaster.RegisterCallbackInterfaces(this, false, true); }