Esempio n. 1
0
    /// <summary>
    /// 初始化值为了和Text的初始值保持一致
    /// </summary>
    /// <param name="txt"></param>
    private static void InitValue(TextI18N txt)
    {
        txt.color = new Color(50f / 255f, 50f / 255f, 50f / 255f);
        RectTransform contentRT = txt.GetComponent <RectTransform>();

        contentRT.sizeDelta  = new Vector2(200f, 50);
        txt.gameObject.layer = LayerMask.NameToLayer(kUILayerName);
    }
Esempio n. 2
0
    private void Awake()
    {
        _contentTxt = transform.Find("ContextMask/ContentTxt").GetComponent <TextI18N>();

        _lineHeight  = _contentTxt.preferredHeight;
        _lineSpacing = (_contentTxt.lineSpacing - 1) * _contentTxt.fontSize;

        RectTransform rect = _contentTxt.GetComponent <RectTransform>();

        rect.sizeDelta = new Vector2(rect.sizeDelta.x, _lineHeight * 3);
    }
Esempio n. 3
0
    public static void AddText(MenuCommand menuCommand)
    {
        GameObject go  = new GameObject("Text");
        TextI18N   txt = go.AddComponent <TextI18N>();

        txt.fontSize = 30;

//        string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes");
        string path = "Assets/BundleAssets/SingleFile/Fonts/MainFont.prefab";

        txt.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(path);

        path     = "Assets/BundleAssets/SingleFile/Fonts/lantingHei.TTF";
        txt.font = AssetDatabase.LoadAssetAtPath <Font>(path);

        PlaceUIElementRoot(go, menuCommand);
        InitValue(txt);
    }
Esempio n. 4
0
    static public void AddButton(MenuCommand menuCommand)
    {
        GameObject buttonRoot = CreateUIElementRoot("Button", menuCommand, s_ThickGUIElementSize);

        GameObject childText = new GameObject("Text");

        GameObjectUtility.SetParentAndAlign(childText, buttonRoot);

        RectTransform rect = buttonRoot.transform as RectTransform;

        rect.sizeDelta = new Vector2(300, 100);

        Image image = buttonRoot.AddComponent <Image>();

        image.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kStandardSpritePath);
        image.type   = Image.Type.Sliced;
        image.color  = s_DefaultSelectableColor;

        Button bt = buttonRoot.AddComponent <Button>();

        SetDefaultColorTransitionValues(bt);

        TextI18N text = childText.AddComponent <TextI18N>();

        text.text      = "Button";
        text.alignment = TextAnchor.MiddleCenter;
        SetDefaultTextValues(text);

        text.fontSize   = 30;
        text.TestString = "Button";

        string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes");
        text.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);

        bundles   = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/lantinghei.bytes");
        text.font = AssetDatabase.LoadAssetAtPath <Font>(bundles[0]);

        RectTransform textRectTransform = childText.GetComponent <RectTransform>();

        textRectTransform.anchorMin = Vector2.zero;
        textRectTransform.anchorMax = Vector2.one;
        textRectTransform.sizeDelta = Vector2.zero;
    }
Esempio n. 5
0
        private void Awake()
        {
            _contentTxt = transform.Find("ContextMask/ContentTxt").GetComponent <TextI18N>();
            _nameTxt    = transform.Find("NameBg/NameTxt").GetComponent <Text>();
            _nameTxt2   = transform.Find("HeadContainer/NameText").GetComponent <Text>();

            _nameBg = transform.Find("NameBg").GetComponent <Image>();

            _headContainer = transform.Find("HeadContainer");
            _headRole      = transform.Find("HeadContainer/Role").GetComponent <RawImage>();

            _bg = transform.Find("Bg").GetComponent <Image>();

            _contentTxt.text = "";
            _lineHeight      = _contentTxt.preferredHeight;
            _lineSpacing     = (_contentTxt.lineSpacing - 1) * _contentTxt.fontSize;

            RectTransform rect = _contentTxt.GetComponent <RectTransform>();

            rect.sizeDelta = new Vector2(rect.sizeDelta.x, _lineHeight * 3);
        }
Esempio n. 6
0
    public override void OnInspectorGUI()
    {
        TextI18N component = (TextI18N)target;

        serializedObject.Update();

        component.Key = EditorGUILayout.TextField("Key", component.Key);

        EditorGUILayout.PropertyField(_testString);
        EditorGUILayout.PropertyField(_useTestString);


        component.CustomFont = (I18NFont)EditorGUILayout.ObjectField("Custom Font", component.CustomFont, typeof(I18NFont), true);

        EditorGUILayout.PropertyField(_isOpenLocalize);

        EditorGUILayout.PropertyField(m_Text);
        EditorGUILayout.PropertyField(m_FontData);
        AppearanceControlsGUI();
        RaycastControlsGUI();
        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 7
0
    static void ReplaceText()
    {
//        EditorUtility.DisplayProgressBar("提示", "开始加载CSV文件", 0f);


        string vFile = new DirectoryInfo(Application.dataPath).Parent.FullName + "/battle.csv";

        string str     = FileUtil.ReadFileText(vFile);
        var    strings = str.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

        Dictionary <string, List <string> > prefabsDict = new Dictionary <string, List <string> >();
        int count = 0;

        foreach (var line in strings)
        {
            string trim = line.Trim();
            if (string.IsNullOrEmpty(trim))
            {
                continue;
            }

            string[] arr       = trim.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries);
            string   path      = arr[0].Trim();
            string[] separator = new[] { ".prefab:" };
            arr = path.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries);

            string prefab = arr[0] + ".prefab";

            if (prefabsDict.ContainsKey(prefab) == false)
            {
                prefabsDict.Add(prefab, new List <string>());
            }

            try
            {
                prefabsDict[prefab].Add(arr[1]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            count++;
        }

//        EditorUtility.DisplayProgressBar("提示", "替换Text (0/" + count + ")", 0.1f);

        count = 0;
        foreach (var dict in prefabsDict)
        {
//            if (count > 1)
//                break;

            GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(dict.Key);
            GameObject go     = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
            foreach (string textPath in dict.Value)
            {
                //去掉最后的数字
                str = textPath.Substring(0, textPath.Length - 1);

                //去掉开头
                int index = str.IndexOf("/", StringComparison.Ordinal);
                str = str.Substring(index + 1);

                int num;

                if (int.TryParse(str[str.Length - 1].ToString(), out num))
                {
                    str = str.Substring(0, str.Length - 1);
                }

                GameObject targetText;
                try
                {
                    targetText = go.transform.Find(str).gameObject;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                TextI18N textI18N = targetText.GetComponent <TextI18N>();
                Text     text     = targetText.GetComponent <Text>();

                if (text.GetType().Name.Contains("TextI18N"))
                {
                    EditorUtility.DisplayDialog("Error!", dict.Key + "->" + str + "里面已经存在TextI18N", "Close");
                    return;
                }

                string     childtext       = text.text;
                Font       childFont       = text.font;
                FontStyle  childFontStyle  = text.fontStyle;
                int        childFontSize   = text.fontSize;
                float      childSpacing    = text.lineSpacing;
                bool       childRichText   = text.supportRichText;
                TextAnchor childAlignment  = text.alignment;
                bool       alignByGeometry = text.alignByGeometry;

                HorizontalWrapMode horizontalOverflow = text.horizontalOverflow;
                VerticalWrapMode   verticalOverflow   = text.verticalOverflow;
                bool     resizeTextForBestFit         = text.resizeTextForBestFit;
                Color    color         = text.color;
                Material material      = text.material;
                bool     raycastTarget = text.raycastTarget;

                DestroyImmediate(text);
                if (textI18N == null)
                {
                    textI18N = targetText.AddComponent <TextI18N>();
                }

                textI18N.TestString = childtext;
                textI18N.font       = childFont;

                if (childFont.name == "lantingTeHei")
                {
                    string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/secondfont.bytes");
                    textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                }
                else if (childFont.name == "huaWenYuanTi")
                {
                    string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/thirdfont.bytes");
                    textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                }
                else
                {
                    string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes");
                    textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                }

                textI18N.fontStyle            = childFontStyle;
                textI18N.fontSize             = childFontSize;
                textI18N.lineSpacing          = childSpacing;
                textI18N.supportRichText      = childRichText;
                textI18N.alignment            = childAlignment;
                textI18N.alignByGeometry      = alignByGeometry;
                textI18N.horizontalOverflow   = horizontalOverflow;
                textI18N.verticalOverflow     = verticalOverflow;
                textI18N.resizeTextForBestFit = resizeTextForBestFit;
                textI18N.color         = color;
                textI18N.material      = material;
                textI18N.raycastTarget = raycastTarget;
            }


            Debug.Log("<color='#CDEA11'>" + dict.Key + "</color>");

            PrefabUtility.ReplacePrefab(go, prefab);

            DestroyImmediate(go);

//            count++;
        }


        EditorUtility.ClearProgressBar();
    }
Esempio n. 8
0
    static void ReplaceAllText()
    {
        EditorUtility.ClearProgressBar();

        string[]      kFileList = Directory.GetFiles(Application.dataPath, "*.prefab", SearchOption.AllDirectories);
        List <string> pList     = new List <string>(kFileList);

        EditorUtility.DisplayProgressBar("提示", "替换中(0/" + pList.Count + ")", 0f);

        List <string> prefabList = new List <string>();

        foreach (var file in pList)
        {
            if (file.ToLower().Contains("resources") || file.ToLower().Contains("streamingassets"))
            {
                continue;
            }

            prefabList.Add(file);
        }

        int count = 0;

        foreach (string file in prefabList)
        {
            int    nPos          = file.IndexOf("Assets");
            string kTexAssetPath = file.Substring(nPos);

            GameObject prefab = AssetDatabase.LoadAssetAtPath(kTexAssetPath, typeof(GameObject)) as GameObject;

            GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
            if (go == null)
            {
                continue;
            }

            Text[] childrenText = go.transform.GetComponentsInChildren <Text>(true);
            foreach (var text in childrenText)
            {
                if (text.GetType().Name.Contains("TextI18N"))
                {
                    EditorUtility.DisplayDialog("Error!",
                                                go.name + "/" + FindPathEditor.GetChildPahth(go, text.gameObject) + "里面已经存在TextI18N",
                                                "Close");
                    return;
                }

                GameObject textParent = text.gameObject;

                string     childtext       = text.text;
                Font       childFont       = text.font;
                FontStyle  childFontStyle  = text.fontStyle;
                int        childFontSize   = text.fontSize;
                float      childSpacing    = text.lineSpacing;
                bool       childRichText   = text.supportRichText;
                TextAnchor childAlignment  = text.alignment;
                bool       alignByGeometry = text.alignByGeometry;

                HorizontalWrapMode horizontalOverflow = text.horizontalOverflow;
                VerticalWrapMode   verticalOverflow   = text.verticalOverflow;
                bool     resizeTextForBestFit         = text.resizeTextForBestFit;
                Color    color         = text.color;
                Material material      = text.material;
                bool     raycastTarget = text.raycastTarget;

                DestroyImmediate(text);

                TextI18N textI18N = textParent.AddComponent <TextI18N>();

                textI18N.TestString = childtext;
                textI18N.font       = childFont;

                if (childFont == null)
                {
                    string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes");
                    textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                }
                else
                {
                    if (childFont.name == "lantingTeHei")
                    {
                        string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/secondfont.bytes");
                        textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                    }
                    else if (childFont.name == "huaWenYuanTi")
                    {
                        string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/thirdfont.bytes");
                        textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                    }
                    else
                    {
                        string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes");
                        textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]);
                    }
                }

                textI18N.fontStyle            = childFontStyle;
                textI18N.fontSize             = childFontSize;
                textI18N.lineSpacing          = childSpacing;
                textI18N.supportRichText      = childRichText;
                textI18N.alignment            = childAlignment;
                textI18N.alignByGeometry      = alignByGeometry;
                textI18N.horizontalOverflow   = horizontalOverflow;
                textI18N.verticalOverflow     = verticalOverflow;
                textI18N.resizeTextForBestFit = resizeTextForBestFit;
                textI18N.color         = color;
                textI18N.material      = material;
                textI18N.raycastTarget = raycastTarget;
            }

            count++;

            PrefabUtility.ReplacePrefab(go, prefab);
            DestroyImmediate(go);

            EditorUtility.DisplayProgressBar("提示", "替换中(" + count + "/" + prefabList.Count + ")" + kTexAssetPath, 0f);
            Debug.Log("<color='#CDEA11'>" + kTexAssetPath + "</color>");
        }
        EditorUtility.ClearProgressBar();
    }