Esempio n. 1
0
        public void Initialize(NetworkSyncTransform _nst)
        {
            nst = _nst;
            na  = nst.na ? nst.na : (nst.na = nst.GetComponent <NSTNetAdapter>());

            frameCount = 60 / nst.sendEveryXTick;

            cache_axisEnabled = new bool[3];
            for (int i = 0; i < 3; ++i)
            {
                cache_axisEnabled[i] = crusher[i].Enabled;
            }

            frames = new ElementFrame[frameCount + 1];
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new ElementFrame(Localized, Compress(), false, this);
            }

            history = new GenericX[frameCount + 1];
            for (int i = 0; i < history.Length; i++)
            {
                history[i] = new GenericX();
            }

            lastSentCompressed = Compress();
            lastSentTransform  = Localized;
        }
Esempio n. 2
0
        public static void UnregisterNstId(NetworkSyncTransform nst, NSTNetAdapter na)
        {
            // Don't try to remove this nst from lookups/arrays if it was never added.
            if (!allNsts.Contains(nst))
            {
                return;
            }

            if (na != null && nstIdToNSTLookup != null && nstIdToNSTLookup.ContainsKey(na.NetId))
            {
                nstIdToNSTLookup.Remove(na.NetId);
            }

            if (na != null && NstIds != null)
            {
                NstIds[na.NstIdSyncvar] = null;
            }

            if (allNsts != null && allNsts.Contains(nst))
            {
                allNsts.Remove(nst);
            }

            if (allNstsWithOfftick != null && allNstsWithOfftick.Contains(nst))
            {
                allNstsWithOfftick.Remove(nst);
            }
        }
Esempio n. 3
0
        // TODO move to helper
        public static void GetNstIdAndSetSyncvar(NetworkSyncTransform nst, NSTNetAdapter na, int assignValue = -1)
        {
            // Server needs to set the syncvar for the NstId
            if (na.IsServer && MasterNetAdapter.NetworkLibrary == NetworkLibrary.UNET)
            {
                if (HeaderSettings.Single.BitsForNstId < 6)
                {
                    // If an ID value hasn't been passed, we need to get a free one
                    na.NstIdSyncvar = (assignValue != -1) ? (uint)assignValue : (uint)GetFreeNstId();
                }
                else
                {
                    na.NstIdSyncvar = na.NetId;
                }
            }
            else
            {
                //TEST should use a method in na to convert the viewid to a smaller nstid
                if (NSTNetAdapter.NetLibrary == NetworkLibrary.PUN || NSTNetAdapter.NetLibrary == NetworkLibrary.PUN2)
                {
                    int clientId = (int)na.NetId / 1000;
                    int entityId = (int)na.NetId % 1000;
                    na.NstIdSyncvar = (uint)((clientId << HeaderSettings.single.bitsForPUNClients) | entityId);
                }
            }

            RegisterNstId(na.NstIdSyncvar, nst);
        }
        public void Initialize(NetworkSyncTransform _nst, INSTTransformElement _nstElement)
        {
            nst        = _nst;
            nstElement = _nstElement;

            na = nst.na ? nst.na : (nst.na = nst.GetComponent <NSTNetAdapter>());

            frameCount = NSTMaster.FRAME_COUNT / nst.sendEveryXTick;

            //// TODO: Would rather not have to do this here - but the automation for this isn't firing in time
            //crusher.CacheValues();

            frames = new ElementFrame[frameCount + 1];
            for (int i = 0; i < frames.Length; i++)
            {
                var ce = new CompressedElement();
                Compress(ce);
                frames[i] = new ElementFrame(Localized, ce, false, this);
            }

            history = new GenericX[frameCount + 1];
            for (int i = 0; i < history.Length; i++)
            {
                history[i] = new GenericX();
            }

            Compress(lastSentCompressed);
            lastSentTransform = Localized;
        }
        // TODO this is redudant with NSTNetAdapter code for UNET
        public static void CopyPlayerPrefabFromPUNtoOthers()
        {
            PUNSampleLauncher punl = PUNSampleLauncher.Single;

            if (!punl || punl.playerPrefab == null)
            {
                return;
            }

            NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);

            //// Copy player prefab from PUN launcher to NM
            //if (MasterNetAdapter.NetLib == NetworkLibrary.UNET)
            //	NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);

            //// Copy PUN playerPrefab to UNET
            //NetworkManager nm = GetNetworkManager(MasterNetAdapter.NetLib == NetworkLibrary.UNET);
            //if (nm && !nm.playerPrefab)
            //{
            //	Debug.Log("Copying Player Prefab : <b>'" + punl.playerPrefab.name + "'</b> from " + punl.GetType().Name + " to NetworkManager for you.");

            //	NetworkIdentity ni = punl.playerPrefab.GetComponent<NetworkIdentity>();
            //	if (!ni)
            //		ni = punl.playerPrefab.AddComponent<NetworkIdentity>();

            //	// This seemingly pointless code forces the NI to initialize the assetid. For some dumb reason UNET.
            //	ni.assetId.IsValid();

            //	if (nm.playerPrefab != punl.playerPrefab)
            //	{
            //		nm.playerPrefab = punl.playerPrefab;
            //		EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            //	}
            //}
        }
Esempio n. 6
0
        // TODO this is redudant with NSTNetAdapter code for UNET
        public static void CopyPlayerPrefabFromPUNtoOthers()
        {
            PUNSampleLauncher punl = PUNSampleLauncher.Single;

            if (!punl || punl.playerPrefab == null)
            {
                return;
            }

            NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);
        }
Esempio n. 7
0
        /// <summary>
        /// Remove the adapter and the NetworkIdentity/View from an object
        /// </summary>
        /// <param name="nst"></param>
        public static void RemoveAdapter(NetworkSyncTransform nst)
        {
            NetworkIdentity ni = nst.GetComponent <NetworkIdentity>();
            NSTNetAdapter   na = nst.GetComponent <NSTNetAdapter>();

            if (na)
            {
                DestroyImmediate(na);
            }

            if (ni)
            {
                DestroyImmediate(ni);
            }
        }
        /// <summary>
        /// Remove the adapter and the NetworkIdentity/View from an object
        /// </summary>
        /// <param name="nst"></param>
        public static void RemoveAdapter(NetworkSyncTransform nst)
        {
            NSTNetAdapter na = nst.GetComponent <NSTNetAdapter>();
            PhotonView    pv = nst.GetComponent <PhotonView>();

            if (na)
            {
                DestroyImmediate(na);
            }

            if (pv)
            {
                DestroyImmediate(pv);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Replacement for standard Awake that instead of firing when the component first wakes up, fires after the root NetworkSyncTransform
        /// completes its Awake(). This ensures the NST has been initialized first.
        /// </summary>
        public virtual void OnNstPostAwake()
        {
            cachedGameObject = gameObject;
            cachedTransform  = transform;

            nst = cachedTransform.root.GetComponent <NetworkSyncTransform>();
            na  = nst.na;

            // If there is no network, then this NST shouldn't exist - is likely just an orphaned prefab instance in the scene and will be deleted at startup.
            if (nst.destroyUnspawned && MasterNetAdapter.ServerIsActive == false && MasterNetAdapter.ClientIsActive == false)
            {
                isShuttingDown = true;
                return;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Ensure all required dependencies are added for this NST to work. Can be called often in edit mode, and should be.
        /// </summary>
        /// <param name="nst"></param>
        /// <param name="silence"></param>
        public static void EnsureAllNSTDependencies(this NetworkSyncTransform nst, SerializedObject serializedObject, bool silence = false)
        {
            EnsureSceneNetLibDependencies();

            if (Application.isPlaying)
            {
                return;
            }

            // If user tried to put NST where it shouldn't be... remove it and all of the required components it added.
            if (nst.transform.parent != null)
            {
                XDebug.LogError("NetworkSyncTransform must be on the root of an prefab object.");
                nst.nstElementsEngine = nst.transform.GetComponent <NSTElementsEngine>();

                NSTNetAdapter.RemoveAdapter(nst);

                Object.DestroyImmediate(nst);

                if (nst.nstElementsEngine != null)
                {
                    Object.DestroyImmediate(nst.nstElementsEngine);
                    EditorUtility.SetDirty(nst.gameObject);
                }
                return;
            }

            nst.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(nst.transform, false);

            nst.na = EditorUtils.EnsureRootComponentExists <NSTNetAdapter>(nst.gameObject, false);

            //AddRewindEngine(nst);

            //// Add this NST to the prefab spawn list (and as player prefab if none exists yet) as an idiot prevention
            NSTNetAdapter.AddAsRegisteredPrefab(nst.gameObject, true, silence);
            return;
        }