Пример #1
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        GUILayout.Label("OSMTileProvider", EditorStyles.boldLabel);

        int oldZoomLevel = OSMTileProviderBehaviour.CurrentZoomLevel;

        OSMTileProviderBehaviour.CurrentZoomLevel = EditorGUILayout.IntSlider("ZoomLevel", OSMTileProviderBehaviour.CurrentZoomLevel, 0, 18);
        if (OSMTileProviderBehaviour.CurrentZoomLevel != oldZoomLevel)
        {
            //OSMTileProvider.PrepareZoomGameObjects(oldZoomLevel);
            OSMTileProvider.SetZoomLevelVisible(oldZoomLevel, false);
            OSMTileProvider.SetZoomLevelVisible(OSMTileProviderBehaviour.CurrentZoomLevel, true);
        }


        currentIndexX = EditorGUILayout.IntSlider("X", currentIndexX, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);
        currentIndexY = EditorGUILayout.IntSlider("Y", currentIndexY, 0, OSMTileProvider.TileCountForZoomLevel(zoomlevel) - 1);

        if (GUILayout.Button("Download Tile"))
        {
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }


        if (GUILayout.Button("Download Tile (with Neighbours)"))
        {
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX - 1, currentIndexY + 1, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX + 1, currentIndexY + 1, zoomlevel);

            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY - 1, zoomlevel);
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY + 1, zoomlevel);
        }


        EditorGUILayout.Separator();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);
        if (GUILayout.Button("^", GUILayout.Width(25f)))
        {
            currentIndexY -= 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("<", GUILayout.Width(25f)))
        {
            currentIndexX -= 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.Space(20f);

        if (GUILayout.Button(">", GUILayout.Width(25f)))
        {
            currentIndexX += 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Space(25f);

        if (GUILayout.Button("v", GUILayout.Width(25f)))
        {
            currentIndexY += 1;
            OSMTileProvider.GetOSMTileGameObject(currentIndexX, currentIndexY, zoomlevel);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();


        if (GUILayout.Button("ResetProvider --> Delete Children"))
        {
            osmTileProviderBehaviour.gameObject.DeleteChildren();
            OSMTileProvider.Clear();
        }


        if (GUILayout.Button("Download Bounds"))
        {
            OSMTileProvider.GetOSMTileGameObjectsInBoundingBoxCutting(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);
        }

        //if (GUI.changed)
        //{
        //    EditorUtility.SetDirty(osmTileProviderBehaviour);
        //}

        DrawDefaultInspector();
    }
Пример #2
0
    /// <summary>
    /// Update the GUI
    /// </summary>
    public void OnGUI()
    {
        // Initialize GUI-Utils

        if (!OpenStreetMapsWindow.initializedAttributes)
        {
            myGuiUtils = new MyGUIUtils();
            myGuiUtils.Initialize();

            //mybounds = new MapBounds(50.9517f, 6.9258f, 6.9902f, 50.9202f); // Köln Groß
            //mybounds = new MapBounds(50.23513f, 8.04716f, 8.07123f, 50.22266f); // Michelbach
            mybounds = MapBounds.Cologne;


            tileMap = new OSMTileMap();
            //tileMap.centerLatitude = mybounds.CenterLatitude;
            //tileMap.centerLongitude = mybounds.CenterLongitude;
            tileMap.centerLatitude  = 50.9390d;
            tileMap.centerLongitude = 6.9605d; //7.02744f; //6.9605d;//7.56211f;  Basti 6.93728f;

            tileMap.zoomLevel = 13;


            osmMap    = new OSMMap();
            osmParser = new OSMParser();

            moving       = new List <bool>();
            points       = new List <Vector2>();
            pointsCoords = new List <Vector2>();
            point        = new Vector2();


            zoomIn       = Resources.Load("OSMWindowIcons/zoomIn", typeof(Texture2D)) as Texture2D;
            zoomOut      = Resources.Load("OSMWindowIcons/zoomOut", typeof(Texture2D)) as Texture2D;
            titleTexture = Resources.Load("OSMWindowIcons/title", typeof(Texture2D)) as Texture2D;
            //Texture2D titleTexture = Resources.Load("title_small", typeof(Texture2D)) as Texture2D;
            pointTexture      = Resources.Load("OSMWindowIcons/marker", typeof(Texture2D)) as Texture2D;
            selectionTexture  = Resources.Load("OSMWindowIcons/selection", typeof(Texture2D)) as Texture2D;
            navigationTexture = Resources.Load("OSMWindowIcons/navigation", typeof(Texture2D)) as Texture2D;
            downloadTexture   = Resources.Load("OSMWindowIcons/download", typeof(Texture2D)) as Texture2D;


            //nodePrefab = GameObject.Find("BCNodePrefab");
            //if (nodePrefab == null)
            //{
            //    nodePrefab = new GameObject("BCNodePrefab");
            //    nodePrefab.AddComponent(typeof(Node));
            //    nodePrefab.AddComponent<BCIntersection>();
            //}

            //edgePrefab = GameObject.Find("BCEdgePrefab");
            //if (edgePrefab == null)
            //{
            //    edgePrefab = new GameObject("BCEdgePrefab");
            //    edgePrefab.AddComponent<Edge>();
            //    edgePrefab.AddComponent<MeshFilter>();
            //    edgePrefab.AddComponent<MeshRenderer>();
            //    edgePrefab.AddComponent<MeshCollider>();
            //    edgePrefab.AddComponent<BCRoad>();
            //}

            //entrancePrefab = GameObject.Find("BCEntrancePrefab");
            //if (entrancePrefab == null)
            //{
            //    entrancePrefab = new GameObject("BCEntrancePrefab");
            //    entrancePrefab.AddComponent(typeof(BCEntrance));
            //    entrancePrefab.AddComponent<MeshFilter>();
            //    entrancePrefab.AddComponent<MeshRenderer>();
            //    entrancePrefab.AddComponent<MeshCollider>();

            //}


            OpenStreetMapsWindow.initializedAttributes = true;
        }


        // Calculate Center Tile, Position and Coords
        CaculateValues();
        tileMap.DisplayTileMap();

        //osmParser = new OSMParser();
        _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUILayout.ExpandWidth(true));

        GUILayout.BeginVertical("Box", GUILayout.Width(sidebarWidth), GUILayout.ExpandHeight(true));
        GUILayout.Space(100f);

        // Display Title-Texture
        //DisplayTitle();

        // Display Zoom controls and execute zoomControl-handling
        ZoomControl();

        // Scroll-Control
        ScrollControl();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(300f));
        EditorGUILayout.BeginHorizontal();
        GUIContent[] toolbarOptions = new GUIContent[2];
        toolbarOptions[0] = new GUIContent(navigationTexture, "Navigation Mode");
        toolbarOptions[1] = new GUIContent(selectionTexture, "Selection Mode");
        editorMode        = GUILayout.Toolbar(editorMode, toolbarOptions, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight), GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        HandleNavigationOrSelection();
        GUILayout.EndVertical();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(80f));
        OSMServerSelection();
        GUILayout.EndVertical();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth));

        //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
        //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

        if (GUILayout.Button(downloadTexture, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight * 2), GUILayout.ExpandWidth(true)))
        {
            //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
            //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

            OSMTileProviderBehaviour.mapBounds = mybounds;

            OSMTileProvider.GetOSMTileGameObjectsInBoundingBoxCutting(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);

            //osmParser.BoundsList = new List<MapBounds>();
            //osmParser.BoundsList.Add(this.mybounds);

            //osmParser.StartParsingNoChunks(reloadContentOSM);

            //MapBounds.CenterOffset = GeographicCoordinates.ConvertLonLatToXY(
            //           osmParser.Map.Box.CenterLongitude,
            //           osmParser.Map.Box.CenterLatitude,
            //           GeographicCoordinates.MapCenter);

            //GameObject srtmMap = new GameObject();
            //srtmMap.name = "SRTMMap";


            //mapTile.bounds = this.mybounds;
            //mapTile.latitude = this.mybounds.South;
            //mapTile.longitude = this.mybounds.West;

            //SRTMMapTile mapTile = srtmMap.AddComponent<SRTMMapTile>();
            //mapTile.ParseToCutMap(this.mybounds);
            //mapTile.transform.position = mapTile.verticesMap[0, 0];
            //srtmMap.active = false;

            //GenerateGraph();

            //foreach (Node tmpNode in Editor.FindSceneObjectsOfType(typeof(Node)))
            //{
            //    tmpNode.FirePositionChanged(NodeEvent.Dirty, 1);
            //}

            EditorUtility.ClearProgressBar();
        }
        GUILayout.BeginHorizontal(GUILayout.Width(sidebarWidth));
        //GUILayout.Label(osmParser.FilePath, GUILayout.Width(sidebarWidth - 30f));
        if (GUILayout.Button("...", GUILayout.Width(25f)))
        {
            osmParser.FilePath = EditorUtility.OpenFilePanel("Open OSM-XML-File...", EditorApplication.applicationContentsPath, "");
            this.osmParser.StartParsingNoChunks(true);
            Debug.Log("Done");
            //if(File.Exists(@osmFilename))
            //    osmParser.FilePath = osmFilename;
        }
        GUILayout.EndHorizontal();


        GUILayout.EndVertical();

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
        // TODO: Unity changed its policy on using events  check if this still works without
        //Event.current.Use();
    }