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();
    }
Beispiel #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();
        }
    }
Beispiel #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);
        }
    }
Beispiel #4
0
    // 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>();
        }
    }
 /// <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)
 {
 }
 // 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);
 }
Beispiel #7
0
 static void UnSpawnObject(NetworkIdentity uv)
 {
     DestroyObject(uv, false);
 }
Beispiel #8
0
 internal void AddOwnedObject(NetworkIdentity obj)
 {
     clientOwnedObjects.Add(obj);
 }
Beispiel #9
0
 internal void SetPlayerController(NetworkIdentity player)
 {
     playerController = player;
 }
Beispiel #10
0
 public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver)
 {
     return(Vector3.Distance(identity.transform.position, newObserver.identity.transform.position) <= visRange);
 }
Beispiel #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);
        }
Beispiel #12
0
 public void AddOwnedObject(NetworkIdentity networkIdentity)
 {
     clientOwnedObjects.Add(networkIdentity);
 }
Beispiel #13
0
 public void RemoveFromVisList(NetworkIdentity identity)
 {
     visList.Remove(identity);
 }
Beispiel #14
0
 public void AddToVisList(NetworkIdentity identity)
 {
     visList.Add(identity);
 }
Beispiel #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);
Beispiel #16
0
 internal void HideForConnection(NetworkIdentity identity, INetworkConnection conn)
 {
     conn.Send(new ObjectHideMessage {
         netId = identity.NetId
     });
 }
Beispiel #17
0
 internal PlayerController(GameObject go, short playerControllerId)
 {
     gameObject = go;
     unetView   = go.GetComponent <NetworkIdentity>();
     this.playerControllerId = playerControllerId;
 }
 /// <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)
 {
 }
Beispiel #19
0
 internal void RemovePlayerController()
 {
     m_PlayerController = null;
 }
Beispiel #20
0
 public void RemoveOwnedObject(NetworkIdentity networkIdentity)
 {
     clientOwnedObjects.Remove(networkIdentity);
 }
Beispiel #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);
        }
Beispiel #22
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
            }
            // '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);
                }
            }
        }
Beispiel #23
0
 internal void RemoveOwnedObject(NetworkIdentity obj)
 {
     clientOwnedObjects.Remove(obj);
 }
 public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection newObserver)
 {
     return(identity.gameObject.scene == newObserver.identity.gameObject.scene);
 }
Beispiel #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);
            }
        }
Beispiel #26
0
 public static int CompareNetworkIdentitySiblingPaths(NetworkIdentity left, NetworkIdentity right)
 {
     return(CompareSiblingPaths(SiblingPathFor(left.transform), SiblingPathFor(right.transform)));
 }
Beispiel #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);
                }
            }
        }
 // 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);
 // 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);
 }