Esempio n. 1
0
            public int CompareTo(object obj)
            {
                int result = -1;

                try
                {
                    WeightVertexNode wvn = obj as WeightVertexNode;
                    if (wvn != null)
                    {
                        result = this.Weight - wvn.Weight;
                        if (result == 0)
                        {
                            return(this.Cell - wvn.Cell);
                        }
                    }
                    else
                    {
                        result = this.Weight - (int)obj;
                    }
                }
                catch (Exception ex)
                {
                    XxdwDebugger.Log(ex.Message);
                }
                return(result);
            }
Esempio n. 2
0
    public void SwitchMap(string mapName)
    {
        XxdwDebugger.Log("Document: SwitchMap() ...");

        if (!this.gpsMaps.ContainsKey(mapName))
        {
            this.currentMapName = mapName;
            this.LoadMapData(mapName);
            this.LoadCsvSheetData(mapName);
            this.LoadDbSheetData("ITEM");
            this.LoadDbSheetData("BUFF");
            this.LoadDbSheetData("TIGER_MACHINE");
            this.LoadDbSheetData("TIGER_ITEM");
            this.LoadDbSheetData("TIGER_BUFF");
            this.LoadDbSheetData("ROLE");
            this.LoadDbSheetData("PLAYER");
            this.LoadDbSheetData("MONSTER");
            this.LoadDbSheetData("BOSS");
        }
        else if (this.currentMapName != mapName)
        {
            this.currentMapName = mapName;
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_SWITCHED, this.gpsMaps[mapName]);
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_INFO_READY, GpsMap.SafeStatus.LS_INFO_DATA, mapName);
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, GpsMap.SafeStatus.LS_PATH_DATA, mapName);
        }
        else
        {
            NotificationCenter.Instance.SendNotification(this, Notification.NOTI_MAP_SWITCHED, this.gpsMaps[mapName]); // 立即触发
            // 从loading初始场景中过来时,NOTI_MAP_INFO_READY已被loading场景处理,ditu场景需初始化
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_INFO_READY, GpsMap.SafeStatus.LS_INFO_DATA, mapName);
        }
    }
Esempio n. 3
0
        public void TraverseAllAdjacents()
        {
            if (this.vertexList.Count == 0)
            {
                XxdwDebugger.Log("No vertex!");
                return;
            }

            foreach (VertexNode vn in this.vertexList)
            {
                string str = "Vertex: (" + (vn.Cell % 144) + "," + (vn.Cell / 144) + ") -> (";

                EdgeNode p = vn.FirstEdge;
                while (p != null)
                {
                    str += (this.vertexList[p.AdjacentVertex].Cell % 144) + "," + this.vertexList[p.AdjacentVertex].Cell / 144 + " -> ";

                    /*Edge edge = p.EdgeLink;
                     * foreach (int e in edge.Spots)
                     * {
                     *  XxdwDebugger.Log("" + e + ",");
                     * }*/
                    p = p.Next;
                }

                XxdwDebugger.Log(str + "\n");
            }
        }
Esempio n. 4
0
    public ITEM FindById(string id)
    {
        XxdwDebugger.Log("hhhhhhhhhh");
        this.cs = Document.Instance.GetSheet("ITEM");
        if (this.cs == null)
        {
            return(null);
        }

        ITEM ss = new ITEM();

        DataRow[] drs = this.cs.Data.Select("NUM='" + id + "'");
        if (drs.Length > 0)
        {
            XxdwDebugger.Log("hhhhhhhhhh");
            DataRow dr = drs[0];
            ss.NUM         = dr["NUM"].ToString();
            ss.NAME        = dr["NAME"].ToString();
            ss.DAZE_TIME   = int.Parse(dr["DAZE_TIME"].ToString());
            ss.POISON_TIME = int.Parse(dr["POISON_TIME"].ToString());
            ss.POISON_DAM  = int.Parse(dr["POISON_DAM"].ToString());
            ss.FREEZE_TIME = int.Parse(dr["FREEZE_TIME"].ToString());
            ss.DAMAGE_PCT  = int.Parse(dr["DAMAGE_PCT"].ToString());
            ss.TELEPORT    = int.Parse(dr["TELEPORT"].ToString());
            ss.TARGET      = int.Parse(dr["TARGET"].ToString());
            ss.USE_REP     = bool.Parse(dr["USE_REP"].ToString());
            ss.CD          = int.Parse(dr["CD"].ToString());
            ss.LV_UP       = int.Parse(dr["LV_UP"].ToString());
            ss.LV_DOWN     = int.Parse(dr["LV_DOWN"].ToString());
        }

        return(ss);
    }
Esempio n. 5
0
    public void CreatBox()
    {
        actor = GameObject.Find("actor").transform;
        //playerPosition = PlayerControl.transform.position; //人物Position
        playerPosition = actor.position;
        GpsMapCell player = Document.Instance.Map.GetCell(playerPosition);

        go = null;

        for (int i = 0; i < 50; i++)
        {
            if (player.Row > 3 && player.Col > 6)
            {
                int x = Random.Range(player.Row - 1, player.Row + 1);           //行
                // int y = Random.Range(player.Col- 5, player.Col - 1) | Random.Range(player.Col + 1, player.Col + 5); ;//列
                int        y   = Random.Range(player.Col - 5, player.Col + 5);; //列
                GpsMapCell gmc = Document.Instance.Map.GetCell(x, y);           //获取对应格子
                if (x != player.Row && y != player.Col)
                {
                    if (gmc.Type == GpsMapCell.EType.EN_CROSS || gmc.Type == GpsMapCell.EType.EN_ROAD)
                    {
                        Vector3 targetPosition = Document.Instance.Map.GetCellPosition(gmc); //将格子转换为世界坐标
                        go = (GameObject)Instantiate(box);
                        go.transform.position = targetPosition;                              //当前的格子转换为世界坐标
                        XxdwDebugger.Log("生成宝箱");
                        break;
                    }
                }
            }
            if (go != null)
            {
                break;
            }
        }
    }
Esempio n. 6
0
 // 在此注册通知
 void Awake()
 {
     XxdwDebugger.Log("BackgroundController -> Awake()");
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MAP_SWITCHED);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MAP_INFO_READY);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MAP_DATA_READY);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_VIEW_PORT_CHANGED);
 }
Esempio n. 7
0
 // 在此注册通知
 void Awake()
 {
     XxdwDebugger.Log("CameraController -> Awake()");
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MAP_SWITCHED);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_BACKGROUND_READY);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_DRAG, Observer.NOTI_PRIORITY_HIGHEST);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_ZOOM_IN);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_ZOOM_OUT);
     NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MOVE_CAMERA);
 }
Esempio n. 8
0
    private void OnNotiBackgroundReady(Notification noti)
    {
        XxdwDebugger.Log("Actor: Notification noti OnBackgroundReady");
        this.range.xMin = this.GetComponent <Renderer>().bounds.size.x / 2 + Document.Instance.Map.MapRange.xMin;
        this.range.xMax = -this.GetComponent <Renderer>().bounds.size.x / 2 + Document.Instance.Map.MapRange.xMax;
        this.range.yMin = this.GetComponent <Renderer>().bounds.size.y / 2 + Document.Instance.Map.MapRange.yMin;
        this.range.yMax = -this.GetComponent <Renderer>().bounds.size.y / 2 + Document.Instance.Map.MapRange.yMax;

        MoveTo(Document.Instance.Map.RolePosition);
    }
Esempio n. 9
0
 public void GetItem(string code)
 {
     if (this.checkitem() == 1)
     {
         this.playeritem = FindItemById(code);
     }
     else if (this.checkitem() == 0)
     {
         XxdwDebugger.Log("item error");
     }
 }
Esempio n. 10
0
 public void ThrowItem()
 {
     if (this.checkitem() == 1)
     {
         XxdwDebugger.Log("throw error");
     }
     else if (this.checkitem() == 0)
     {
         this.playeritem = new ITEM();
     }
 }
Esempio n. 11
0
        private void MoveCamera()
        {
            // 通知视口改变以便加载地图切片
            Vector2 sliceRowCol = this.gpsMap.GetSliceRowCol(this.cameraTarget);

            NotificationCenter.Instance.SendNotification(this, Notification.NOTI_VIEW_PORT_CHANGED,
                                                         this.GetComponent <Camera>().orthographicSize * 2, sliceRowCol);

            this.GetComponent <Camera>().transform.position = this.cameraTarget;
            XxdwDebugger.Log("current position:(" + this.cameraTarget.x + "," + this.cameraTarget.y + ")");
        }
Esempio n. 12
0
        public void SendNotification(Notification aNotification)
        {
            // First make sure that the name of the notification is valid.
            if (aNotification.Name == null || aNotification.Name == "")
            {
                XxdwDebugger.Log("Null name sent to SendNotification."); return;
            }
            // Obtain the notification list, and make sure that it is valid as well
            List <Observer> notifyList = (List <Observer>)notifications[aNotification.Name]; //change from original

            if (notifyList == null)
            {
                XxdwDebugger.Log("NotificationCenter Notify list not found -> " + aNotification.Name); return;
            }

            // Clone list, so there won't be an issue if an observer is added or removed while notifications are being sent
            notifyList = new List <Observer>(notifyList);

            // Create an array to keep track of invalid observers that we need to remove
            List <Observer> observersToRemove = new List <Observer>(); //change from original

            // Itterate through all the objects that have signed up to be notified by this type of notification.
            bool preNotiReturn = false;

            for (int i = notifyList.Count - 1; i >= 0; i--)
            {
                // If the observer isn't valid, then keep track of it so we can remove it later.
                // We can't remove it right now, or it will mess the for loop up.
                if (!notifyList[i].observer)
                {
                    observersToRemove.Add(notifyList[i]);
                }
                else if (!preNotiReturn && (notifyList[i].sender == null || notifyList[i].sender == aNotification.Sender))
                {
                    // If the observer is valid, then send it the notification.  The message that's sent is the name of the notification.
                    if (aNotification.IsInput &&
                        this.inputResponseQueue.Count > 0 &&
                        notifyList[i].observer != this.inputResponseQueue.Peek())
                    {
                        continue;
                    }

                    notifyList[i].observer.SendMessage(aNotification.Name, aNotification, SendMessageOptions.DontRequireReceiver);
                    preNotiReturn = aNotification.Ret;
                }
            }

            // Remove all the invalid observers
            foreach (Observer observer in observersToRemove)
            {
                notifyList.Remove(observer);
            }
        }
Esempio n. 13
0
    private void MoveTo(Cell newCell)
    {
        LimitCellRange(newCell);
        if (newCell == this.cell)
        {
            return;                         // 位置没变
        }
        XxdwDebugger.Log("current cell:(" + this.cell.Row + "," + this.cell.Col + ")");
        this.cell.Row = newCell.Row;
        this.cell.Col = newCell.Col;
        Vector3 targetPosition = Document.Instance.Map.GetCellPosition(this.cell);

        this.transform.position = targetPosition;
        AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MOVE_CAMERA, targetPosition);
    }
Esempio n. 14
0
    public void LoadDbSheetData(string filename)
    {
        TextAsset ta = Resources.Load("db/" + filename, typeof(TextAsset)) as TextAsset;

        if (ta != null)
        {
            XxdwDebugger.Log("Document: LoadDbSheetData() source ok -> " + filename);
            this.csvSheets[filename] = new CsvSheet();
            ((CsvSheet)(this.csvSheets[filename])).LoadData(filename, ta.text);
        }
        else
        {
            XxdwDebugger.Log("Document: LoadDbSheetData() no source ->" + filename);
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_SET_HINT, TypeAndParameter.STR_LOAD_SCENIC_SPOT_RESOURCE_FAILED);
        }
    }
Esempio n. 15
0
        public void LoadData(string mapXmlText, bool force = false)
        {
            if (this.LoadingStatus == SafeStatus.LS_NULL || (force && this.LoadingStatus == SafeStatus.LS_PATH_DATA))
            {
                this.LoadingStatus = SafeStatus.LS_NULL;

                this.mapXmlText = mapXmlText;
                this.dataThread = new Thread(new ThreadStart(DataThreadFunc));
                XxdwDebugger.Log("GpsMap: LoadData() -> start dataThread");
                this.dataThread.Start();
            }
            else
            {
                XxdwDebugger.Log("GpsMap: LoadData() do nothing in status : " + this.LoadingStatus);
            }
        }
Esempio n. 16
0
        private void OnNotiDrag(Notification noti)
        {
            XxdwDebugger.Log("OnNotiDrag in CameraController");
            Vector3 pre = (Vector3)noti.ExtraData;
            Vector3 cur = (Vector3)noti.Data;

            Vector3 preWorld = this.GetComponent <Camera>().ScreenToWorldPoint(pre);
            Vector3 curWorld = this.GetComponent <Camera>().ScreenToWorldPoint(cur);

            Vector3 v = this.GetComponent <Camera>().transform.position;

            v.x -= curWorld.x - preWorld.x;
            v.y -= curWorld.y - preWorld.y;

            this.cameraTarget = LimitRange(v);
            MoveCamera();
        }
Esempio n. 17
0
    void Start()
    {
        //Monstercopy ();
        XxdwDebugger.Log("MainMediator -> Start()");
        //XxdwDebugger.DisplayMessage("StoragePath: " + Util.GetStoragePath());
        //InvokeRepeating ("bulletcopy", 2, 2);
        this.running = true;
        //this.dataThread = new Thread(new ThreadStart(DataThreadFunc));
        //this.dataThread.Start();

        Document.Instance.SwitchMap(TypeAndParameter.instance.DEFAULT_MAP);
        Document.Instance.player     = Document.Instance.FindPlayerById("100");
        Document.Instance.MonsterHP  = Document.Instance.FindMonsterById("200").HP;
        Document.Instance.MonsterATK = Document.Instance.FindMonsterById("200").ATK;
        Document.Instance.MonsterDEF = Document.Instance.FindMonsterById("200").DEF;
        Document.Instance.MonsterHPB = Document.Instance.FindMonsterById("200").HP_BASE;
    }
Esempio n. 18
0
 /////////////////////////////////////////////////////
 public string OpenTigerMachine(string code)
 {
     if (code.Substring(0, 1) == "N" || code.Substring(0, 1) == "E")
     {
         XxdwDebugger.Log("NULL");
         return("NULL");
     }
     else if (code.Substring(0, 1) == "I")
     {
         if (code.Substring(1, 2) == "03" || code.Substring(1, 2) == "05" || code.Substring(1, 2) == "07")
         {
             XxdwDebugger.Log("I01");
             return("I01");
         }
         else if (code.Substring(1, 2) == "04" || code.Substring(1, 2) == "06")
         {
             XxdwDebugger.Log("I02");
             return("I02");
         }
         else
         {
             XxdwDebugger.Log(code);
             return(code);
         }
     }
     else if (code.Substring(0, 1) == "B")
     {
         if (code.Substring(1, 2) == "02" || code.Substring(1, 2) == "04" || code.Substring(1, 2) == "07" || code.Substring(1, 2) == "08" || code.Substring(1, 2) == "09" || code.Substring(1, 2) == "12" || code.Substring(1, 2) == "13" || code.Substring(1, 2) == "14")
         {
             XxdwDebugger.Log("B01");
             return("B01");
         }
         else if (code.Substring(1, 2) == "05" || code.Substring(1, 2) == "06" || code.Substring(1, 2) == "10" || code.Substring(1, 2) == "11" || code.Substring(1, 2) == "15" || code.Substring(1, 2) == "16" || code.Substring(1, 2) == "17")
         {
             XxdwDebugger.Log("B03");
             return("B03");
         }
         else
         {
             XxdwDebugger.Log(code);
             return(code);
         }
     }
     return("NULL");
 }
Esempio n. 19
0
        public ClientSocket(String dstName, int dstPort)
        {
            try
            {
                this.s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                IPAddress[] ia = Dns.GetHostAddresses(dstName);
                //IPAddress ip = IPAddress.Parse(dstName);
                //IPEndPoint ipe = new IPEndPoint(ia[0], dstPort);
                this.s.Connect(ia, dstPort);
            }
            catch (Exception e)
            {
                this.s = null;
                XxdwDebugger.Log(e.ToString());
                throw e;
            }
        }
Esempio n. 20
0
    // 在此注册通知
    void Awake()
    {
        XxdwDebugger.EnableLog     = true;  // 决定是否记录调试信息日志
        Parameters.EngineerVersion = false; // 决定有无工程版的功能(含在屏幕显示调试信息功能)
        XxdwDebugger.Log("MainMediator -> Awake()");

        Application.runInBackground = true;
        AsyncNotification.Instance.PostNotification(this, Notification.NOTI_APP_LOADING);

        // 注册通知消息
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_SWITCH_SCENIC_RESORT);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_MAP_DATA_READY);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_KEY_DOWN);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_TO_OPEN_WINDOW);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_DIALOG_QUIT);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_SET_HINT);
        NotificationCenter.Instance.AddObserver(this, Notification.NOTI_COMM_RESULT);
    }
Esempio n. 21
0
    public void LoadMapData(string mapName)
    {
        TextAsset ta = Resources.Load(mapName + "/" + TypeAndParameter.MAP_DATA_FILE, typeof(TextAsset)) as TextAsset;

        if (ta != null)
        {
            XxdwDebugger.Log("Document: LoadMapData() source ok -> " + mapName);
            this.gpsMaps[mapName] = new GpsMap();
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_SWITCHED, this.gpsMaps[mapName]);

            ((GpsMap)(this.gpsMaps[mapName])).LoadData(ta.text);
        }
        else
        {
            XxdwDebugger.Log("Document: LoadMapData() no source ->" + mapName);
            AsyncNotification.Instance.PostNotification(this, Notification.NOTI_SET_HINT, TypeAndParameter.STR_LOAD_MAP_RESOURCE_FAILED);
        }
    }
Esempio n. 22
0
        public bool AddEdge(int cell1, int cell2, float weight, int[] spots, string identifer, FuncCompareEdgeByRadian compare)
        {
            if (cell1 > cell2)
            {
                int temp = cell1;
                cell1 = cell2;
                cell2 = temp;
            }
            if (FindEdge(cell1, cell2) >= 0)
            {
                XxdwDebugger.Log("The edge already exists.");
                return(false);
            }
            Edge edge = new Edge(cell1, cell2, weight, spots, identifer);

            this.edgeList.Add(edge);

            int index1 = FindVertex(cell1);

            if (index1 < 0)
            {
                index1 = this.vertexList.Count;
                this.vertexList.Add(new VertexNode(cell1));
            }

            int index2 = FindVertex(cell2);

            if (index2 < 0)
            {
                index2 = this.vertexList.Count;
                this.vertexList.Add(new VertexNode(cell2));
            }

            EdgeNode edgeNode1 = new EdgeNode(index2, edge);

            InsertEdgeNode(index1, edgeNode1, compare);
            EdgeNode edgeNode2 = new EdgeNode(index1, edge);

            InsertEdgeNode(index2, edgeNode2, compare);

            return(true);
        }
Esempio n. 23
0
        private void OnNotiMapDataReady(Notification noti)
        {
            XxdwDebugger.Log("BackgroundController -> OnNotiMapDataReady()");
            if (this.gpsMap == null)
            {
                return;
            }

            if (this.gpsMap.IsPathDataReady())
            {
                if (this.triggerPoints == null)
                {
                    this.triggerPoints = new List <GameObject>();
                }
                else if (this.triggerPoints.Count > 0)
                {
                    // 清除原先的触发点
                    foreach (GameObject go in this.triggerPoints)
                    {
                        DestroyObject(go);
                    }
                    this.triggerPoints.Clear();
                }

                // 添加新的触发点
                List <GpsMapMonitorSpot> spots = this.gpsMap.GetMonitorSpots();
                XxdwDebugger.Log("MonitorPoint Number:" + spots.Count);
                if (this.monitorSpotPrefab != null)
                {
                    foreach (GpsMapMonitorSpot gmms in spots)
                    {
                        XxdwDebugger.Log("MonitorPoint At:" + gmms.Cell);
                        Vector3    v  = this.gpsMap.GetCellPosition(gmms.Cell);
                        GameObject go = (GameObject)Instantiate(this.monitorSpotPrefab, v, Quaternion.identity);
                        go.name = Parameters.STR_PREFIX_MONITOR_POINT + gmms.Id;
                        this.triggerPoints.Add(go);
                    }
                }
            }
        }
Esempio n. 24
0
        private void OnNotiMapInfoReady(Notification noti)
        {
            XxdwDebugger.Log("BackgroundController -> OnNotiMapInfoReady()");
            if (this.gpsMap == null)
            {
                return;
            }

            // 销毁原先的背景
            foreach (Transform child in transform)
            {
                DestroyObject(child.gameObject);
            }

            //------------------------------------------------------
            this.sliceLoaded = new bool[this.gpsMap.SliceRowNum, this.gpsMap.SliceColNum];

            // 通知相机地图背景OK,可进行缩放
            //Document.Instance.Map.CheckMapRange(TestBackgroundRange());
            NotificationCenter.Instance.SendNotification(this, Notification.NOTI_BACKGROUND_READY);
            //}
        }
Esempio n. 25
0
        public int CompareTo(object obj)
        {
            int result = -1;

            try
            {
                GpsMapCell gmc = obj as GpsMapCell;
                if (gmc != null)
                {
                    result = this.Index - gmc.Index;
                }
                else
                {
                    result = this.Index - (int)obj;
                }
            }
            catch (Exception ex)
            {
                XxdwDebugger.Log(ex.Message);
            }
            return(result);
        }
Esempio n. 26
0
        public int CompareTo(object obj)
        {
            int result = -1;

            try
            {
                GpsMapMonitorSpot ms = obj as GpsMapMonitorSpot;
                if (ms != null)
                {
                    result = this.Id.CompareTo(ms.Id);
                }
                else
                {
                    result = this.Id.CompareTo(obj);
                }
            }
            catch (Exception ex)
            {
                XxdwDebugger.Log(ex.Message);
            }
            return(result);
        }
Esempio n. 27
0
        public void AddObserver(Component observer, string name, int priority, object sender)
        {
            // If the name isn't good, then throw an error and return.
            if (name == null || name == "")
            {
                XxdwDebugger.Log("Null name specified for notification in AddObserver."); return;
            }
            // If this specific notification doens't exist yet, then create it.
            if (!notifications.ContainsKey(name))
            {
                notifications[name] = new List <Observer>();
            }

            List <Observer> notifyList = (List <Observer>)notifications[name];

            // If the list of observers doesn't already contain the one that's registering, then add it.
            Observer o     = new Observer(observer, priority, sender);
            int      index = notifyList.BinarySearch(o);

            if (index < 0)
            {
                notifyList.Insert(~index, o);
            }
        }
Esempio n. 28
0
        private void Zoom()
        {
            if (this.gpsMap == null)
            {
                return;
            }

            float orthographicSize = this.gpsMap.GetZoomOrthographicSize(this.zoomLevel);

            // this.camera.orthographicSize 为相机视口纵幅的一半
            // this.camera.orthographicSize * this.camera.aspect 为相机视口横幅的一半
            this.cameraRange.xMin = orthographicSize * this.GetComponent <Camera>().aspect + this.gpsMap.MapRange.xMin;
            this.cameraRange.xMax = -orthographicSize *this.GetComponent <Camera>().aspect + this.gpsMap.MapRange.xMax;

            this.cameraRange.yMin = orthographicSize + this.gpsMap.MapRange.yMin;
            this.cameraRange.yMax = -orthographicSize + this.gpsMap.MapRange.yMax;
            XxdwDebugger.Log("cameraRange:(" + this.cameraRange.xMin + "," + this.cameraRange.yMin + "),(" + this.cameraRange.xMax + "," + this.cameraRange.yMax + ")");

            Vector3 v = LimitRange(this.GetComponent <Camera>().transform.position);

            this.GetComponent <Camera>().orthographicSize = orthographicSize;
            this.cameraTarget = v;
            MoveCamera();
        }
Esempio n. 29
0
        // 输出的顶点数和边数相同
        public bool FindCell2CrossPath(GpsMapCell from, GpsMapCell cross,
                                       out List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode, out List <MapPathGraph.Edge> listEdge)
        {
            listNavigateVertexNode = null;
            listEdge = null;

            from = FindNearestCellOf(from, GpsMapCell.EType.EN_ROAD);
            if (from == null)
            {
                XxdwDebugger.Log("Road nearby not found. Strange!");
                return(false);
            }

            int crossVertexIndex = this.pathGraph.FindVertex(cross.Index);

            if (crossVertexIndex < 0)
            {
                XxdwDebugger.Log("Target cross not found. Strange!");
                return(false);
            }
            MapPathGraph.VertexNode vnTo = this.pathGraph.VertexList[crossVertexIndex];

            MapPathGraph.VertexNode vn1, vn2;
            MapPathGraph.Edge       e;
            int spotIndex = FindEdgeOfRoadCell(from.Index, out vn1, out vn2, out e);

            if (spotIndex < 0)
            {
                XxdwDebugger.Log("Cross of road not found. Strange!");
                return(false);
            }
            float w1 = CalcDetailWeight(e.Spots, 0, spotIndex + 1);
            float w2 = CalcDetailWeight(e.Spots, spotIndex, e.Spots.Length);

            int[] spots1 = new int[spotIndex + 1];
            Array.Copy(e.Spots, 0, spots1, 0, spotIndex + 1);
            int[] spots2 = new int[e.Spots.Length - spotIndex];
            Array.Copy(e.Spots, spotIndex, spots2, 0, e.Spots.Length - spotIndex);

            MapPathGraph.Edge e1, e2;
            if (e.Spots[0] == vn1.Cell)
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w1, spots1, "");
                e1.ReverseSpots();
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w2, spots2, "");
            }
            else
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w2, spots2, "");
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w1, spots1, "");
                e2.ReverseSpots();
            }


            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode1 = new List <MapPathGraph.NavigateVertexNode>();
            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode2 = new List <MapPathGraph.NavigateVertexNode>();
            AStarHelper ash = new AStarHelper(this.CalcDistanceWeight);

            ash.Clear();
            float weight1 = this.pathGraph.FindShortestPaths(ash, vn1, vnTo, listNavigateVertexNode1);

            weight1 += weight1 >= 0 ? w1 : Parameters.MAX_EDGE_WEIGHT;
            ash.Clear();
            float weight2 = this.pathGraph.FindShortestPaths(ash, vn2, vnTo, listNavigateVertexNode2);

            weight2 += weight2 >= 0 ? w2 : Parameters.MAX_EDGE_WEIGHT;
            if (listNavigateVertexNode1.Count == 0 && listNavigateVertexNode2.Count == 0)
            {
                return(false);
            }

            listEdge = new List <MapPathGraph.Edge>();
            if (weight1 < weight2)
            {
                listNavigateVertexNode1[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn1, e);
                listNavigateVertexNode = listNavigateVertexNode1;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e1);
            }
            else
            {
                listNavigateVertexNode2[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn2, e);
                listNavigateVertexNode = listNavigateVertexNode2;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e2);
            }

            return(true);
        }
Esempio n. 30
0
        private void DataThreadFunc()
        {
            XxdwDebugger.Log("GpsMap: DataThreadFunc() entering...");
            try
            {
                this.LoadingStatus = SafeStatus.LS_NULL;

                int    pos        = this.mapXmlText.IndexOf("<cells>");
                string strMapData = this.mapXmlText.Substring(0, pos);
                strMapData += "</grid>";
                string strCellAndPathData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<grid>\n";
                strCellAndPathData += this.mapXmlText.Substring(pos);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(new StringReader(strMapData));

                XmlNode node = xmlDoc.SelectSingleNode("/grid/mapName");
                this.name            = (node == null ? "" : node.InnerText.Trim());
                node                 = xmlDoc.SelectSingleNode("/grid/sliceWidth");
                this.sliceWidth      = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/sliceHeight");
                this.sliceHeight     = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/triggerDistance");
                this.triggerDistance = (node == null ? 0 : int.Parse(node.InnerText.Trim()));

                node                  = xmlDoc.SelectSingleNode("/grid/pixelWidth");
                this.pixelWidth       = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/pixelHeight");
                this.pixelHeight      = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/gridCellPixelNum");
                this.gridCellPixelNum = int.Parse(node.InnerText.Trim());
                this.rowNum           = this.pixelHeight / this.gridCellPixelNum;
                this.colNum           = this.pixelWidth / this.gridCellPixelNum;

                this.mapRange = new Rect(-(float)this.PixelWidth / 2 / UNIT_PIXEL_NUM,
                                         -(float)this.pixelHeight / 2 / UNIT_PIXEL_NUM,
                                         (float)this.PixelWidth / UNIT_PIXEL_NUM,
                                         (float)this.PixelHeight / UNIT_PIXEL_NUM);
                XxdwDebugger.Log("rowNum=" + this.rowNum + "colNum=" + this.colNum
                                 + " mapRange:(" + this.mapRange.xMin + "," + this.mapRange.yMin + "),(" + this.mapRange.xMax + "," + this.mapRange.yMax + ")");

                node = xmlDoc.SelectSingleNode("/grid/rolePositionIndex");
                if (node != null)
                {
                    this.rolePositionIndex = int.Parse(node.InnerText.Trim());
                }

                node = xmlDoc.SelectSingleNode("/grid/gridCellLongitudeDiff");
                this.gridCellLongitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellLatitudeDiff");
                this.gridCellLatitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDistance");
                this.gridCellDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDiagonalDistance");
                this.gridCellDiagonalDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLongitude");
                this.zeroLongitude = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLatitude");
                this.zeroLatitude = float.Parse(node.InnerText.Trim());

                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex1");
                this.baseIndex1          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex2");
                this.baseIndex2          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Longitude");
                this.basePoint1Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Latitude");
                this.basePoint1Latitude  = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Longitude");
                this.basePoint2Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Latitude");
                this.basePoint2Latitude  = float.Parse(node.InnerText.Trim());

                this.LoadingStatus |= SafeStatus.LS_INFO_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_INFO_READY");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_INFO_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                xmlDoc.Load(new StringReader(strCellAndPathData));

                // read cells of the grid
                this.grid = new GpsMapCell[this.rowNum, this.colNum];

                string      xmlPathPattern = "/grid/cells/r";
                XmlNodeList rows           = xmlDoc.SelectNodes(xmlPathPattern);
                if (rows != null && rows.Count > 0)
                {
                    foreach (XmlNode xn in rows)
                    {
                        int         i    = int.Parse(xn.Attributes["v"].InnerText);
                        XmlNodeList cols = xn.SelectNodes("./c");
                        foreach (XmlNode cell in cols)
                        {
                            int j = int.Parse(cell.Attributes["v"].InnerText);
                            if (!(i >= 0 && i < this.rowNum && j >= 0 && j < this.colNum))
                            {
                                continue;
                            }

                            node = cell.SelectSingleNode("./t");
                            int type = int.Parse(node.InnerText.Trim());

                            node = cell.SelectSingleNode("./d");
                            string data = (node == null ? "" : node.InnerText.Trim());

                            int entryNumber = 0;
                            if ((type & (int)GpsMapCell.EType.EN_CROSS) != 0)
                            {
                                node = cell.SelectSingleNode("./n");
                                if (node != null)
                                {
                                    entryNumber = int.Parse(node.InnerText.Trim());
                                }
                            }

                            this.grid[i, j] = new GpsMapCell(i * this.colNum + j, i, j, (GpsMapCell.EType)type, data, entryNumber);

                            //---------------------------------------------------------------------------------
                            // 触发点,以触发点编号排序插入
                            if ((type & (int)GpsMapCell.EType.EN_MONITOR_POINT) != 0)
                            {
                                node = cell.SelectSingleNode("./d2");
                                if (node != null)
                                {
                                    string   data2       = node.InnerText.Trim();
                                    string[] ssid_number = data2.Split(new char[] { '_' });
                                    if (ssid_number.Length == 2)
                                    {
                                        GpsMapMonitorSpot ms = new GpsMapMonitorSpot(data2, ssid_number[0], i * this.colNum + j);
                                        int index            = this.listMonitorSpots.BinarySearch(ms);
                                        if (index < 0)
                                        {
                                            this.listMonitorSpots.Insert(~index, ms);
                                        }
                                    }
                                    else
                                    {
                                        XxdwDebugger.LogWarning("Invalid monitor spot data at: " + (i * this.colNum + j));
                                    }
                                }
                                else
                                {
                                    XxdwDebugger.LogWarning("Monitor spot without data at: " + (i * this.colNum + j));
                                }
                            }
                        }
                    }
                }

                this.LoadingStatus |= SafeStatus.LS_CELL_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY cell_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                // read the road data of the grid, which will shape a Data Structure of Graph.
                xmlPathPattern = "/grid/edges/e";
                XmlNodeList edges = xmlDoc.SelectNodes(xmlPathPattern);

                if (edges != null && edges.Count > 0)
                {
                    for (int i = 0; i < edges.Count; i++)
                    {
                        node = edges[i].SelectSingleNode("./cl1");
                        int cell1 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./cl2");
                        int cell2 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./w");
                        float weight = float.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = edges[i].SelectSingleNode("./s");
                        string   strSpots = node.InnerText.Trim();
                        string[] sSpots   = strSpots.Split(new char[] { ',' });
                        if (sSpots.Length == 0)
                        {
                            continue;
                        }
                        int[] spots = new int[sSpots.Length];
                        for (int j = 0; j < sSpots.Length; j++)
                        {
                            spots[j] = int.Parse(sSpots[j]);
                        }

                        this.pathGraph.AddEdge(cell1, cell2, weight, spots, identifier, CompareEdgeByRadian);
                    }
                }

                //--------------------------------------------------------------------------------------
                // read the scenic spot data of the grid
                xmlPathPattern = "/grid/scenic_spot/ss";
                XmlNodeList scenicSpots = xmlDoc.SelectNodes(xmlPathPattern);
                this.listScenicSpots.Clear();
                if (scenicSpots != null)
                {
                    foreach (XmlNode xn in scenicSpots)
                    {
                        node = xn.SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = xn.SelectSingleNode("./en");
                        string cells = node.InnerText.Trim();

                        GpsMapScenicSpot ss = new GpsMapScenicSpot(identifier, cells);
                        int index           = listScenicSpots.BinarySearch(ss);
                        if (index < 0)
                        {
                            this.listScenicSpots.Insert(~index, ss);
                        }
                    }
                }

                //------------------------------------------------------
                this.LoadingStatus |= SafeStatus.LS_PATH_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY path_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);
            }
            catch (System.Exception ex)
            {
                XxdwDebugger.LogError(ex.Message);
                this.LoadingStatus = SafeStatus.LS_NULL;
            }

            //this.pathGraph.TraverseAllAdjacents();
            XxdwDebugger.Log("GpsMap: DataThreadFunc() leaving...");
        }