Ejemplo n.º 1
0
    private void CheckNullControl()
    {
        OnlineMapsControlBase[] controls = api.GetComponents <OnlineMapsControlBase>();
        if (controls != null && controls.Length != 0)
        {
            return;
        }

        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.HelpBox("Problem detected:\nCan not find OnlineMaps Control component.", MessageType.Error);
        if (GUILayout.Button("Add Control"))
        {
            GenericMenu menu = new GenericMenu();

            Type[] types = api.GetType().Assembly.GetTypes();
            foreach (Type t in types)
            {
                if (t.IsSubclassOf(typeof(OnlineMapsControlBase)))
                {
                    if (t == typeof(OnlineMapsControlBase2D) || t == typeof(OnlineMapsControlBase3D))
                    {
                        continue;
                    }

                    string fullName = t.FullName.Substring(10);

                    int controlIndex = fullName.IndexOf("Control");
                    fullName = fullName.Insert(controlIndex, " ");

                    int textureIndex = fullName.IndexOf("Texture");
                    if (textureIndex > 0)
                    {
                        fullName = fullName.Insert(textureIndex, " ");
                    }

                    menu.AddItem(new GUIContent(fullName), false, data =>
                    {
                        Type ct = data as Type;
                        api.gameObject.AddComponent(ct);
                        pTarget.enumValueIndex = ct == typeof(OnlineMapsTileSetControl) ? (int)OnlineMapsTarget.tileset : (int)OnlineMapsTarget.texture;
                        Repaint();
                    }, t);
                }
            }

            menu.ShowAsContext();
        }

        EditorGUILayout.EndVertical();
    }
Ejemplo n.º 2
0
    private void CheckNullControl()
    {
        OnlineMapsControlBase[] controls = map.GetComponents <OnlineMapsControlBase>();
        if (controls != null && controls.Length != 0)
        {
            return;
        }

        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.HelpBox("Problem detected:\nCan not find OnlineMaps Control component.", MessageType.Error);
        if (GUILayout.Button("Add Control"))
        {
            GenericMenu menu = new GenericMenu();

            Type[] types = map.GetType().Assembly.GetTypes();
            foreach (Type t in types)
            {
                if (t.IsSubclassOf(typeof(OnlineMapsControlBase)) && !t.IsAbstract)
                {
                    string fullName = t.FullName;
                    if (fullName.StartsWith("OnlineMaps"))
                    {
                        fullName = fullName.Substring(10);
                    }

                    int controlIndex = fullName.IndexOf("Control");
                    fullName = fullName.Insert(controlIndex, " ");

                    int textureIndex = fullName.IndexOf("Texture");
                    if (textureIndex > 0)
                    {
                        fullName = fullName.Insert(textureIndex, " ");
                    }

                    menu.AddItem(new GUIContent(fullName), false, data =>
                    {
                        Type ct = data as Type;
                        map.gameObject.AddComponent(ct);
                        Repaint();
                    }, t);
                }
            }

            menu.ShowAsContext();
        }

        EditorGUILayout.EndVertical();
    }
Ejemplo n.º 3
0
    private static void PlaymodeStateChanged(PlayModeStateChange playModeStateChange)
#endif
    {
        if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
        {
            if (Exists())
            {
#pragma warning disable 618
                OnlineMaps map = ((OnlineMaps[])Object.FindSceneObjectsOfType(typeof(OnlineMaps))).FirstOrDefault();
#pragma warning restore 618
                if (map != null)
                {
                    try
                    {
                        IOnlineMapsSavableComponent[] savableComponents = map.GetComponents <IOnlineMapsSavableComponent>();
                        OnlineMapsSavableItem[]       savableItems      = savableComponents.SelectMany(c => c.GetSavableItems()).ToArray();
                        if (savableItems.Length != 0)
                        {
                            string prefs = EditorPrefs.GetString(prefsKey);
                            OnlineMapsJSONObject json = OnlineMapsJSON.Parse(prefs) as OnlineMapsJSONObject;
                            foreach (KeyValuePair <string, OnlineMapsJSONItem> pair in json.table)
                            {
                                OnlineMapsSavableItem savableItem = savableItems.FirstOrDefault(s => s.name == pair.Key);
                                if (savableItem != null && savableItem.loadCallback != null)
                                {
                                    savableItem.loadCallback(pair.Value as OnlineMapsJSONObject);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogException(ex);
                        // ignored
                    }

                    EditorPrefs.DeleteKey(prefsKey);
                    EditorUtility.SetDirty(map);
                }
            }

            if (EditorPrefs.HasKey("OnlineMapsRefreshAssets"))
            {
                EditorPrefs.DeleteKey("OnlineMapsRefreshAssets");
                AssetDatabase.Refresh();
            }
        }
    }
Ejemplo n.º 4
0
    private void OnEnable()
    {
        try
        {
            CacheSerializedProperties();
            map     = (OnlineMaps)target;
            control = map.GetComponent <OnlineMapsControlBase>();

            savableItems = map.GetComponents <IOnlineMapsSavableComponent>().SelectMany(c => c.GetSavableItems()).OrderByDescending(s => s.priority).ThenBy(s => s.label).ToList();

            providers      = OnlineMapsProvider.GetProviders();
            providersTitle = providers.Select(p => p.title).ToArray();

            trafficProviders     = OnlineMapsTrafficProvider.GetProviders();
            cTrafficProviders    = trafficProviders.Select(p => new GUIContent(p.title)).ToArray();
            trafficProviderIndex = 0;
            for (int i = 0; i < trafficProviders.Length; i++)
            {
                if (trafficProviders[i].id == pTrafficProviderID.stringValue)
                {
                    trafficProviderIndex = i;
                    break;
                }
            }

            if (pTooltipTexture.objectReferenceValue == null)
            {
                pTooltipTexture.objectReferenceValue = OnlineMapsEditorUtils.LoadAsset <Texture2D>("Textures\\Tooltip.psd");
            }

            updateAvailableContent = new GUIContent("Update Available", OnlineMapsEditorUtils.LoadAsset <Texture2D>("Icons\\update_available.png"), "Update Available");
            wizardIconContent      = new GUIContent(OnlineMapsEditorUtils.LoadAsset <Texture2D>("Icons\\WizardIcon.png"), "Wizard");

            OnlineMapsUpdater.CheckNewVersionAvailable();

            mapType       = OnlineMapsProvider.FindMapType(pMapType.stringValue);
            providerIndex = mapType.provider.index;

            serializedObject.ApplyModifiedProperties();

            map.floatZoom = map.CheckMapSize(map.floatZoom);
        }
        catch (Exception e)
        {
            Debug.Log(e.Message + "\n" + e.StackTrace);
            //throw;
        }
    }
Ejemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        DrawToolbarGUI();

        bool dirty = DrawGeneralGUI();

        EditorGUILayout.BeginVertical(GUI.skin.box);
        showMarkers = Foldout(showMarkers, "2D Markers");
        if (showMarkers)
        {
            DrawMarkersGUI();
        }
        EditorGUILayout.EndVertical();

        if (api.target == OnlineMapsTarget.texture)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            showCreateTexture = Foldout(showCreateTexture, "Create texture");
            if (showCreateTexture)
            {
                DrawCreateTextureGUI(ref dirty);
            }
            EditorGUILayout.EndVertical();
        }

        EditorGUILayout.BeginVertical(GUI.skin.box);
        showAdvanced = Foldout(showAdvanced, "Advanced");
        if (showAdvanced)
        {
            DrawAdvancedGUI(ref dirty);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(GUI.skin.box);
        showTroubleshooting = Foldout(showTroubleshooting, "Troubleshooting");
        if (showTroubleshooting)
        {
            DrawTroubleshootingGUI(ref dirty);
        }
        EditorGUILayout.EndVertical();

        OnlineMapsControlBase[] controls = api.GetComponents <OnlineMapsControlBase>();
        if (controls == null || controls.Length == 0)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);

            EditorGUILayout.HelpBox("Problem detected:\nCan not find OnlineMaps Control component.", MessageType.Error);
            if (GUILayout.Button("Add Control"))
            {
                GenericMenu menu = new GenericMenu();

                Type[] types = api.GetType().Assembly.GetTypes();
                foreach (Type t in types)
                {
                    if (t.IsSubclassOf(typeof(OnlineMapsControlBase)))
                    {
                        if (t == typeof(OnlineMapsControlBase2D) || t == typeof(OnlineMapsControlBase3D))
                        {
                            continue;
                        }

                        string fullName = t.FullName.Substring(10);

                        int controlIndex = fullName.IndexOf("Control");
                        fullName = fullName.Insert(controlIndex, " ");

                        int textureIndex = fullName.IndexOf("Texture");
                        if (textureIndex > 0)
                        {
                            fullName = fullName.Insert(textureIndex, " ");
                        }

                        menu.AddItem(new GUIContent(fullName), false, data =>
                        {
                            Type ct = data as Type;
                            api.gameObject.AddComponent(ct);
                            api.target = (ct == typeof(OnlineMapsTileSetControl))
                                ? OnlineMapsTarget.tileset
                                : OnlineMapsTarget.texture;
                            Repaint();
                        }, t);
                    }
                }

                menu.ShowAsContext();
            }

            EditorGUILayout.EndVertical();
        }

        if (dirty)
        {
            EditorUtility.SetDirty(api);
            Repaint();
        }
    }