コード例 #1
0
    void Start()
    {
        // Add Sprite
        if (!spriteRenderer)
        {
            spriteRenderer = this.gameObject.AddComponent <SpriteRenderer>();
        }

        networkIdentity = gameObject.GetComponent <Mirror.NetworkIdentity>();
        if (!networkIdentity)
        {
            networkIdentity = gameObject.AddComponent <Mirror.NetworkIdentity>();
        }

        if (sound.clip)
        {
            if (!audioSource)
            {
                audioSource = this.gameObject.AddComponent <AudioSource>();
            }

            audioSource.spatialize   = true;
            audioSource.spatialBlend = .5f;
            sound.SetSource(audioSource);
            sound.PlaySound();
        }

        ComputeDetonationTimer();
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        networkIdentity = gameObject.GetComponent <Mirror.NetworkIdentity>();
        if (!networkIdentity)
        {
            networkIdentity = gameObject.AddComponent <Mirror.NetworkIdentity>();
        }

        if (sound.clip)
        {
            if (!audioSource)
            {
                audioSource = this.gameObject.AddComponent <AudioSource>();
            }

            audioSource.spatialize   = true;
            audioSource.spatialBlend = .5f;
            sound.SetSource(audioSource);
            sound.PlaySound();
        }

        // Schedule first periodic update
        if (aoeFrequency > 0)
        {
            nextPeriodicUpdate = Time.time + aoeFrequency;
        }

        expirationTime = Time.time + aoeDuration;
        if (isServer)
        {
            AreaOfEffectAction();
        }
    }
コード例 #3
0
    void Start()
    {
        playerCanvas = (Canvas)gameObject.GetComponentInChildren(typeof(Canvas), true);

        networkIdentity = gameObject.GetComponent <Mirror.NetworkIdentity>();
        if (!networkIdentity)
        {
            networkIdentity = gameObject.AddComponent <Mirror.NetworkIdentity>();
        }

        playerCursor = GetComponentInChildren <CursorScript>();

        FillDeck();
        FillHand();

        if (!isLocalPlayer)
        {
            // Disable all non-local player canvas UI elements
            playerCanvas.gameObject.SetActive(false);
            playerCursor.gameObject.SetActive(false);
        }
    }
コード例 #4
0
ファイル: Unit.cs プロジェクト: CaptainStack/LordsOfTheClash
    // Use for initialization of all units (client and server)
    void Start()
    {
        // Add RigidBody2D
        if (!unitRigidBody)
        {
            unitRigidBody                = this.gameObject.AddComponent <Rigidbody2D>();
            unitRigidBody.drag           = 5f;
            unitRigidBody.gravityScale   = 0.0f;
            unitRigidBody.freezeRotation = true;
        }

        // Add Sprite
        if (!spriteRenderer)
        {
            spriteRenderer = this.gameObject.AddComponent <SpriteRenderer>();
        }

        // Add Network Identity
        networkIdentity = gameObject.GetComponent <Mirror.NetworkIdentity>();
        if (!networkIdentity)
        {
            networkIdentity = gameObject.AddComponent <Mirror.NetworkIdentity>();
        }
    }
コード例 #5
0
 /// <summary>Called on the server when a new networked object is spawned.</summary>
 // (useful for 'only rebuild if changed' interest management algorithms)
 public virtual void OnSpawned(NetworkIdentity identity)
 {
 }
コード例 #6
0
 // helper function to get vis range for a given object, or default.
 int GetVisRange(NetworkIdentity identity)
 {
     return(identity.TryGetComponent(out DistanceInterestManagementCustomRange custom) ? custom.visRange : visRange);
 }
コード例 #7
0
 static void UnSpawnObject(NetworkIdentity uv)
 {
     DestroyObject(uv, false);
 }
コード例 #8
0
ファイル: NetworkConnection.cs プロジェクト: LXShades/Mirror
 internal void AddOwnedObject(NetworkIdentity obj)
 {
     clientOwnedObjects.Add(obj);
 }
コード例 #9
0
ファイル: NetworkConnection.cs プロジェクト: bejita968/Mirror
 internal void SetPlayerController(NetworkIdentity player)
 {
     playerController = player;
 }
コード例 #10
0
 public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver)
 {
     return(Vector3.Distance(identity.transform.position, newObserver.identity.transform.position) <= visRange);
 }
コード例 #11
0
        // helper function to get vis range for a given object, or default.
        int GetVisRange(NetworkIdentity identity)
        {
            DistanceInterestManagementCustomRange custom = identity.GetComponent <DistanceInterestManagementCustomRange>();

            return(custom != null ? custom.visRange : visRange);
        }
コード例 #12
0
ファイル: NetworkConnection.cs プロジェクト: RaveKev/MirrorNG
 public void AddOwnedObject(NetworkIdentity networkIdentity)
 {
     clientOwnedObjects.Add(networkIdentity);
 }
コード例 #13
0
ファイル: NetworkConnection.cs プロジェクト: RaveKev/MirrorNG
 public void RemoveFromVisList(NetworkIdentity identity)
 {
     visList.Remove(identity);
 }
コード例 #14
0
ファイル: NetworkConnection.cs プロジェクト: RaveKev/MirrorNG
 public void AddToVisList(NetworkIdentity identity)
 {
     visList.Add(identity);
 }
コード例 #15
0
 static ArraySegment <byte> CreateSpawnMessagePayload(bool isOwner, NetworkIdentity identity, PooledNetworkWriter ownerWriter, PooledNetworkWriter observersWriter)
 {
     // Only call OnSerializeAllSafely if there are NetworkBehaviours
     if (identity.NetworkBehaviours.Length == 0)
     {
         return(default);
コード例 #16
0
 internal void HideForConnection(NetworkIdentity identity, INetworkConnection conn)
 {
     conn.Send(new ObjectHideMessage {
         netId = identity.NetId
     });
 }
コード例 #17
0
 internal PlayerController(GameObject go, short playerControllerId)
 {
     gameObject = go;
     unetView   = go.GetComponent <NetworkIdentity>();
     this.playerControllerId = playerControllerId;
 }
コード例 #18
0
 /// <summary>Called on the server when a networked object is destroyed.</summary>
 // (useful for 'only rebuild if changed' interest management algorithms)
 public virtual void OnDestroyed(NetworkIdentity identity)
 {
 }
コード例 #19
0
 internal void RemovePlayerController()
 {
     m_PlayerController = null;
 }
コード例 #20
0
ファイル: NetworkConnection.cs プロジェクト: RaveKev/MirrorNG
 public void RemoveOwnedObject(NetworkIdentity networkIdentity)
 {
     clientOwnedObjects.Remove(networkIdentity);
 }
コード例 #21
0
        /// <summary>
        /// Called when a new player enters, and when scene changes occur
        /// </summary>
        /// <param name="observers">List of players to be updated.  Modify this set with all the players that can see this object</param>
        /// <param name="initial">True if this is the first time the method is called for this object</param>
        /// <returns>True if this component calculated the list of observers</returns>
        public override bool OnRebuildObservers(HashSet <NetworkConnection> observers, bool initial)
        {
            // if force hidden then return without adding any observers.
            if (forceHidden)
            {
                // always return true when overwriting OnRebuildObservers so that
                // Mirror knows not to use the built in rebuild method.
                return(true);
            }

            // find players within range
            switch (checkMethod)
            {
            case CheckMethod.Physics3D:
            {
                // cast without allocating GC for maximum performance
                int hitCount = Physics.OverlapSphereNonAlloc(transform.position, visRange, hitsBuffer3D, castLayers);
                if (hitCount == hitsBuffer3D.Length)
                {
                    Debug.LogWarning("NetworkProximityChecker's OverlapSphere test for " + name + " has filled the whole buffer(" + hitsBuffer3D.Length + "). Some results might have been omitted. Consider increasing buffer size.");
                }

                for (int i = 0; i < hitCount; i++)
                {
                    Collider hit = hitsBuffer3D[i];
                    // collider might be on pelvis, often the NetworkIdentity is in a parent
                    // (looks in the object itself and then parents)
                    NetworkIdentity identity = hit.GetComponentInParent <NetworkIdentity>();
                    // (if an object has a connectionToClient, it is a player)
                    if (identity != null && identity.connectionToClient != null)
                    {
                        observers.Add(identity.connectionToClient);
                    }
                }
                break;
            }

            case CheckMethod.Physics2D:
            {
                // cast without allocating GC for maximum performance
                int hitCount = Physics2D.OverlapCircleNonAlloc(transform.position, visRange, hitsBuffer2D, castLayers);
                if (hitCount == hitsBuffer2D.Length)
                {
                    Debug.LogWarning("NetworkProximityChecker's OverlapCircle test for " + name + " has filled the whole buffer(" + hitsBuffer2D.Length + "). Some results might have been omitted. Consider increasing buffer size.");
                }

                for (int i = 0; i < hitCount; i++)
                {
                    Collider2D hit = hitsBuffer2D[i];
                    // collider might be on pelvis, often the NetworkIdentity is in a parent
                    // (looks in the object itself and then parents)
                    NetworkIdentity identity = hit.GetComponentInParent <NetworkIdentity>();
                    // (if an object has a connectionToClient, it is a player)
                    if (identity != null && identity.connectionToClient != null)
                    {
                        observers.Add(identity.connectionToClient);
                    }
                }
                break;
            }
            }

            // always return true when overwriting OnRebuildObservers so that
            // Mirror knows not to use the built in rebuild method.
            return(true);
        }
コード例 #22
0
ファイル: NetworkServer.cs プロジェクト: fuqunaga/Mirror
        internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnection conn)
        {
            if (identity.serverOnly)
            {
                return;
            }

            if (LogFilter.Debug)
            {
                Debug.Log("Server SendSpawnMessage: name=" + identity.name + " sceneId=" + identity.sceneId.ToString("X") + " netid=" + identity.netId);                  // for easier debugging
            }
            // 'identity' is a prefab that should be spawned
            if (identity.sceneId == 0)
            {
                SpawnPrefabMessage msg = new SpawnPrefabMessage
                {
                    netId    = identity.netId,
                    owner    = conn?.playerController == identity,
                    assetId  = identity.assetId,
                    position = identity.transform.position,
                    rotation = identity.transform.rotation,
                    scale    = identity.transform.localScale,

                    // serialize all components with initialState = true
                    payload = identity.OnSerializeAllSafely(true)
                };

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send(msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(identity, msg);
                }
            }
            // 'identity' is a scene object that should be spawned again
            else
            {
                SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage
                {
                    netId    = identity.netId,
                    owner    = conn?.playerController == identity,
                    sceneId  = identity.sceneId,
                    position = identity.transform.position,
                    rotation = identity.transform.rotation,
                    scale    = identity.transform.localScale,

                    // include synch data
                    payload = identity.OnSerializeAllSafely(true)
                };

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send(msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(identity, msg);
                }
            }
        }
コード例 #23
0
 internal void RemoveOwnedObject(NetworkIdentity obj)
 {
     clientOwnedObjects.Remove(obj);
 }
コード例 #24
0
 public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver)
 {
     return(identity.gameObject.scene == newObserver.identity.gameObject.scene);
 }
コード例 #25
0
        internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnection conn)
        {
            if (identity.serverOnly)
            {
                return;
            }

            if (LogFilter.Debug)
            {
                Debug.Log("Server SendSpawnMessage: name=" + identity.name + " sceneId=" + identity.sceneId.ToString("X") + " netid=" + identity.netId);                  // for easier debugging
            }
            // serialize all components with initialState = true
            // (can be null if has none)
            // convert to ArraySegment to avoid reader allocations
            // (need to handle null case too)
            ArraySegment <byte> segment = identity.OnSerializeAllSafely(true, out NetworkWriter serialized) ? serialized.ToArraySegment() : default;

            // 'identity' is a prefab that should be spawned
            if (identity.sceneId == 0)
            {
                SpawnPrefabMessage msg = new SpawnPrefabMessage
                {
                    netId   = identity.netId,
                    owner   = conn?.playerController == identity,
                    assetId = identity.assetId,
                    // use local values for VR support
                    position = identity.transform.localPosition,
                    rotation = identity.transform.localRotation,
                    scale    = identity.transform.localScale,
                    payload  = segment
                };

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send(msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(identity, msg);
                }
            }
            // 'identity' is a scene object that should be spawned again
            else
            {
                SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage
                {
                    netId   = identity.netId,
                    owner   = conn?.playerController == identity,
                    sceneId = identity.sceneId,
                    // use local values for VR support
                    position = identity.transform.localPosition,
                    rotation = identity.transform.localRotation,
                    scale    = identity.transform.localScale,
                    payload  = segment
                };

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send(msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(identity, msg);
                }
            }

            if (serialized != null)
            {
                NetworkWriterPool.Recycle(serialized);
            }
        }
コード例 #26
0
 public static int CompareNetworkIdentitySiblingPaths(NetworkIdentity left, NetworkIdentity right)
 {
     return(CompareSiblingPaths(SiblingPathFor(left.transform), SiblingPathFor(right.transform)));
 }
コード例 #27
0
        internal static void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn)
        {
            if (uv.serverOnly)
            {
                return;
            }

            if (LogFilter.logDebug)
            {
                Debug.Log("Server SendSpawnMessage: name=" + uv.name + " sceneId=" + uv.sceneId + " netid=" + uv.netId);
            }                                                                                                                                    // for easier debugging

            // 'uv' is a prefab that should be spawned
            if (uv.sceneId.IsEmpty())
            {
                SpawnPrefabMessage msg = new SpawnPrefabMessage();
                msg.netId    = uv.netId;
                msg.assetId  = uv.assetId;
                msg.position = uv.transform.position;
                msg.rotation = uv.transform.rotation;

                // serialize all components with initialState = true
                NetworkWriter writer = new NetworkWriter();
                uv.OnSerializeAllSafely(writer, true);
                msg.payload = writer.ToArray();

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send((short)MsgType.SpawnPrefab, msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(uv.gameObject, (short)MsgType.SpawnPrefab, msg);
                }
            }
            // 'uv' is a scene object that should be spawned again
            else
            {
                SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage();
                msg.netId    = uv.netId;
                msg.sceneId  = uv.sceneId;
                msg.position = uv.transform.position;

                // include synch data
                NetworkWriter writer = new NetworkWriter();
                uv.OnSerializeAllSafely(writer, true);
                msg.payload = writer.ToArray();

                // conn is != null when spawning it for a client
                if (conn != null)
                {
                    conn.Send((short)MsgType.SpawnSceneObject, msg);
                }
                // conn is == null when spawning it for the local player
                else
                {
                    SendToReady(uv.gameObject, (short)MsgType.SpawnSceneObject, msg);
                }
            }
        }
コード例 #28
0
 // rebuild observers for the given NetworkIdentity.
 // Server will automatically spawn/despawn added/removed ones.
 //   newObservers: cached hashset to put the result into
 //   initialize: true if being rebuilt for the first time
 //
 // IMPORTANT:
 // => global rebuild would be more simple, BUT
 // => local rebuild is way faster for spawn/despawn because we can
 //    simply rebuild a select NetworkIdentity only
 // => having both .observers and .observing is necessary for local
 //    rebuilds
 //
 // in other words, this is the perfect solution even though it's not
 // completely simple (due to .observers & .observing).
 //
 // Mirror maintains .observing automatically in the background. best of
 // both worlds without any worrying now!
 public abstract void OnRebuildObservers(NetworkIdentity identity, HashSet <NetworkConnection> newObservers, bool initialize);
コード例 #29
0
 // Callback used by the visibility system to determine if an observer
 // (player) can see the NetworkIdentity. If this function returns true,
 // the network connection will be added as an observer.
 //   conn: Network connection of a player.
 //   returns True if the player can see this object.
 public abstract bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver);
 public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver)
 {
     return(identity.GetComponent <NetworkMatch>().matchId ==
            newObserver.identity.GetComponent <NetworkMatch>().matchId);
 }