Exemple #1
0
    // note: this hides base.update, which is fine
    void Update()
    {
        if (!NetworkServer.active)
        {
            return;
        }

        // has connection to client? then we are a possible observer (player)
        // (monsters don't observer each other)
        if (connectionToClient != null)
        {
            // calculate current grid position
            Vector2Int current = ProjectToGrid(transform.position);

            // changed since last time?
            if (current != previous)
            {
                // update position in grid
                grid.Remove(previous, connectionToClient);
                grid.Add(current, connectionToClient);

                // save as previous
                previous = current;
            }
        }

        // possibly rebuild AFTER updating position in grid, so it's always up
        // to date. otherwise player might have moved and not be in current grid
        // hence OnRebuild wouldn't even find itself there
        if (Time.time - m_VisUpdateTime > visUpdateInterval)
        {
            netIdentity.RebuildObservers(false);
            m_VisUpdateTime = Time.time;
        }
    }
Exemple #2
0
 void Update()
 {
     if (!NetworkServer.active)
     {
         return;
     }
     if (connectionToClient != null)
     {
         Vector2Int current = ProjectToGrid(transform.position);
         if (current != previous)
         {
             grid.Remove(previous, connectionToClient);
             grid.Add(current, connectionToClient);
             previous = current;
         }
     }
     if (Time.time - m_VisUpdateTime > visUpdateInterval)
     {
         netIdentity.RebuildObservers(false);
         m_VisUpdateTime = Time.time;
     }
 }
Exemple #3
0
        public void AddAndGetNeighbours()
        {
            // add two at (0, 0)
            grid.Add(Vector2Int.zero, 1);
            grid.Add(Vector2Int.zero, 2);
            HashSet <int> result = new HashSet <int>();

            grid.GetWithNeighbours(Vector2Int.zero, result);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result.Contains(1), Is.True);
            Assert.That(result.Contains(2), Is.True);

            // add a neighbour at (1, 1)
            grid.Add(new Vector2Int(1, 1), 3);
            grid.GetWithNeighbours(Vector2Int.zero, result);
            Assert.That(result.Count, Is.EqualTo(3));
            Assert.That(result.Contains(1), Is.True);
            Assert.That(result.Contains(2), Is.True);
            Assert.That(result.Contains(3), Is.True);
        }