Exemple #1
0
    protected override void DrawSettings(ref bool dirty)
    {
        base.DrawSettings(ref dirty);

        EditorGUI.BeginChangeCheck();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(defaultTexture);
        if (EditorGUI.EndChangeCheck())
        {
            OnlineMapsEditorUtils.CheckMarkerTextureImporter(defaultTexture);
        }

        EditorGUILayout.PropertyField(defaultAlign);
        EditorGUILayout.PropertyField(defaultScale);
        EditorGUILayout.PropertyField(allowAddMarkerByM, new GUIContent("Add Marker by M"));

        if (EditorGUI.EndChangeCheck())
        {
            dirty = true;
        }
    }
Exemple #2
0
    private void OnEnable()
    {
        if (EditorPrefs.HasKey(invoiceNumberKey))
        {
            invoiceNumber = EditorPrefs.GetString(invoiceNumberKey);
        }
        else
        {
            invoiceNumber = "";
        }

        if (EditorPrefs.HasKey(channelKey))
        {
            channel = (OnlineMapsUpdateChannel)EditorPrefs.GetInt(channelKey);
        }
        else
        {
            channel = OnlineMapsUpdateChannel.stable;
        }

        helpContent = new GUIContent(OnlineMapsEditorUtils.LoadAsset <Texture2D>("Icons\\HelpIcon.png"), "You can find out your Invoice Number in the email confirming the purchase, or page the user in Unity Asset Store.\nClick to go to the Unity Asset Store.");
    }
    private void DrawLabelsGUI()
    {
        if (mapType.isCustom)
        {
            return;
        }

        bool showLanguage;

        if (mapType.hasLabels)
        {
            OnlineMapsEditorUtils.PropertyField(pLabels, "Show labels?");
            showLanguage = pLabels.boolValue;
        }
        else
        {
            showLanguage = mapType.labelsEnabled;
            GUILayout.Label("Labels " + (showLanguage ? "enabled" : "disabled"));
        }
        if (showLanguage && mapType.hasLanguage)
        {
            OnlineMapsEditorUtils.PropertyField(pLanguage, mapType.provider.twoLetterLanguage ? "Use two-letter code such as: en" : "Use three-letter code such as: eng");
        }
    }
Exemple #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        try
        {
            Rect rect = new Rect(position.x, position.y, position.width, 16);
            if (!DrawHeader(label, rect, property))
            {
                EditorGUI.EndProperty();
                return;
            }

            EditorGUI.BeginChangeCheck();
            SerializedProperty pLat = DrawProperty(property, "latitude", ref rect);
            if (EditorGUI.EndChangeCheck())
            {
                if (pLat.doubleValue < -90)
                {
                    pLat.doubleValue = -90;
                }
                else if (pLat.doubleValue > 90)
                {
                    pLat.doubleValue = 90;
                }
            }

            EditorGUI.BeginChangeCheck();
            SerializedProperty pLng = DrawProperty(property, "longitude", ref rect);
            if (EditorGUI.EndChangeCheck())
            {
                if (pLng.doubleValue < -180)
                {
                    pLng.doubleValue += 360;
                }
                else if (pLng.doubleValue > 180)
                {
                    pLng.doubleValue -= 360;
                }
            }

            DrawProperty(property, "range", ref rect, new GUIContent("Zooms"));

            EditorGUI.BeginChangeCheck();
            SerializedProperty pRot = DrawProperty(property, "_rotation", ref rect, new GUIContent("Rotation (0-1)"));
            if (EditorGUI.EndChangeCheck())
            {
                if (pRot.floatValue < 0 || pRot.floatValue > 1)
                {
                    pRot.floatValue = Mathf.Repeat(pRot.floatValue, 1);
                }
            }

            DrawProperty(property, "_scale", ref rect);
            DrawProperty(property, "label", ref rect);
            DrawProperty(property, "align", ref rect);

            EditorGUI.BeginChangeCheck();
            SerializedProperty pTexture = DrawProperty(property, "texture", ref rect);
            if (EditorGUI.EndChangeCheck())
            {
                OnlineMapsEditorUtils.CheckMarkerTextureImporter(pTexture);
            }

            DrawCenterButton(rect, pLng, pLat);
        }
        catch
        {
        }

        EditorGUI.EndProperty();
    }
Exemple #5
0
    protected override void Init()
    {
        Texture2D icon = OnlineMapsEditorUtils.LoadAsset <Texture2D>("Icons/Online-Maps-uContext.png", true);

        _guiContent = new GUIContent(icon, "Online Maps");
    }
    private void CreateMap()
    {
        OnlineMaps map    = CreateMapGameObject();
        GameObject go     = map.gameObject;
        Sprite     sprite = null;

        Control   control   = activeControl;
        Component component = go.AddComponent(control.type);

        if (control.resultType == OnlineMapsTarget.texture)
        {
            map.redrawOnPlay = true;

            string    texturePath;
            Texture2D texture = CreateTexture(map, out texturePath);

            if (control.useSprite)
            {
                if (!string.IsNullOrEmpty(texturePath))
                {
                    TextureImporter textureImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
                    textureImporter.textureType = TextureImporterType.Sprite;
                    textureImporter.SaveAndReimport();

                    sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite;
                }

                if (component is OnlineMapsSpriteRendererControl)
                {
                    SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
                    spriteRenderer.sprite = sprite;
                    go.AddComponent <BoxCollider>();
                }
            }

            if (component is OnlineMapsUIImageControl || component is OnlineMapsUIRawImageControl)
            {
                if (uGUIParent == null)
                {
                    uGUIParent = OnlineMapsEditorUtils.GetCanvas().gameObject;
                }

                RectTransform rectTransform = go.AddComponent <RectTransform>();
                rectTransform.SetParent(uGUIParent.transform as RectTransform);
                go.AddComponent <CanvasRenderer>();
                rectTransform.localPosition = Vector3.zero;
                rectTransform.anchorMax     = rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                rectTransform.pivot         = new Vector2(0.5f, 0.5f);
                rectTransform.sizeDelta     = new Vector2(textureWidth, textureHeight);

                if (component is OnlineMapsUIImageControl)
                {
                    Image image = go.AddComponent <Image>();
                    image.sprite = sprite;
                }
                else
                {
                    RawImage image = go.AddComponent <RawImage>();
                    image.texture = texture;
                }
            }

            if (component is OnlineMapsNGUITextureControl)
            {
#if NGUI
                go.layer = NGUIParent.layer;
                UITexture uiTexture = go.AddComponent <UITexture>();
                uiTexture.mainTexture      = texture;
                uiTexture.width            = textureWidth;
                uiTexture.height           = textureHeight;
                go.transform.parent        = NGUIParent.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.Euler(Vector3.zero);
                BoxCollider boxCollider = go.AddComponent <BoxCollider>();
                boxCollider.size = new Vector3(textureWidth, textureHeight, 0);
#endif
            }
            if (component is OnlineMapsTextureControl)
            {
                Renderer renderer = go.GetComponent <Renderer>();
                renderer.sharedMaterial             = new Material(Shader.Find("Diffuse"));
                renderer.sharedMaterial.mainTexture = texture;
            }
        }
        else
        {
            OnlineMapsControlBaseDynamicMesh control3D = component as OnlineMapsControlBaseDynamicMesh;
            map.width             = tilesetWidth;
            map.height            = tilesetHeight;
            control3D.sizeInScene = sizeInScene;
            map.renderInThread    = false;

            OnlineMapsTileSetControl tsControl = component as OnlineMapsTileSetControl;
            if (tsControl != null)
            {
                tsControl.tileMaterial   = tileMaterial;
                tsControl.markerMaterial = markerMaterial;
                tsControl.tilesetShader  = tilesetShader;
                tsControl.drawingShader  = drawingShader;
                tsControl.markerShader   = markerShader;
            }

            if (moveCameraToMap)
            {
                GameObject cameraGO = activeCamera.gameObject;
                float      minSide  = Mathf.Min(sizeInScene.x, sizeInScene.y);
                Vector3    pos      = new Vector3(sizeInScene.x / -2, minSide, sizeInScene.y / 2);
                cameraGO.transform.position = pos;
                cameraGO.transform.rotation = Quaternion.Euler(90, 180, 0);
            }
        }

        foreach (IPlugin plugin in control.plugins)
        {
            if (plugin is Plugin)
            {
                Plugin p = plugin as Plugin;
                if (p.enabled)
                {
                    go.AddComponent(p.type);
                }
            }
            else if (plugin is PluginGroup)
            {
                PluginGroup g = plugin as PluginGroup;
                if (g.selected > 0)
                {
                    go.AddComponent(g.plugins.First(p => p.title == g.titles[g.selected]).type);
                }
            }
        }

        EditorGUIUtility.PingObject(go);
        Selection.activeGameObject = go;
    }
    private void DrawMapTypes(ref bool dirty)
    {
        if (control != null && !control.useRasterTiles)
        {
            return;
        }
        if (pSource.enumValueIndex == (int)OnlineMapsSource.Resources)
        {
            return;
        }
        if (pSource.enumValueIndex == (int)OnlineMapsSource.StreamingAssets)
        {
            return;
        }

        DrawProviderGUI();

        if (mapType.provider.types.Length > 1)
        {
            GUIContent[] availableTypes = mapType.provider.types.Select(t => new GUIContent(t.title)).ToArray();
            int          index          = mapType.index;
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            index = EditorGUILayout.Popup(new GUIContent("Type", "Type of map texture"), index, availableTypes);
            if (EditorGUI.EndChangeCheck())
            {
                mapType = mapType.provider.types[index];
                pMapType.stringValue = mapType.ToString();
            }
            OnlineMapsEditorUtils.HelpButton("Type (style) of the map");
            EditorGUILayout.EndHorizontal();
        }

        DrawProviderExtraFields(ref dirty, mapType.provider.extraFields);
        DrawProviderExtraFields(ref dirty, mapType.extraFields);
        if (mapType.fullID == "google.satellite")
        {
            if (GUILayout.Button("Detect the latest version of tiles"))
            {
                WebClient client   = new WebClient();
                string    response = client.DownloadString("http://maps.googleapis.com/maps/api/js");
                Match     match    = Regex.Match(response, @"kh\?v=(\d+)");
                if (match.Success)
                {
                    OnlineMapsProvider.ExtraField version = mapType.extraFields.FirstOrDefault(f =>
                    {
                        OnlineMapsProvider.ExtraField ef = f as OnlineMapsProvider.ExtraField;
                        if (ef == null)
                        {
                            return(false);
                        }
                        if (ef.token != "version")
                        {
                            return(false);
                        }
                        return(true);
                    }) as OnlineMapsProvider.ExtraField;
                    if (version != null)
                    {
                        version.value = match.Groups[1].Value;
                    }
                }
            }
        }
        DrawLabelsGUI();
    }