Example #1
0
        public void FillMapData(bool[] _mapData)
        {
            var minX = mNowFowPos.x - mViewRange;
            var maxX = mNowFowPos.x + mViewRange;
            var minY = mNowFowPos.y - mViewRange;
            var maxY = mNowFowPos.y + mViewRange;

            for (var x = minX; x <= maxX; x++)
            {
                for (var y = minY; y <= maxY; y++)
                {
                    //超出边界范围,不进行运算
                    if (x < 1 || y < 1 || x >= CEFowFacade.instance.fowMapWidth - 1 || y >= CEFowFacade.instance.fowMapHeight - 1)
                    {
                        continue;
                    }

                    //在圆形区域外,不进行运算
                    var disSquare = (x - mNowFowPos.x) * (x - mNowFowPos.x) + (y - mNowFowPos.y) * (y - mNowFowPos.y);
                    if (disSquare > mViewRangeSquare)
                    {
                        continue;
                    }

                    CEFowFacade.SetMap(_mapData, x, y);
                    CEFowFacade.SetMap(CEFowFacade.instance.data.exploreMapData, x, y);
                }
            }
        }
Example #2
0
        public void Initialize(int _viewRange, Vector3 _worldPos)
        {
            mViewRange       = _viewRange;
            mViewRangeSquare = mViewRange * mViewRange;
            mNowFowPos       = CEFowFacade.GetFowPos(_worldPos);

            CEFowFacade.instance.staticExplorerList.Add(this);
            CEFowFacade.instance.painter.MarkStaticViewDataChange();
        }
Example #3
0
        public void Update(Vector3 _nowWorldPos)
        {
            var pos = CEFowFacade.GetFowPos(_nowWorldPos);

            if (pos != mNowFowPos)
            {
                mNowFowPos = pos;
                RunLogic();
            }
        }
Example #4
0
        public void Initialize(int _viewRange, Vector3 _worldPos)
        {
            mViewRange          = _viewRange;
            mViewRangeSquare    = mViewRange * mViewRange;
            mNowFowPos          = CEFowFacade.GetFowPos(_worldPos);
            selfViewMapDataList = new List <Vector2Int>();

            CEFowFacade.instance.dynamicExplorerList.Add(this);

            RunLogic();
        }
Example #5
0
        /// <summary>
        /// 更新FogData
        /// 通知Painter重绘RT
        /// </summary>
        private void RunLogic()
        {
            selfViewMapDataList.Clear();
            var minX          = mNowFowPos.x - mViewRange;
            var maxX          = mNowFowPos.x + mViewRange;
            var minY          = mNowFowPos.y - mViewRange;
            var maxY          = mNowFowPos.y + mViewRange;
            var isNeedRepaint = false;

            for (var x = minX; x <= maxX; x++)
            {
                for (var y = minY; y <= maxY; y++)
                {
                    //超出边界范围,不进行运算
                    if (x < 1 || y < 1 || x >= CEFowFacade.instance.fowMapWidth - 1 || y >= CEFowFacade.instance.fowMapHeight - 1)
                    {
                        continue;
                    }

                    //在圆形区域外,不进行运算
                    float disSquare = (x - mNowFowPos.x + 0.5f) * (x - mNowFowPos.x + 0.5f) + (y - mNowFowPos.y + 0.5f) * (y - mNowFowPos.y + 0.5f);
                    if (disSquare > mViewRangeSquare)
                    {
                        continue;
                    }

                    isNeedRepaint = true;
                    selfViewMapDataList.Add(new Vector2Int(x, y));
                    CEFowFacade.SetMap(CEFowFacade.instance.data.exploreMapData, x, y);
                }
            }

            if (!isNeedRepaint)
            {
                return;
            }
            CEFowFacade.instance.painter.MarkDynamicViewDataChange();
            CEFowFacade.instance.painter.MarkExploreDataChange();
        }
Example #6
0
        private void RecalculateColorBuffer()
        {
            var tempViewMapData = (bool[])mCacheStaticViewMapData.Clone();

            CEFowFacade.instance.dynamicExplorerList.ForEach(explorer => { explorer.selfViewMapDataList.ForEach(pos => { CEFowFacade.SetMap(tempViewMapData, pos.x, pos.y); }); });
            CEFowFacade.instance.data.viewMapData = tempViewMapData;

            for (var x = 0; x < CEFowFacade.instance.fowMapWidth; x++)
            {
                for (var y = 0; y < CEFowFacade.instance.fowMapHeight; y++)
                {
                    var color = new Color
                    {
                        r = CEFowFacade.GetMap(CEFowFacade.instance.data.exploreMapData, x, y) ? 1 : 0,
                        g = CEFowFacade.GetMap(tempViewMapData, x, y) ? 1 : 0,
                        b = 0,
                    };

                    mColorBuffer[x + y * CEFowFacade.instance.fowMapWidth] = color;
                }
            }
        }
Example #7
0
 // Update is called once per frame
 private void Update()
 {
     mChild.SetActive(CEFowFacade.IsWorldPosInView(mTrans.position));
 }