Exemplo n.º 1
0
        //private int xcellCount;
        //private float xcellSize;
        //private int ycellCount;
        //private float ycellSize;
        //private float maxCellSize;


        private void OnLineVisiableEvent(LineObject obj, bool state)
        {
            if (lineEvent != null)
            {
                LineInfo info = new LineInfo();
                obj.ToInfo(ref info);
                lineEvent(info, state);
            }
        }
Exemplo n.º 2
0
        public void SetLineData(int id, object data)
        {
            if (objDict == null)
            {
                return;
            }
            LineObject obj = null;

            if (!objDict.TryGetValue(id, out obj))
            {
                return;
            }
            obj.customData = data;
            if (obj.IsDisplay() && lineEvent != null)
            {
                var info = new LineInfo();
                obj.ToInfo(ref info);
                lineEvent(info, true);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化方法
        /// </summary>
        ///   int xcellCount, float xcellSize,
        //int ycellCount, float ycellSize,
        /// <param name="cellCount">格子一排的数量</param>
        /// <param name="cellSize">格子大小</param>
        /// <param name="focusTrans">检查点</param>
        /// <param name="infos">线的数据</param>
        /// <param name="lineEvent">消息委托</param>
        public void Init(
            //int xcellCount, float xcellSize,
            // int ycellCount, float ycellSize,
            int cellCount, float cellSize,
            Transform focusTrans,
            LineInfo[] infos, float CellSwapInDist, float CellSwapOutDist,
            float SwapProcessInterval, float SwapTriggerInterval
            , System.Action <LineInfo, bool> lineEvent)
        {
            this.focusTrans = focusTrans;
            running         = false;

            //this.xcellCount = xcellCount;
            //this.xcellSize = xcellSize;
            //this.ycellCount = ycellCount;
            //this.ycellSize = ycellSize;
            //this.maxCellSize = Mathf.Max(xcellSize, ycellSize);


            //Rect mapRect = new Rect(
            //       (-xcellCount / 2f) * xcellSize,
            //       (-ycellCount / 2f) * ycellSize,
            //       xcellCount * xcellSize, ycellCount * ycellSize
            //   );



            Rect mapRect = new Rect(
                (-cellCount / 2f) * cellSize,
                (-cellCount / 2f) * cellSize,
                cellCount * cellSize, cellCount * cellSize
                );

            this.lineEvent           = lineEvent;
            this.CellSwapInDist      = CellSwapInDist;
            this.CellSwapOutDist     = CellSwapOutDist;
            this.SwapProcessInterval = SwapProcessInterval;
            this.SwapTriggerInterval = SwapTriggerInterval;

            //QtConfig.CellSizeThreshold = cellSize *4;
            QtConfig.CellSizeThreshold   = cellSize + 0.01f;
            QtConfig.CellSwapInDist      = CellSwapInDist;
            QtConfig.CellSwapOutDist     = CellSwapOutDist;
            QtConfig.SwapProcessInterval = SwapProcessInterval;
            QtConfig.SwapTriggerInterval = SwapTriggerInterval;

            quadtree = new QuadTree(mapRect);
            if (objDict == null)
            {
                objDict = new Dictionary <long, LineObject>();
            }
            else
            {
                objDict.Clear();
            }
            for (int i = 0; i < infos.Length; i++)
            {
                var        l   = infos[i];
                LineObject obj = new LineObject(l, this.OnLineVisiableEvent);
                if (!objDict.ContainsKey(l.id))
                {
                    objDict.Add(l.id, obj);
                }
                else
                {
                    Debug.LogError("Line Obj's ID is REPEATED!!! this Shoud Not Happend!! -- id:" + l.id);
                    continue;
                }
                quadtree.Receive(obj);
            }
        }