Esempio n. 1
0
        private void InstantiateNames(Transform targetHeader, NativeArray <float2> centers,
                                      NativeArray <float> angles, IReadOnlyList <string> strSource, NativeArray <float> longest, bool countryScale,
                                      out bool toggle)
        {
            // Setting header to proper location at bottom left corner of texture.
            // Default scaling is 1 / 100 of the actual texture size. Hardcoded I know. Dividing by 2 because origin is at center of texture.
            targetHeader.localPosition = new Vector3(-_mapComponent.ColorSize.x / 100f / 2f,
                                                     -_mapComponent.ColorSize.y / 100f / 2f, -9);

            for (var i = 0; i < centers.Length; i++)
            {
                var newText       = Instantiate(textPrefab, targetHeader);
                var textTransform = newText.GetComponent <RectTransform>();
                textTransform.localPosition = new Vector3(centers[i].x / 100,
                                                          centers[i].y / 100);
                textTransform.rotation = Quaternion.AngleAxis(angles[i], Vector3.forward);

                var tmp = newText.GetComponent <TextMeshPro>();
                tmp.text = LoadMethods.NameCleaning(strSource[i]);
                textTransform.sizeDelta = new Vector2(tmp.preferredWidth, 2.02f);

                // Default scale: 0.0075. Hardcoded because it's the only one that looks nice.
                var scale = longest[i] / tmp.preferredWidth;
                tmp.name = scale.ToString(CultureInfo.InvariantCulture);

                if (!countryScale && scale > 50 || tmp.preferredWidth < 0.01)
                {
                    Destroy(newText);
                    continue;
                }

                // Trial and error
                if (countryScale)
                {
                    scale *= scale < 10  // Countries
                        ? 0.01f
                        : scale < 20     // Countries
                            ? 0.0075f
                            : scale < 30 // Countries
                                ? 0.006f
                                : 0.004f;
                }
                else
                {
                    scale *= scale < 3 // Provinces
                        ? 0.0078f
                        : scale < 5
                            ? 0.0062f
                            : 0.0035f;
                }

                textTransform.localScale = new Vector3(scale, scale, 1);
            }

            toggle = true;
        }