Example #1
0
        private void UpdateObservers()
        {
            if (lastObserverCheck + CheckObserversInterval < Time.time)
            {
                // Could probably be more efficient, it's currently checking every connection in game.
                foreach (NetworkConnectionToClient connection in NetworkServer.connections.Values)
                {
                    if (connection != null && connection.identity != null)
                    {
                        var creature = connection.identity.GetComponent <Entity>();
                        if (creature == null)
                        {
                            continue;
                        }
                        if (creature.CanSee(gameObject))
                        {
                            if (attachedContainer.Observers.Contains(creature))
                            {
                                continue;
                            }
                            attachedContainer.AddObserver(creature);
                        }
                        else
                        {
                            attachedContainer.RemoveObserver(creature);
                        }
                    }
                }

                lastObserverCheck = Time.time;
            }
        }
Example #2
0
        public void Update()
        {
            if (lastObserverCheck + CheckObserversInterval < Time.time)
            {
                foreach (NetworkConnectionToClient connection in NetworkServer.connections.Values)
                {
                    if (connection != null && connection.identity != null)
                    {
                        var creature = connection.identity.GetComponent <Entity>();
                        if (creature == null)
                        {
                            continue;
                        }
                        if (creature.CanSee(gameObject))
                        {
                            if (currentObservers.Contains(creature))
                            {
                                continue;
                            }

                            if (AttachedContainer.AddObserver(creature))
                            {
                                currentObservers.Add(creature);
                            }
                        }
                        else if (currentObservers.Remove(creature))
                        {
                            AttachedContainer.RemoveObserver(creature);
                        }
                    }
                }

                lastObserverCheck = Time.time;
            }
        }