コード例 #1
0
        void Illuminate()
        {
            //remove self from all levelNodes.
            foreach (TileNode t in gridElement.tilemapManager.allTileNodes)
            {
                if (t.lightsOnMe.Contains(this))
                {
                    t.lightsOnMe.Remove(this);
                    t.SetBrightness();
                }
            }
            //dont do anything if we are turned off.
            if (!lightOn)
            {
                return;
            }

            var c = new Vector2Int[0];

            switch (gridLightType)
            {
            case GridLightType.Circle:
                c = GridUtility.Circle(position, lightRange);
                break;

            case GridLightType.Arc:
                c = GridUtility.Arc(position, agent.facingDirection, lightRange, 45);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            foreach (Vector2Int p in c)
            {
                TileNode tn = gridElement.tilemapManager.GetTileNode(p);
                if (tn != null)
                {
                    if (gridElement.tilemapManager.LineOfSight(tn.position, position))
                    {
                        if (!tn.lightsOnMe.Contains(this))
                        {
                            tn.lightsOnMe.Add(this);
                            tn.SetBrightness();
                        }
                    }
                }
            }

            gridElement.tilemapManager.UpdateBrightnessDisplay();
        }
コード例 #2
0
        public void CheckSight()
        {
            placesISee.Clear();
            agentsISee.Clear();
            itemsISee.Clear();
            if (!canSee)
            {
                return;
            }

            var c = GridUtility.Arc(_gridElement.position, _agent.facingDirection, viewRange, 45);

            foreach (var p in c)
            {
                var tn = _gridElement.tilemapManager.GetTileNode(p);
                if (tn != null)
                {
                    if (tn.brightness > visibilityThreshold.Value)
                    {
                        if (_gridElement.tilemapManager.LineOfSight(tn.position, _gridElement.position))
                        {
                            foreach (GridElement item in tn.itemsHere)
                            {
                                placesISee.Add(tn.position);
                                if (!itemsISee.Contains(item))
                                {
                                    itemsISee.Add(item);
                                    if (item.GetComponent <Agent>() != null)
                                    {
                                        agentsISee.Add(item.GetComponent <Agent>());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }