コード例 #1
0
        /* ----------------------------------
         * ON GUI: Used for drawing the window every unity event
         * ----------------------------------*/
        public override void Draw(int aID)
        {
            if (mapScene == null)
            {
                GUILayout.Label("There is no selected element. Please select or create one.");
                return;
            }


            if (placeSearcher == null)
            {
                Init();
            }

            placeSearcher.LayoutBegin();

            // Location control
            mapScene.LatLon = EditorGUILayout.Vector2Field("Location", mapScene.LatLon.ToVector2()).ToVector2d();
            if (mapScene.LatLon != map.Center)
            {
                map.Center = mapScene.LatLon;
            }

            EditorGUILayout.BeginHorizontal();
            // Map Elements
            mapElementReorderableList.list = mapScene.Elements;
            var elementsWidth = 150;

            mapElementReorderableList.elementHeight = mapElementReorderableList.list.Count == 0 ? 20 : 70;
            EditorGUILayout.BeginVertical(GUILayout.Width(elementsWidth), GUILayout.ExpandHeight(true));
            mapElementReorderableList.DoLayoutList();
            EditorGUILayout.EndVertical();

            var mapRect = EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            // Map drawing
            if (map.DrawMap(mapRect) && movingReference != null)
            {
                this.positionManagers[movingReference].Repositionate(map, mapRect);
                movingReference = null;
            }

            if (movingReference != null && Event.current.type == EventType.Repaint)
            {
                this.positionManagers[movingReference].Repositionate(map, mapRect);
            }

            mapScene.LatLon = map.Center;
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            if (placeSearcher.LayoutEnd())
            {
                mapScene.LatLon = placeSearcher.LatLon;
                Repaint();
            }
        }
コード例 #2
0
            void OnGUI()
            {
                if (guiMap == null)
                {
                    guiMap = new GUIMap();
                }


                debugWindowRect = GUI.Window(12341234, debugWindowRect, (id) =>
                {
                    var mapRect = new Rect(2, 18, 196, 180);
                    using (new GUILayout.AreaScope(mapRect))
                    {
                        guiMap.Center = GeoExtension.Instance.Location;
                        guiMap.Zoom   = 17;
                        guiMap.DrawMap(new Rect(0, 0, 196, 180));
                        // Calculate the player pixel relative to the map
                        var playerMeters        = MapzenGo.Helpers.GM.LatLonToMeters(GeoExtension.Instance.Location);
                        var playerPixel         = MapzenGo.Helpers.GM.MetersToPixels(playerMeters, guiMap.Zoom);
                        var playerPixelRelative = playerPixel + guiMap.PATR;

                        // Do the point handling
                        var pointControl = GUIUtility.GetControlID("PlayerPosition".GetHashCode(), FocusType.Passive);
                        EditorGUI.BeginChangeCheck();
                        var newPlayerPixel = HandleUtil.HandlePointMovement(pointControl, playerPixelRelative.ToVector2(), 10,
                                                                            (point, isOver, isActive) => HandleUtil.DrawPoint(point, 4, Color.cyan,
                                                                                                                              Color.black), MouseCursor.MoveArrow);
                        if (EditorGUI.EndChangeCheck())
                        {
                            // If changed, restore the point to the geochar
                            playerPixel  = newPlayerPixel.ToVector2d() - guiMap.PATR;
                            playerMeters = MapzenGo.Helpers.GM.PixelsToMeters(playerPixel, guiMap.Zoom);
                            GeoExtension.Instance.Location = MapzenGo.Helpers.GM.MetersToLatLon(playerMeters);
                        }

                        guiMap.ProcessEvents(mapRect);
                    }
                    GUI.DragWindow();
                },
                                             "DebugWindow");
            }
コード例 #3
0
 protected override void BeforeDrawElements(Rect rect)
 {
     ScreenRect = rect;
     guiMap.DrawMap(rect);
 }
コード例 #4
0
        void OnGUI()
        {
            var paintSimbol = disconnectedSimbol;

            switch (Input.location.status)
            {
            default:
            case LocationServiceStatus.Failed:
            case LocationServiceStatus.Stopped:
                paintSimbol = disconnectedSimbol;
                break;

            case LocationServiceStatus.Initializing:
                paintSimbol = connectingSimbol;
                break;

            case LocationServiceStatus.Running:
                var connecting = ((time > blinkingTime / 2f) ? connectedSimbol : connectingSimbol);
                paintSimbol = IsLocationValid() ? connectedSimbol : connecting;
                break;
            }

            /*if (Event.current.type == EventType.Repaint)
             *  GUI.DrawTexture(new Rect(Screen.width - iconWidth - 5, 5, iconWidth, iconHeight), paintSimbol);*/

            if (guiMap == null)
            {
                guiMap = new GUIMap();
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                hidden = !hidden;
            }

            if (!hidden && (inMapScene || inZoneControl))
            {
                debugWindowRect = GUI.Window(12341234, debugWindowRect, (id) =>
                {
                    var mapRect = new Rect(2, 18, 196, 180);
                    using (new GUILayout.AreaScope(mapRect))
                    {
                        guiMap.Center = GeoExtension.Instance.Location;
                        guiMap.Zoom   = 17;
                        guiMap.DrawMap(new Rect(0, 0, 196, 180));
                        // Calculate the player pixel relative to the map
                        var playerMeters        = MapzenGo.Helpers.GM.LatLonToMeters(GeoExtension.Instance.Location);
                        var playerPixel         = MapzenGo.Helpers.GM.MetersToPixels(playerMeters, guiMap.Zoom);
                        var playerPixelRelative = playerPixel + guiMap.PATR;

                        // Do the point handling
                        var pointControl   = GUIUtility.GetControlID("PlayerPosition".GetHashCode(), FocusType.Passive);
                        var oldPlayerPixel = playerPixelRelative.ToVector2();
                        var newPlayerPixel = HandlePointMovement(pointControl, oldPlayerPixel, 60,
                                                                 (point, isOver, isActive) =>
                        {
                            var locationRect    = new Rect(0, 0, 30, 30);
                            locationRect.center = point;
                            locationRect.y     -= locationRect.height / 2f;
                            GUI.DrawTexture(locationRect, pointer);
                        });

                        if (oldPlayerPixel != newPlayerPixel)
                        {
                            // If changed, restore the point to the geochar
                            playerPixel  = newPlayerPixel.ToVector2d() - guiMap.PATR;
                            playerMeters = MapzenGo.Helpers.GM.PixelsToMeters(playerPixel, guiMap.Zoom);
                            GeoExtension.Instance.Location = MapzenGo.Helpers.GM.MetersToLatLon(playerMeters);
                        }

                        guiMap.ProcessEvents(mapRect);

                        GUI.Label(new Rect(0, 0, 196, 40), "Drag the pointer to move");
                    }
                    GUI.DragWindow();
                },
                                             "Debug Location");
            }
        }
コード例 #5
0
ファイル: MapWindow.cs プロジェクト: dotlive/uAdventure
        /* ----------------------------------
         * ON GUI: Used for drawing the window every unity event
         * ----------------------------------*/
        protected void OnGUI()
        {
            if (addressDropdown == null)
            {
                Init();
            }

            var prevAddress = address;

            address = addressDropdown.LayoutBegin();
            if (address != prevAddress)
            {
                timeSinceLastWrite = 0;
            }


            // Location control
            location = EditorGUILayout.Vector2Field("Location", location);
            var lastRect = GUILayoutUtility.GetLastRect();

            if (location != map.Center.ToVector2())
            {
                map.Center = new Vector2d(location.x, location.y);
            }

            GUILayout.BeginHorizontal();
            // Geometries control
            var geometriesWidth = 150;

            geometriesReorderableList.elementHeight = geometriesReorderableList.list.Count == 0 ? 20 : 70;
            var rect = GUILayoutUtility.GetRect(geometriesWidth, position.height - lastRect.y - lastRect.height);

            geometriesReorderableList.DoList(rect);

            // Map drawing
            map.selectedGeometry = geometriesReorderableList.index >= 0 ? geometries[geometriesReorderableList.index] : null;
            if (map.DrawMap(GUILayoutUtility.GetRect(position.width - geometriesWidth, position.height - lastRect.y - lastRect.height)))
            {
                Debug.Log(map.GeoMousePosition);
                if (editing != null)
                {
                    switch (editing.Type)
                    {
                    case GMLGeometry.GeometryType.Point:
                        if (editing.Points.Count == 1)
                        {
                            editing.Points[0] = map.GeoMousePosition;
                        }
                        else
                        {
                            editing.Points.Add(map.GeoMousePosition);
                        }
                        break;

                    case GMLGeometry.GeometryType.LineString:
                        editing.Points.Add(map.GeoMousePosition);
                        break;

                    case GMLGeometry.GeometryType.Polygon:
                        if (editing.Points.Count <= 1)
                        {
                            editing.Points.Add(map.GeoMousePosition);
                        }
                        else
                        {
                            // Find the closest index
                            var min     = editing.Points.Min(p => (p - map.GeoMousePosition).magnitude);
                            var closest = editing.Points.FindIndex(p => (p - map.GeoMousePosition).magnitude == min);

                            // Fix the previous and next
                            var prev = closest == 0 ? editing.Points.Count - 1 : closest - 1;
                            var next = (closest + 1) % editing.Points.Count;
                            // Calculate the normal to both adjacent axis to closest point
                            var c  = editing.Points[closest];
                            var v1 = (editing.Points[closest] - editing.Points[prev]).normalized;
                            var v2 = (editing.Points[closest] - editing.Points[next]).normalized;

                            var closestNormal = (v1 + v2).normalized;
                            var convex        = Vector3.Cross(v1.ToVector2(), v2.ToVector2()).z > 0;

                            var mouseVector = (map.GeoMousePosition - c);
                            var left        = Vector3.Cross(closestNormal.ToVector2(), mouseVector.ToVector2()).z > 0;

                            Debug.Log(convex ? "Convex" : "Concave");
                            if ((left && convex) || (!left && !convex))
                            {
                                Debug.Log("Prev");
                                // We insert at the closest
                                editing.Points.Insert(closest, map.GeoMousePosition);
                            }
                            else
                            {
                                Debug.Log("Next");
                                // We insert at the next
                                editing.Points.Insert(next, map.GeoMousePosition);
                            }
                        }
                        break;
                    }
                }
            }


            location = map.Center.ToVector2();
            geometriesReorderableList.index = map.selectedGeometry != null?geometries.IndexOf(map.selectedGeometry) : -1;

            GUILayout.EndHorizontal();

            if (addressDropdown.LayoutEnd())
            {
                // If new Location is selected from the dropdown
                lastSearch = address = addressDropdown.Value;
                foreach (var l in place.DataStructure.dataChache)
                {
                    if (l.label == address)
                    {
                        location = l.coordinates;
                    }
                }

                var geometry = new GMLGeometry();
                geometry.Type = GMLGeometry.GeometryType.Polygon;

                var points = 5f;
                var radius = 0.00005;
                for (float i = 0; i < 5; i++)
                {
                    geometry.Points.Add(new Vector2d(location.x + radius * Mathf.Sin(i * 2f * Mathf.PI / points) * 1.33333f, location.y + radius * Mathf.Cos(i * 2f * Mathf.PI / points)));
                }


                geometries.Add(geometry);

                place.DataStructure.dataChache.Clear();
                Repaint();
            }
        }
コード例 #6
0
        public override void Draw(int aID)
        {
            if (selectedElement == -1)
            {
                GUILayout.Label("Nothing selected");
                return;
            }

            element = Controller.Instance.SelectedChapterDataControl.getObjects <GeoElement>()[selectedElement];


            actionsList.list = element.Actions;
            // Set geometries list reference
            map.Geometries = new List <GMLGeometry>()
            {
                element.Geometry
            };

            selected = GUILayout.Toolbar(selected, menus);

            switch (selected)
            {
            case 0:     // Map view
            {
                element.Geometry.Type = (GMLGeometry.GeometryType)EditorGUILayout.EnumPopup("Geometry type", element.Geometry.Type);
                EditorGUILayout.LabelField("Points: " + element.Geometry.Points.Count);
                element.Geometry.Influence = EditorGUILayout.FloatField("Influence Radius", element.Geometry.Influence);


                if (GUILayout.Button("Center") && element.Geometry.Points.Count > 0)
                {
                    Center(element);
                }

                if (GUILayout.Button(!editing ? "Edit" : "Finish"))
                {
                    editing = !editing;
                }

                EditorGUILayout.Separator();
                placeSearcher.LayoutBegin();

                // Location control
                location = EditorGUILayout.Vector2Field("Location", location);
                if (location != map.Center.ToVector2())
                {
                    map.Center = new Vector2d(location.x, location.y);
                }

                // Map drawing
                if (editing)
                {
                    map.selectedGeometry = element.Geometry;
                }

                if (map.DrawMap(GUILayoutUtility.GetRect(0, 0, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true))) && element != null && editing)
                {
                    element.Geometry.AddPoint(map.GeoMousePosition);
                }

                location = map.Center.ToVector2();

                if (placeSearcher.LayoutEnd())
                {
                    // If new Location is selected from the dropdown
                    location = placeSearcher.LatLon.ToVector2();
                    Repaint();
                }
            } break;

            case 1:
            {
                GUILayout.Label("Full description");
                element.FullDescription = GUILayout.TextArea(element.FullDescription, GUILayout.Height(250));

                element.Name                = EditorGUILayout.TextField("Name", element.Name);
                element.BriefDescription    = EditorGUILayout.TextField("Brief description", element.BriefDescription);
                element.DetailedDescription = EditorGUILayout.TextField("Detailed description", element.DetailedDescription);

                GUILayout.Label("Element image");
                GUILayout.BeginHorizontal();
                GUILayout.Box(element.Image, GUILayout.Width(0.78f * m_Rect.width));
                if (GUILayout.Button(TC.get("Buttons.Select"), GUILayout.Width(0.2f * m_Rect.width)))
                {
                    ShowAssetChooser(AssetType.Image);
                }
                GUILayout.EndHorizontal();
            }
            break;

            case 2:
            {
                actionsList.list = element.Actions;
                actionsList.DoList(new Rect(0, 50, m_Rect.width * 0.99f, m_Rect.height));
            }
            break;
            }
        }