Esempio n. 1
0
        public void SetCountryDecorator(int groupIndex, string countryName, CountryDecorator decorator)
        {
            // Get the group decorator container
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, true);

            if (decorator.countryName == null || !decorator.countryName.Equals(countryName))
            {
                decorator.countryName = countryName;
            }
            di.SetDecorator(decorator);
        }
Esempio n. 2
0
        public void SetDecorator(CountryDecorator decorator)
        {
            int k = GetDecoratorIndex(decorator.countryName);

            if (k >= 0)
            {
                decorators [k] = decorator;
            }
            else
            {
                decorators.Add(decorator);
            }
            decorator.isNew = false;
            UpdateDecorators(true);
        }
        // Sample code to show how to use decorators to assign a texsture
        void TextureSample()
        {
            // 1st way (best): assign a flag texture to USA using direct API - this texture will get cleared when you call HideCountrySurfaces()
            Texture2D texture      = Resources.Load <Texture2D> ("flagUSA");
            int       countryIndex = map.GetCountryIndex("United States of America");

            map.ToggleCountrySurface(countryIndex, true, Color.white, texture);

            // 2nd way: assign a flag texture to Brazil using decorator - the texture will stay when you call HideCountrySurfaces()
            string           countryName = "Brazil";
            CountryDecorator decorator   = new CountryDecorator();

            decorator.isColorized   = true;
            decorator.texture       = Resources.Load <Texture2D> ("flagBrazil");
            decorator.textureOffset = Misc.Vector2down * 2.4f;
            map.decorator.SetCountryDecorator(0, countryName, decorator);

            Debug.Log("USA flag added with direct API.");
            Debug.Log("Brazil flag added with decorator (persistent texture).");

            map.FlyToCountry("Panama", 2f);
        }
Esempio n. 4
0
        // Sample code to show how to use decorators to assign a texsture
        void TextureSample()
        {
            // Assign a flag texture to USA
            string           countryName = "United States of America";
            CountryDecorator decorator   = new CountryDecorator();

            decorator.isColorized = true;
            decorator.texture     = Resources.Load <Texture2D> ("flagUSA");
            map.decorator.SetCountryDecorator(0, countryName, decorator);

            // Assign a flag texture to Brazil with vertical offset
            countryName             = "Brazil";
            decorator               = new CountryDecorator();
            decorator.isColorized   = true;
            decorator.texture       = Resources.Load <Texture2D> ("flagBrazil");
            decorator.textureOffset = -Vector2.up * 2.5f;
            map.decorator.SetCountryDecorator(0, countryName, decorator);

            // Fly to Mexico (just to see both USA and Brazil on the screen)
            map.FlyToCountry("Mexico", 3);
            map.autoRotationSpeed = 0;             // stops auto-rotating
        }
Esempio n. 5
0
        public void UpdateDecorators(bool ignoreActive)
        {
            if (!active && !ignoreActive)
            {
                return;
            }
            if (decorators == null || map == null)
            {
                return;
            }

            bool needsLabelRedraw     = false;
            bool needsFrontiersRedraw = false;

            for (int k = 0; k < decorators.Count; k++)
            {
                CountryDecorator decorator = decorators [k];

                // Check if something needs to be changed
                int countryIndex = map.GetCountryIndex(decorator.countryName);
                if (countryIndex >= 0)
                {
                    Country country    = map.countries [countryIndex];
                    Region  mainRegion = country.regions[country.mainRegionIndex];
                    if (active)
                    {
                        // label Font override
                        if (country.labelFontOverride != decorator.labelFontOverride)
                        {
                            country.labelFontOverride = decorator.labelFontOverride;
                            needsLabelRedraw          = true;
                        }
                        // label color override
                        if (country.labelColorOverride != decorator.labelOverridesColor)
                        {
                            country.labelColorOverride = decorator.labelOverridesColor;
                            needsLabelRedraw           = true;
                        }
                        if (country.labelColorOverride && country.labelColor != decorator.labelColor)
                        {
                            country.labelColor = decorator.labelColor;
                            needsLabelRedraw   = true;
                        }
                        // label visible
                        if (country.labelVisible != decorator.labelVisible)
                        {
                            country.labelVisible = decorator.labelVisible;
                            needsLabelRedraw     = true;
                        }
                        // label rotation
                        if (country.labelRotation != decorator.labelRotation)
                        {
                            country.labelRotation = decorator.labelRotation;
                            needsLabelRedraw      = true;
                        }
                        // label offset
                        if (country.labelOffset != decorator.labelOffset)
                        {
                            country.labelOffset = decorator.labelOffset;
                            needsLabelRedraw    = true;
                        }
                        // custom label
                        if ((country.customLabel == null && decorator.customLabel.Length > 0) || (country.customLabel != null && country.customLabel != decorator.customLabel))
                        {
                            if (decorator.customLabel.Length > 0)
                            {
                                country.customLabel = decorator.customLabel;
                            }
                            else
                            {
                                country.customLabel = null;
                            }
                            if (country.labelGameObject != null)
                            {
                                DestroyImmediate(country.labelGameObject);
                            }
                            needsLabelRedraw = true;
                        }
                        // colorize
                        if (decorator.isColorized)
                        {
                            map.ToggleCountryMainRegionSurface(countryIndex, true, decorator.fillColor, decorator.texture, decorator.textureScale, decorator.textureOffset, decorator.textureRotation);
                        }
                        else if (!decorator.isColorized && mainRegion.customMaterial != null)
                        {
                            map.HideCountrySurface(countryIndex);
                        }
                        // hidden
                        if (country.hidden != decorator.hidden)
                        {
                            country.hidden       = decorator.hidden;
                            needsFrontiersRedraw = true;
                        }
                    }
                    else
                    {
                        if (country.labelFontOverride != null)
                        {
                            country.labelFontOverride = null;
                            needsLabelRedraw          = true;
                        }
                        if (country.labelColorOverride)
                        {
                            country.labelColorOverride = false;
                            needsLabelRedraw           = true;
                        }
                        if (!country.labelVisible)
                        {
                            country.labelVisible = true;
                            needsLabelRedraw     = true;
                        }
                        if (country.customLabel != null)
                        {
                            country.customLabel = null;
                            needsLabelRedraw    = true;
                        }
                        if (country.labelRotation > 0)
                        {
                            country.labelRotation = 0;
                            needsLabelRedraw      = true;
                        }
                        if (country.labelOffset != Misc.Vector2zero)
                        {
                            country.labelOffset = Misc.Vector2zero;
                            needsLabelRedraw    = true;
                        }
                        if (country.hidden)
                        {
                            country.hidden       = false;
                            needsFrontiersRedraw = true;
                        }
                        if (mainRegion.customMaterial != null)
                        {
                            mainRegion.customMaterial = null;
                            map.HideCountrySurface(countryIndex);
                        }
                    }
                }
            }

            if (needsFrontiersRedraw)
            {
                map.OptimizeFrontiers();
                map.Redraw();
            }
            else if (needsLabelRedraw)
            {
                map.RedrawMapLabels();
            }
        }
        public override void OnInspectorGUI()
        {
            if (_decorator == null)
            {
                return;
            }

            bool requestChanges = false;

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

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Group", GUILayout.Width(120));
            int oldGroup = _decorator.GUIGroupIndex;

            _decorator.GUIGroupIndex = EditorGUILayout.Popup(_decorator.GUIGroupIndex, groupNames, GUILayout.MaxWidth(200));
            if (_decorator.GUIGroupIndex != oldGroup || decoratorGroup == null)
            {
                decoratorGroup = _decorator.GetDecoratorGroup(_decorator.GUIGroupIndex, true);
            }

            if (GUILayout.Button("Clear"))
            {
                _decorator.ClearDecoratorGroup(_decorator.GUIGroupIndex);
                ReloadGroupNames();
                ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Enabled", GUILayout.Width(120));
            decoratorGroup.active = EditorGUILayout.Toggle(decoratorGroup.active, GUILayout.Width(20));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            // country selector
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Country", GUILayout.Width(120));
            if (lastCountryCount != _map.countries.Length)
            {
                ReloadCountryNames();
            }
            int selection = EditorGUILayout.Popup(_decorator.GUICountryIndex, countryNames);

            if (selection != _decorator.GUICountryIndex)
            {
                _decorator.GUICountryName  = "";
                _decorator.GUICountryIndex = selection;
                FlyToCountry();
            }

            bool prevc = _decorator.groupByContinent;

            GUILayout.Label("Grouped");
            _decorator.groupByContinent = EditorGUILayout.Toggle(_decorator.groupByContinent, GUILayout.Width(20));
            if (_decorator.groupByContinent != prevc)
            {
                ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            // type of decoration
            if (_decorator.GUICountryName.Length > 0)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(120));
                if (GUILayout.Button("Toggle Zoom"))
                {
                    ToggleZoomState();
                }
                if (GUILayout.Button("Fly To"))
                {
                    FlyToCountry();
                }
                EditorGUILayout.EndHorizontal();

                CountryDecorator existingDecorator = _decorator.GetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                if (existingDecorator != null)
                {
                    decorator = existingDecorator;
                }
                else if (decorator == null || !decorator.countryName.Equals(_decorator.GUICountryName))
                {
                    decorator = new CountryDecorator(_decorator.GUICountryName);
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Hidden", GUILayout.Width(120));
                bool prevHidden = decorator.hidden;
                decorator.hidden = EditorGUILayout.Toggle(decorator.hidden);
                if (prevHidden != decorator.hidden)
                {
                    requestChanges = true;
                }
                EditorGUILayout.EndHorizontal();

                if (!decorator.hidden)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Label Visible", GUILayout.Width(120));
                    bool prevLabelVisible = decorator.labelVisible;
                    decorator.labelVisible = EditorGUILayout.Toggle(decorator.labelVisible);
                    if (prevLabelVisible != decorator.labelVisible)
                    {
                        requestChanges = true;
                    }
                    EditorGUILayout.EndHorizontal();

                    if (decorator.labelVisible)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Text", GUILayout.Width(120));
                        string prevLabel = decorator.customLabel;
                        decorator.customLabel = EditorGUILayout.TextField(decorator.customLabel);
                        if (!prevLabel.Equals(decorator.customLabel))
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Font", GUILayout.Width(120));
                        Font prevFont = decorator.labelFontOverride;
                        decorator.labelFontOverride = (Font)EditorGUILayout.ObjectField(decorator.labelFontOverride, typeof(Font), false);
                        if (decorator.labelFontOverride != prevFont)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();


                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Color", GUILayout.Width(120));
                        decorator.labelOverridesColor = EditorGUILayout.Toggle(decorator.labelOverridesColor);
                        if (decorator.labelOverridesColor)
                        {
                            GUILayout.Label("Color", GUILayout.Width(120));
                            Color prevColor = decorator.labelColor;
                            decorator.labelColor = EditorGUILayout.ColorField(decorator.labelColor);
                            if (prevColor != decorator.labelColor)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Offset", GUILayout.Width(120));
                        Vector2 prevLabelOffset = decorator.labelOffset;
                        decorator.labelOffset = EditorGUILayout.Vector2Field("", decorator.labelOffset);
                        if (prevLabelOffset != decorator.labelOffset)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Rotation", GUILayout.Width(120));
                        float prevLabelRotation = decorator.labelRotation;
                        decorator.labelRotation = EditorGUILayout.Slider(decorator.labelRotation, 0, 359);
                        if (prevLabelRotation != decorator.labelRotation)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Colorized", GUILayout.Width(120));
                    bool prevColorized = decorator.isColorized;
                    decorator.isColorized = EditorGUILayout.Toggle(decorator.isColorized);
                    if (decorator.isColorized != prevColorized)
                    {
                        requestChanges = true;
                    }
                    if (decorator.isColorized)
                    {
                        GUILayout.Label("Fill Color", GUILayout.Width(120));
                        Color prevColor = decorator.fillColor;
                        decorator.fillColor = EditorGUILayout.ColorField(decorator.fillColor);
                        if (prevColor != decorator.fillColor)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Texture", GUILayout.Width(120));
                        Texture2D prevTexture = decorator.texture;
                        decorator.texture = (Texture2D)EditorGUILayout.ObjectField(decorator.texture, typeof(Texture2D), false);
                        if (decorator.texture != prevTexture)
                        {
                            requestChanges = true;
                        }

                        if (decorator.texture != null)
                        {
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            Vector2 prevVector = decorator.textureScale;
                            decorator.textureScale = EditorGUILayout.Vector2Field("   Scale", decorator.textureScale);
                            if (prevVector != decorator.textureScale)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            prevVector = decorator.textureOffset;
                            decorator.textureOffset = EditorGUILayout.Vector2Field("   Offset", decorator.textureOffset);
                            if (prevVector != decorator.textureOffset)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Rotation", GUILayout.Width(120));
                            float prevFloat = decorator.textureRotation;
                            decorator.textureRotation = EditorGUILayout.Slider(decorator.textureRotation, 0, 360);
                            if (prevFloat != decorator.textureRotation)
                            {
                                requestChanges = true;
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.BeginHorizontal();
                if (decorator.isNew)
                {
                    if (GUILayout.Button("Assign"))
                    {
                        _decorator.SetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName, decorator);
                        ReloadGroupNames();
                        ReloadCountryNames();
                    }
                }
                else if (GUILayout.Button("Remove"))
                {
                    decorator = null;
                    _decorator.RemoveCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                    ReloadGroupNames();
                    ReloadCountryNames();
                }
                EditorGUILayout.EndHorizontal();

                if (!decoratorGroup.active)
                {
                    DrawWarningLabel("Enable the decoration group to activate changes");
                }
            }


            EditorGUILayout.EndVertical();

            if (requestChanges)
            {
                _decorator.ForceUpdateDecorators();
                SceneView.RepaintAll();
                EditorUtility.SetDirty(_map);
                if (!Application.isPlaying)
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
        }