Exemplo n.º 1
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);
            }
        }
Exemplo n.º 3
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;
        }
        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;
        }
Exemplo n.º 5
0
    /// <summary>
    /// When a custom message is received, the OnCustomMsgRcvEvent is fired. Note that the rotations will only be correct if you have the NST set to update
    /// rotations on events. If it is set to 'changes only' these rotations values will be zero.
    /// </summary>
    private static void OnCustomMsgRcv(NetworkConnection ownerConn, byte[] bytearray, NetworkSyncTransform shooterNst, Vector3 pos, List <GenericX> positions, List <GenericX> rotations)
    {
        //For this example we fired locally already when the custom message was sent (with OnCustomMsgSend). Firing again here on the local player would cause repeat fire events.
        //Note however that code for the local player can be added here to sync the projectile with the server, by adding a projectileID to your custom events.

        Weapon wpn = shooterNst.GetComponent <Weapon>();

        PlayerFireCustomMsg weaponFireMsg = bytearray.DeserializeToStruct <PlayerFireCustomMsg>();

        if ((WeaponType)weaponFireMsg.weaponId == WeaponType.Bullet)
        {
            if (!shooterNst.isLocalPlayer)
            {
                wpn.FireBullet(pos, rotations[0], weaponFireMsg);
            }
        }

        // Hitscan arrive on server/other clients

        else if ((WeaponType)weaponFireMsg.weaponId == WeaponType.Hitscan)
        {
            //DebugText.Log(weaponFireMsg.hitmask.PrintBitMask() + " RCV " + (WeaponType)weaponFireMsg.weaponId);
            uint confirmedHitmask = 0;

            // Draw the graphic if this isn't the local player
            if (!shooterNst.isLocalPlayer)
            {
                wpn.DrawRay(pos, rotations[0]);
            }

            // Server needs to test if this was a hit.
            if (NetworkServer.active)
            {
                for (int i = 0; i < 32; i++)
                {
                    if (weaponFireMsg.hitmask.GetBitInMask(i) == false)
                    {
                        continue;
                    }

                    NetworkSyncTransform hitNst = NetworkSyncTransform.GetNstFromId((uint)i);
                    bool hit = hitNst.TestHitscanAgainstRewind(ownerConn, new Ray(pos, (Quaternion)rotations[0] * Vector3.forward));

                    if (hit)
                    {
                        ((int)hitNst.NstId).SetBitInMask(ref confirmedHitmask, true);
                    }
                }
                DebugText.Log("Rewind Confirmation Mask : \n" + confirmedHitmask.PrintBitMask(), true);
            }
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// OnCustomMsgSndEvent fires on the originating client when a custom event is sent. The position and rotation information will contain the same
    /// lossy rounding errors/ranges that are being sent to the network. Useful for ensuring that your local events use the exact same pos/rot data
    /// the server and clients will be using (such as projectile vectors).
    /// </summary>
    /// <param name="rootPos">Lossy position after compression - exactly what is sent.</param>
    /// <param name="rotations">Lossy rotation after compression - exactly what is sent.</param>
    private static void OnCustomMsgSnd(NetworkConnection ownerConn, byte[] bytearray, NetworkSyncTransform nst, Vector3 rootPos, List <GenericX> positions, List <GenericX> rotations)
    {
        Weapon wpn = nst.GetComponent <Weapon>();

        PlayerFireCustomMsg weaponFireMsg = bytearray.DeserializeToStruct <PlayerFireCustomMsg>();

        if (weaponFireMsg.weaponId == (byte)WeaponType.Bullet)
        {
            wpn.FireBullet(rootPos, rotations[0], weaponFireMsg);
        }

        else if (weaponFireMsg.weaponId == (byte)WeaponType.Mine)
        {
            wpn.FireMine(wpn.turret.transform.position, rotations[1], weaponFireMsg);
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// When a custom message is taken from the buffer and applied for interpolation, the OnCustomMsgRcvEvent is fired. Note that the rotations
    /// will only be correct if you have the NST set to update rotations on events. If it is set to 'changes only' these rotations values will be zero.
    /// </summary>
    private static void OnCustomMsgApply(NetworkConnection ownerConn, byte[] bytearray, NetworkSyncTransform nst, Vector3 pos, List <GenericX> positions, List <GenericX> rotations)
    {
        Weapon wpn = nst.GetComponent <Weapon>();

        PlayerFireCustomMsg weaponFireMsg = bytearray.DeserializeToStruct <PlayerFireCustomMsg>();

        if (nst == NetworkSyncTransform.lclNST)
        {
            return;
        }

        if (weaponFireMsg.weaponId == (byte)WeaponType.Mine)
        {
            wpn.FireMine(wpn.turret.transform.position, rotations[1], weaponFireMsg);
        }
    }
Exemplo n.º 8
0
        /// <summary>
        /// Add NSTRewindEngine to the NST if Rewind Addon is present, and authority model calls for rewind.
        /// </summary>
        /// <param name="nst"></param>
        public static void AddRewindEngine(this NetworkSyncTransform nst)
        {
            // Try to add/remove the rewind engine by name (to avoid errors if they aren't installed)
            System.Type t = System.Type.GetType("emotitron.NST.NSTRewindEngine");

            if (t != null)
            {
                if (NetLibrarySettings.Single.defaultAuthority == DefaultAuthority.ServerAuthority)
                {
                    if (!nst.GetComponent(t))
                    {
                        nst.gameObject.AddComponent(t);
#if UNITY_EDITOR
                        if (!Application.isPlaying)
                        {
                            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                        }
#endif
                    }
                }
            }
        }