示例#1
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Check Variable for Valid MultiLanguageText Reference
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private static void CheckVariable(GameManager rGameManager, GameManager.SystemLanguages eChosenLanguage, ref MultiLanguageTextList[] alMultiLanguageTextItems, FieldInfo a_variable, int a_iCurrentSceneID, Component a_parent, object a_ContainingType, MultiLanguageTextReceiveMode eMultiLanguageTextReceiveMode, BindingFlags a_flags, string appendedName = "")
    {
        FieldInfo currentField = a_ContainingType.GetType().GetField(a_variable.Name);

        if (currentField == null)
        {
            return;
        }
        object currentObject = currentField.GetValue(a_ContainingType);


        if (a_variable.FieldType == typeof(MultiLanguageText))
        {
            CaptureMultiTextObject(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, currentObject as MultiLanguageText, a_iCurrentSceneID, a_parent, eMultiLanguageTextReceiveMode, a_variable.Name, appendedName);
        }
        else if (a_variable.FieldType == typeof(MultiLanguageText[]))
        {
            MultiLanguageText[] aTextComponents = currentObject as MultiLanguageText[];
            for (int j = 0; j < aTextComponents.Length; ++j)
            {
                CaptureMultiTextObject(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, aTextComponents[j] as MultiLanguageText, a_iCurrentSceneID, a_parent, eMultiLanguageTextReceiveMode, a_variable.Name, appendedName);
            }
        }
        else
        {
            // Keep Searching through all declared objects... I want EVERY Multi-Laguage Component
            CheckInnerDeclarations(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, a_variable, a_iCurrentSceneID, a_parent, a_ContainingType, eMultiLanguageTextReceiveMode, a_flags);
        }
    }
示例#2
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Check Variables INSIDE of a Class/Struct/Interface
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private static void CheckInnerDeclarations(GameManager rGameManager, GameManager.SystemLanguages eChosenLanguage, ref MultiLanguageTextList[] alMultiLanguageTextItems, FieldInfo a_declaration, int a_iCurrentSceneID, Component a_parent, object a_ContainingType, MultiLanguageTextReceiveMode eMultiLanguageTextReceiveMode, BindingFlags a_flags)
    {
        if (a_declaration.FieldType.IsArray)
        {
            object[] data = a_ContainingType.GetType().GetField(a_declaration.Name).GetValue(a_ContainingType) as object[];
            if (data != null)
            {
                for (int j = 0; j < data.Length; ++j)
                {
                    if (data[j] != null)
                    {
                        FieldInfo[] arrayFields = data[j].GetType().GetFields(a_flags);
                        foreach (FieldInfo info in arrayFields)
                        {
                            CheckVariable(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, info, a_iCurrentSceneID, a_parent, data[j], eMultiLanguageTextReceiveMode, a_flags, ((j + 1) < 100 ? "0" : "") + ((j + 1) < 10 ? "0" : "") + (j + 1).ToString());
                        }
                    }
                }
                return;
            }
        }

        // Check Fields
        FieldInfo[] fields = a_declaration.GetType().GetFields(a_flags);
        foreach (FieldInfo variable in fields)
        {
            CheckVariable(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, variable, a_iCurrentSceneID, a_parent, a_ContainingType, eMultiLanguageTextReceiveMode, a_flags);
        }
    }
示例#3
0
 private TextDisplayValues GetLanguageInstance(GameManager.SystemLanguages eSelectedLanguage)
 {
     if ((int)eSelectedLanguage >= m_arLanguageText.Length || m_arLanguageText[(int)eSelectedLanguage] == null)
     {
         return(null);
     }
     return(m_arLanguageText[(int)eSelectedLanguage]);
 }
示例#4
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get Font
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private Font GetFont(GameManager.SystemLanguages eSelectedLanguage)
    {
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance != null)
        {
            return((instance.chosenFont != null) ? instance.chosenFont : Resources.GetBuiltinResource <Font>("Arial.ttf"));
        }
        return(Resources.GetBuiltinResource <Font>("Arial.ttf"));
    }
示例#5
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get Position
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private Vector3 GetPosition(GameManager.SystemLanguages eSelectedLanguage)
    {
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance != null)
        {
            return(instance.fontPosition);
        }
        return(Vector3.zero);
    }
示例#6
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get FontSize
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private int GetFontSize(GameManager.SystemLanguages eSelectedLanguage)
    {
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance != null)
        {
            return(instance.fontSize);
        }
        else
        {
            if (m_arLanguageText.Length > (int)GameManager.SystemLanguages.ENGLISH && m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH] != null)
            {
                return(m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].fontSize);
            }
            return(0);
        }
    }
示例#7
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get Line Spacing
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private float GetLineSpacing(GameManager.SystemLanguages eSelectedLanguage)
    {
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance != null)
        {
            return(instance.lineSpacing);
        }
        else
        {
            if (m_arLanguageText.Length > (int)GameManager.SystemLanguages.ENGLISH && m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH] != null)
            {
                return(m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].lineSpacing);
            }
            return(0.0f);
        }
    }
示例#8
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get Text
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private string GetText(GameManager.SystemLanguages eSelectedLanguage)
    {
        // Show Error if LanguageID doesn't exist or does not have a valid value (only if debugging). If not debugging, show English version... Better than nothing?!
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance == null)
        {
#if UNITY_EDITOR
            Debug.LogError(GameManager.SelectedLanguage.ToString() + " NOT Available");
            return(GameManager.SelectedLanguage.ToString() + " NOT Available");
#else
            if (m_arLanguageText.Length > (int)GameManager.SystemLanguages.ENGLISH && m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH] != null)
            {
                return(m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text);
            }
            return(GameManager.SelectedLanguage.ToString() + " NOT Available");
#endif
        }
        return(instance.text);
    }
示例#9
0
    public void ApplyEffects(UnityEngine.UI.Text uiTextRenderer, GameManager.SystemLanguages selectedLanguage)
    {
        if (uiTextRenderer != null)
        {
            uiTextRenderer.font = GetFont(selectedLanguage);
            uiTextRenderer.text = GetText(selectedLanguage);
            uiTextRenderer.rectTransform.localPosition = GetPosition(selectedLanguage);
            int fontSize = GetFontSize(selectedLanguage);
            uiTextRenderer.resizeTextForBestFit = (fontSize == 0);
            uiTextRenderer.fontSize             = fontSize;
            uiTextRenderer.alignment            = GetTextAlignment(selectedLanguage, uiTextRenderer);

            float lineSpacing = GetLineSpacing(selectedLanguage);
            if (lineSpacing > 0.0f)
            {
                uiTextRenderer.lineSpacing = lineSpacing;
            }

            uiTextRenderer.horizontalOverflow = ((selectedLanguage == GameManager.SystemLanguages.ARABIC || selectedLanguage == GameManager.SystemLanguages.PERSIAN || selectedLanguage == GameManager.SystemLanguages.URDU) ? HorizontalWrapMode.Overflow : HorizontalWrapMode.Wrap);
        }
    }
示例#10
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Capture the MultiLanugageText Reference we found earlier
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private static void CaptureMultiTextObject(GameManager rGameManager, GameManager.SystemLanguages eChosenLanguage, ref MultiLanguageTextList[] alMultiLanguageTextItems, MultiLanguageText a_rMultiTextObject, int a_iCurrentSceneID, Component a_parent, MultiLanguageTextReceiveMode eMultiLanguageTextReceiveMode, string a_variableName, string appendedName = "")
    {
        if (eMultiLanguageTextReceiveMode == MultiLanguageTextReceiveMode.BLANK_ONLY)
        {
            if (a_rMultiTextObject.m_arLanguageText[(int)eChosenLanguage].text != "")
            {
                return;
            }
        }
        else if (eMultiLanguageTextReceiveMode == MultiLanguageTextReceiveMode.FILLED_ONLY)
        {
            if (a_rMultiTextObject.m_arLanguageText[(int)eChosenLanguage].text == "")
            {
                return;
            }
        }

        MultiLanguageTextInstanceInfo mlti = new MultiLanguageTextInstanceInfo();

        mlti.rInstance     = a_rMultiTextObject;
        mlti.rOwningParent = a_parent;

        Transform trans = a_parent.transform;

        mlti.sDisplayLabel = a_parent.name + "\\" + a_variableName + appendedName;
        while (trans != rGameManager.m_agoRootParentsOfMultiLanguageTextComponents[a_iCurrentSceneID].transform)
        {
            mlti.sDisplayLabel = trans.name + "\\" + mlti.sDisplayLabel;
            trans = trans.parent;
        }

        if (!alMultiLanguageTextItems[a_iCurrentSceneID].Contains(mlti))
        {
            alMultiLanguageTextItems[a_iCurrentSceneID].AddLast(mlti);
        }
    }
示例#11
0
    public TextAnchor GetTextAlignment(GameManager.SystemLanguages eSelectedLanguage, UnityEngine.UI.Text uiTextRenderer = null)
    {
        TextDisplayValues instance = GetLanguageInstance(eSelectedLanguage);

        if (instance != null)
        {
            if (uiTextRenderer != null)
            {
                switch (uiTextRenderer.alignment)
                {
                case TextAnchor.UpperCenter:
                case TextAnchor.UpperLeft:
                case TextAnchor.UpperRight:
                    switch (instance.textAlignment)
                    {
                    case TextAlignment.Center:      return(TextAnchor.UpperCenter);

                    case TextAlignment.Left:        return(TextAnchor.UpperLeft);

                    default:                                        return(TextAnchor.UpperRight);
                    }

                case TextAnchor.MiddleCenter:
                case TextAnchor.MiddleLeft:
                case TextAnchor.MiddleRight:
                    switch (instance.textAlignment)
                    {
                    case TextAlignment.Center:      return(TextAnchor.MiddleCenter);

                    case TextAlignment.Left:        return(TextAnchor.MiddleLeft);

                    default:                                        return(TextAnchor.MiddleRight);
                    }

                default:                 // LOWER!
                    switch (instance.textAlignment)
                    {
                    case TextAlignment.Center:      return(TextAnchor.LowerCenter);

                    case TextAlignment.Left:        return(TextAnchor.LowerLeft);

                    default:                                        return(TextAnchor.LowerRight);
                    }
                }
            }

            else
            {
                switch (instance.textAlignment)
                {
                case TextAlignment.Center:      return(TextAnchor.UpperCenter);

                case TextAlignment.Left:        return(TextAnchor.UpperLeft);

                default:                                        return(TextAnchor.UpperRight);
                }
            }
        }

        return(TextAnchor.UpperCenter);
    }
示例#12
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Scan for Multi-Language Text Components
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public static MultiLanguageTextList[] ScanForMultiLanguageTextComponents(GameManager rGameManager, GameManager.SystemLanguages eChosenLanguage, MultiLanguageTextReceiveMode eMultiLanguageTextReceiveMode)
    {
        // Declare Holders of Text Items - This is to sort them without having to use exspensive algorthms/RegularExpressions (Even though it doesn't matter so much in the CustomEditor classes).
        MultiLanguageTextList[] alMultiLanguageTextItems = new MultiLanguageTextList[rGameManager.m_agoRootParentsOfMultiLanguageTextComponents.Length];
        for (int i = 0; i < alMultiLanguageTextItems.Length; ++i)
        {
            alMultiLanguageTextItems[i] = new MultiLanguageTextList();
        }

        // Use #Reflection to identify Multi-Language Components found within script fields (i.e Variables) then capture those instances and use them here. Essentially compiling a database
        for (int i = 0; i < rGameManager.m_agoRootParentsOfMultiLanguageTextComponents.Length; ++i)
        {
            LinkedList <Transform> transformList = new LinkedList <Transform>();
            GetAllChildren(transformList, rGameManager.m_agoRootParentsOfMultiLanguageTextComponents[i].transform);
            const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
            foreach (Transform obj in transformList)
            {
                foreach (Component component in obj.GetComponents <Component>())
                {
                    FieldInfo[] fields = component.GetType().GetFields(flags);
                    foreach (FieldInfo variable in fields)
                    {
                        CheckVariable(rGameManager, eChosenLanguage, ref alMultiLanguageTextItems, variable, i, component, component, eMultiLanguageTextReceiveMode, flags);
                    }
                }
            }
        }

        return(alMultiLanguageTextItems);
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Static Method: Generate File
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public static void GenerateFile(LinkedList <CustomEditor_GameManager.MultiLanguageTextInstanceInfo> a_lMultiLanguageTextItems, GameManager.SystemLanguages a_eSelectedLanguage)
    {
        string saveFilename = EditorUtility.SaveFilePanel("Save File", @"C:\", "Multi-Language Text Generator", "xml");

        if (saveFilename != "")
        {
            string xmlString = CreateExcelDocument(a_lMultiLanguageTextItems, a_eSelectedLanguage);
            using (System.IO.StreamWriter textWriter = new System.IO.StreamWriter(saveFilename))
            {
                foreach (string line in xmlString.Split(new char[] { '\n' }))
                {
                    textWriter.WriteLine(line);
                }
            }
            EditorUtility.DisplayDialog("Success", "Text File Generation Successful\n\n\nFind the Generated File at: " + saveFilename, "Okay");
        }
        else
        {
            Debug.Log("TEXT FILE GENERATION CANCELLED");
        }
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Static Method: Create Excel Document
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private static string CreateExcelDocument(LinkedList <CustomEditor_GameManager.MultiLanguageTextInstanceInfo> a_lMultiLanguageTextItems, GameManager.SystemLanguages a_eSelectedLanguage)
    {
        LinkedList <string> lAlreadyAddedText       = new LinkedList <string>();
        const string        columnWidth             = "250";
        const float         defaultRowHeight        = 22.5f;
        const string        englishLabel            = "ENGLISH TEXT:&#10;&#10;";
        const string        englishLabelExplanation = "The text we're looking to get translated. Please do not change any of the text (even if there is something wrong with it gramatically) as the exact English in these boxes will be identified via script and will not work if you change anything";
        const string        contextLabel            = "CONTEXT FOR TEXT:&#10;&#10;";
        const string        contextLabelExplanation = "Please check the context before translating as it may help you better understand the tone we are looking for.";
        string translationLabel            = "Translation:&#10;&#10;";
        string translationLabelExplanation = "Please insert the language translation for " + GameManager.GetLanguageAsEnglishString(a_eSelectedLanguage) + " into the boxes below. We also ask that when you come across </Font><Font html:Color=\"#F26D7D\">coloured</Font><Font html:Color=\"#000000\"> English words that you also </Font><Font html:Color=\"#F26D7D\">colour</Font><Font html:Color=\"#000000\"> the translated phrase in the same colour.&#10;&#10;Please also remember that this app is intended for children. Child friendly text is preferred.";
        string xmlString = "<?xml version=\"1.0\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\nxmlns:o=\"urn:schemas-microsoft-com:office:office\"\n xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\nxmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"\n xmlns:html=\"http://www.w3.org/TR/REC-html40\">\n <DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\">\n  <Author>CDA</Author>\n  <LastAuthor>CDA</LastAuthor>\n  <Created>2016-01-28T05:58:23Z</Created>\n  <Version>12.00</Version>\n </DocumentProperties>\n <ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\">\n  <WindowHeight>12780</WindowHeight>\n  <WindowWidth>28695</WindowWidth>\n  <WindowTopX>120</WindowTopX>\n  <WindowTopY>60</WindowTopY>\n  <ProtectStructure>False</ProtectStructure>\n  <ProtectWindows>False</ProtectWindows>\n </ExcelWorkbook>\n <Styles>\n <Style ss:ID=\"Default\" ss:Name=\"Normal\">\n <Alignment ss:Vertical=\"Bottom\"/>\n <Borders/>\n <Font ss:FontName=\"Calibri\" x:Family=\"Swiss\" ss:Size=\"11\" ss:Color=\"#000000\"/>\n <Interior/>\n <NumberFormat/>\n <Protection/>\n </Style>\n <Style ss:ID=\"s65\">\n <Alignment ss:Horizontal=\"Left\" ss:Vertical=\"Center\" ss:WrapText=\"1\"/>\n </Style>\n </Styles>\n <Worksheet ss:Name=\"Sheet1\">\n";

        // Telling the Translator what the boxes are for~
        string identityString = "   <Row ss:AutoFitHeight=\"0\" ss:Height=\"150\">\n";

        identityString += "    <Cell ss:StyleID=\"s65\"><ss:Data ss:Type=\"String\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
        identityString += "<B><Font html:Color=\"#000000\">" + contextLabel + "</Font></B><Font html:Color=\"#000000\">" + contextLabelExplanation + "</Font></ss:Data></Cell>\n";
        identityString += "    <Cell ss:StyleID=\"s65\"><ss:Data ss:Type=\"String\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
        identityString += "<B><Font html:Color=\"#000000\">" + englishLabel + "</Font></B><Font html:Color=\"#000000\">" + englishLabelExplanation + "</Font></ss:Data></Cell>\n";
        identityString += "    <Cell ss:StyleID=\"s65\"><ss:Data ss:Type=\"String\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
        identityString += "<B><Font html:Color=\"#000000\">" + translationLabel + "</Font></B><Font html:Color=\"#000000\">" + translationLabelExplanation + "</Font></ss:Data></Cell>\n   </Row>\n";

        string dataString = "";
        int    indexID    = 0;

        foreach (CustomEditor_GameManager.MultiLanguageTextInstanceInfo displayedText in a_lMultiLanguageTextItems)
        {
            if (displayedText.rInstance.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text != "")
            {
                if (lAlreadyAddedText.Contains(displayedText.rInstance.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text.ToUpper()))
                {
                    continue;
                }
                else
                {
                    lAlreadyAddedText.AddLast(displayedText.rInstance.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text.ToUpper());
                    indexID += 1;
                }

                string rowHeight = (defaultRowHeight * (1 * Mathf.CeilToInt(Mathf.Max((float)displayedText.rInstance.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text.Split(new char[] { '\n' }).Length, ((float)displayedText.rInstance.dm_sTranslationDescription.Length / 47.0f))))).ToString();
                dataString += "   <Row ss:AutoFitHeight=\"0\" ss:Height=\"" + rowHeight + "\">\n";
                {
                    // ~~~ TEXT CONTEXT ~~~ //
                    {
                        dataString += "    <Cell ss:StyleID=\"s65\"><ss:Data ss:Type=\"String\" xmlns=\"http://www.w3.org/TR/REC-html40\"><Font html:Color=\"#000000\">";
                        dataString += displayedText.rInstance.dm_sTranslationDescription.Replace("\n", "&#10;").Replace("\"", "&quot;");
                        dataString += "</Font></ss:Data></Cell>\n";
                    }

                    // ~~~ ENGLISH TEXT ~~~ //
                    {
                        dataString += "    <Cell ss:StyleID=\"s65\"><ss:Data ss:Type=\"String\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
                        string[] colourDifferences = Regex.Split(displayedText.rInstance.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text, @"(<color=#[0-9a-zA-Z]{6}[0-9a-zA-Z]?[0-9a-zA-Z]?>.+?</color>)", RegexOptions.Multiline);
                        foreach (string colourPart in colourDifferences)
                        {
                            string[] lineDifferences = Regex.Replace(colourPart, @"<color=#[a-zA-Z0-9]+>", "").Replace("</color>", "").Split(new char[] { '\n', '\r' });
                            string   colourCode      = "000000";
                            Match    match           = Regex.Match(colourPart, @"<color=#([0-9a-zA-Z]{6})[0-9a-zA-Z]?[0-9a-zA-Z]?>", RegexOptions.Multiline);
                            if (match.Success)
                            {
                                colourCode = match.Groups[1].Value;
                            }

                            for (int i = 0; i < lineDifferences.Length; ++i)
                            {
                                dataString += "<Font html:Color=\"#" + colourCode + "\">";                                     // Define the Colour of the Text in Excel
                                if (i > 0)
                                {
                                    dataString += "&#10;";
                                }
                                dataString += lineDifferences[i];
                                dataString += "</Font>";
                            }
                        }
                        dataString += "</ss:Data></Cell>\n";
                    }
                }
                dataString += "   </Row>\n";
            }
        }


        string tableInfo = "  <Table x:FullColumns=\"1\" x:FullRows=\"1\" ss:DefaultRowHeight=\"15\">\n";

        for (int i = 0; i < 3; ++i)
        {
            tableInfo += "   <Column ss:AutoFitWidth=\"0\" ss:Width=\"" + columnWidth + "\"/>\n";
        }

        xmlString += tableInfo;
        xmlString += identityString;
        xmlString += dataString;


        xmlString += "  </Table>\n  <WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">\n   <PageSetup>\n    <Header x:Margin=\"0.3\"/>\n    <Footer x:Margin=\"0.3\"/>\n    <PageMargins x:Bottom=\"0.75\" x:Left=\"0.7\" x:Right=\"0.7\" x:Top=\"0.75\"/>\n   </PageSetup>\n   <Unsynced/>\n   <Print>\n    <ValidPrinterInfo/>\n    <PaperSizeIndex>9</PaperSizeIndex>\n    <HorizontalResolution>600</HorizontalResolution>\n    <VerticalResolution>600</VerticalResolution>\n   </Print>\n   <Selected/>\n   <Panes>\n    <Pane>\n     <Number>3</Number>\n     <ActiveRow>1</ActiveRow>\n     <ActiveCol>2</ActiveCol>\n    </Pane>\n   </Panes>\n   <ProtectObjects>False</ProtectObjects>\n   <ProtectScenarios>False</ProtectScenarios>\n  </WorksheetOptions>\n </Worksheet>\n </Workbook>";
        return(xmlString);
    }
示例#15
0
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //	* New Method: Is Language Available
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 public bool IsLanguageAvailable(GameManager.SystemLanguages eSelectedLanguage)
 {
     return(m_abAvailableLanguages[(int)eSelectedLanguage]);
 }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Static Method: Read From File
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public static void ReadFromFile(LinkedList <CustomEditor_GameManager.MultiLanguageTextInstanceInfo> a_lMultiLanguageTextItems, GameManager.SystemLanguages a_eSelectedLanguage)
    {
        string openFilename = (Application.dataPath + "/Multi-Language-Urdu-Updated.xml");

        if (!System.IO.File.Exists(openFilename))
        {
            openFilename = EditorUtility.OpenFilePanel("Open File", @"C:\", "xml");
        }
        if (openFilename != "")
        {
            using (System.IO.StreamReader textReader = new System.IO.StreamReader(openFilename))
            {
                m_sErrorMessage = "";
                Dictionary <string, string> translationData = ReadExcelDocument(textReader.ReadToEnd().Replace("\r", "").Replace("\n", ""));
                if (translationData != null)
                {
                    LinkedList <string>    lUnTranslatedComponenets = new LinkedList <string>();
                    LinkedList <Component> lDirtyComponentsList     = new LinkedList <Component>();
                    foreach (CustomEditor_GameManager.MultiLanguageTextInstanceInfo mlti in a_lMultiLanguageTextItems)
                    {
                        MultiLanguageText textComponent = mlti.rInstance;
                        if (!(textComponent.m_arLanguageText.Length > (int)a_eSelectedLanguage))
                        {
                            ResizeArray(ref textComponent.m_arLanguageText, (int)a_eSelectedLanguage + 1);
                        }

                        string sTranslation = Regex.Replace(textComponent.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].text.Replace("\n", "").Replace("\r", ""), @"<color=#[a-zA-Z0-9]+?>(.*?)</color>",
                                                            m =>
                        {
                            return((m.Groups.Count > 1 && m.Groups[1].Value != "") ? string.Format("{0}", m.Groups[1].Value) : "");
                        },
                                                            RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(" ", "").ToUpper();
                        if (translationData.ContainsKey(sTranslation))
                        {
                            // Assign Translation Fixes and Alignment!
                            switch (a_eSelectedLanguage)
                            {
                            case GameManager.SystemLanguages.ARABIC:
                            case GameManager.SystemLanguages.PERSIAN:
                            case GameManager.SystemLanguages.URDU:
                                sTranslation = RTLService.RTL.Convert(Regex.Replace(translationData[sTranslation], "<color=#[a-zA-Z0-9]+?>", "").Replace("</color>", ""));
                                //textComponent.m_arLanguageText[(int)a_eSelectedLanguage].textAlignment = TextAlignment.Right;
                                break;

                            case GameManager.SystemLanguages.CHINESE_SIMPLIFIED:
                            case GameManager.SystemLanguages.JAPANESE:
                                sTranslation = translationData[sTranslation];
                                break;

                            default:
                                textComponent.m_arLanguageText[(int)a_eSelectedLanguage].chosenFont = textComponent.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].chosenFont;
                                sTranslation = translationData[sTranslation];
                                break;
                            }
                            textComponent.m_arLanguageText[(int)a_eSelectedLanguage].text = sTranslation;

                            if (textComponent.m_arLanguageText[(int)a_eSelectedLanguage].fontPosition == Vector3.zero)
                            {
                                textComponent.m_arLanguageText[(int)a_eSelectedLanguage].fontPosition = textComponent.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].fontPosition;
                            }

                            if (textComponent.m_arLanguageText[(int)a_eSelectedLanguage].fontSize == 0)
                            {
                                textComponent.m_arLanguageText[(int)a_eSelectedLanguage].fontSize = textComponent.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].fontSize;
                            }

                            if (textComponent.m_arLanguageText[(int)a_eSelectedLanguage].lineSpacing == 0.0f)
                            {
                                textComponent.m_arLanguageText[(int)a_eSelectedLanguage].lineSpacing = textComponent.m_arLanguageText[(int)GameManager.SystemLanguages.ENGLISH].lineSpacing;
                            }

                            if (!lDirtyComponentsList.Contains(mlti.rOwningParent))
                            {
                                lDirtyComponentsList.AddLast(mlti.rOwningParent);
                            }
                        }
                        else
                        {
                            if (sTranslation != "")
                            {
                                lUnTranslatedComponenets.AddLast(mlti.sDisplayLabel);
                            }
                        }
                    }

                    if (lUnTranslatedComponenets.Count > 0)
                    {
                        string msg = "Non-Translated Components Count: " + lUnTranslatedComponenets.Count + "\n";
                        foreach (string s in lUnTranslatedComponenets)
                        {
                            msg += s + "\n";
                        }
                        Debug.LogWarning(msg);
                    }

                    foreach (Component c in lDirtyComponentsList)
                    {
                        if (c != null)
                        {
                            EditorUtility.SetDirty(c);
                        }
                    }

                    //EditorUtility.DisplayDialog("Success", "Load Successful. Check your Multi-Language Text Components to make sure everything imported correctly and looks nice.", "Okay");
                }

                if (m_sErrorMessage != "")
                {
                    Debug.LogError(m_sErrorMessage);
                }
            }
        }
        else
        {
            Debug.Log("TEXT FILE LOAD CANCELLED");
        }
    }
示例#17
0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* Overwritten Method: Draw Multi-Language Text System Options
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    protected void DrawMultiLanguageTextSystemOptions()
    {
        m_eSelectedLanguage = (GameManager.SystemLanguages)Mathf.Clamp((int)((GameManager.SystemLanguages)EditorGUILayout.EnumPopup(new GUIContent("Language To Edit: ", "The language which will be shown when a following button is pressed. If TOTAL_LANGUAGES is selected then each individual MultiLanguageText component will be able to select which language to display respectively"), m_eSelectedLanguage)), (int)GameManager.SystemLanguages.ENGLISH, (int)GameManager.SystemLanguages.TOTAL_LANGUAGES);
        AddSpaces(1);
        Rect rectPos = GetScaledRect();

        AddSpaces(3);
        if (m_eSelectedLanguage == GameManager.SystemLanguages.TOTAL_LANGUAGES)
        {
            rectPos.width /= 2;
            rectPos.x     += rectPos.width;
            if (GUI.Button(rectPos, new GUIContent("Show All Entries", "Show All Multi-Language Text components which may or may not contain data for the Selected Langauge")))
            {
                m_alMultiLanguageTextItems = ScanForMultiLanguageTextComponents(Target, m_eSelectedLanguage, MultiLanguageTextReceiveMode.ALL);
            }
        }
        else
        {
            rectPos.width /= 3;
            if (GUI.Button(rectPos, new GUIContent("Show Blank Entries", "Show remaining Multi-Language Text components which are missing data for the Selected Langauge")))
            {
                m_alMultiLanguageTextItems = ScanForMultiLanguageTextComponents(Target, m_eSelectedLanguage, MultiLanguageTextReceiveMode.BLANK_ONLY);
            }
            rectPos.x += rectPos.width;
            if (GUI.Button(rectPos, new GUIContent("Show All Entries", "Show All Multi-Language Text components which may or may not contain data for the Selected Langauge")))
            {
                m_alMultiLanguageTextItems = ScanForMultiLanguageTextComponents(Target, m_eSelectedLanguage, MultiLanguageTextReceiveMode.ALL);
            }
            rectPos.x += rectPos.width;
            if (GUI.Button(rectPos, new GUIContent("Show Completed Entries", "Show All Multi-Language Text components which currently contain data for the Selected Langauge")))
            {
                m_alMultiLanguageTextItems = ScanForMultiLanguageTextComponents(Target, m_eSelectedLanguage, MultiLanguageTextReceiveMode.FILLED_ONLY);
            }
        }


        if (m_alMultiLanguageTextItems != null)
        {
            bool valid = false;
            for (int i = 0; i < m_alMultiLanguageTextItems.Length; ++i)
            {
                if (m_alMultiLanguageTextItems[i].Count > 0)
                {
                    valid = true;
                    break;
                }
            }

            if (valid)
            {
                // Generate/Load Translation Files
                if (m_eSelectedLanguage != GameManager.SystemLanguages.ENGLISH)
                {
                    AddSpaces(2);
                    rectPos        = GetScaledRect();
                    rectPos.x     += rectPos.width;
                    rectPos.width  = 300.0f;
                    rectPos.height = 20.0f;
                    rectPos.x     -= rectPos.width;
                    if (GUI.Button(rectPos, new GUIContent("Generate Language Translation File for " + GameManager.GetLanguageAsEnglishString(m_eSelectedLanguage), "Generates a file that can be handed over to translators to perform language translation")))
                    {
                        GenerateLanguageTranslationFile();
                    }

                    AddSpaces(2);
                    rectPos.y += rectPos.height + 3;
                    if (GUI.Button(rectPos, new GUIContent("Read Language Translation File for " + GameManager.GetLanguageAsEnglishString(m_eSelectedLanguage), "Loads data from a specified xml document which contains data for this language")))
                    {
                        ReadDataFromLanguageTranslationFile();
                    }
                }



                GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout);
                foldoutStyle.normal.textColor   = new Color32(72, 164, 26, 255);
                foldoutStyle.onActive.textColor = new Color32(0, 0, 255, 255);
                int itemsCount = 1;
                for (int i = 0; i < m_alMultiLanguageTextItems.Length; ++i)
                {
                    AddSpaces(3);
                    foreach (MultiLanguageTextInstanceInfo mlti in m_alMultiLanguageTextItems[i])
                    {
                        string prefix = ((itemsCount < 1000 ? "0" : "") + (itemsCount < 100 ? "0" : "") + (itemsCount < 10 ? "0" : "") + itemsCount) + " ~ ";
                        mlti.bShowDisplay = EditorGUI.Foldout(GetScaledRect(), mlti.bShowDisplay, prefix + mlti.sDisplayLabel, true, foldoutStyle);
                        AddSpaces(3);
                        if (mlti.bShowDisplay)
                        {
                            DrawSplitter();
                            AddSpaces(1);
                            DrawMultiLanguageText(mlti.rInstance, m_eSelectedLanguage);
                            AddSpaces(5);
                        }

                        itemsCount += 1;
                    }
                }
            }
            else
            {
                GUIStyle fontstyle = new GUIStyle(EditorStyles.boldLabel);
                fontstyle.normal.textColor = new Color32(43, 82, 174, 255);
                fontstyle.alignment        = TextAnchor.UpperCenter;
                AddSpaces(3);
                EditorGUI.LabelField(GetScaledRect(), "No \"Multi-Language Text Components\" Were Found Under The Selected Setting(s)!", fontstyle);
                AddSpaces(3);
            }
        }
    }