Пример #1
0
        public override void OnEnter()
        {
            var ok = false;

            var go = Fsm.GetOwnerDefaultTarget(GameObject);

            if (go != null)
            {
                mLocalize = go.GetComponent <Localize> ();
            }

            if (mLocalize != null)
            {
                if (string.IsNullOrEmpty(SecondaryTerm.Value))
                {
                    mLocalize.SetTerm(PrimaryTerm.Value);
                }
                else
                {
                    mLocalize.SetTerm(PrimaryTerm.Value, SecondaryTerm.Value);
                }

                ok = true;
            }


            if (!success.IsNone)
            {
                success.Value = ok;
            }

            Fsm.Event(ok ? successEvent : failureEvent);

            Finish();
        }
 public static void SetRandomTerm(this Localize localize, string[] terms)
 {
     if (terms.Length > 0)
     {
         localize.SetTerm(terms[Random.Range(0, terms.Length)]);
     }
 }
        public static void SetRandomTerm(this Localize localize, string prefix)
        {
            var allTerms     = LocalizationManager.GetTermsList();
            var matchedTerms = new List <string>();

            foreach (var term in allTerms)
            {
                if (term.StartsWith(prefix))
                {
                    matchedTerms.Add(term);
                }
            }
            if (matchedTerms.Count > 0)
            {
                localize.SetTerm(matchedTerms[Random.Range(0, matchedTerms.Count)]);
            }
        }
Пример #4
0
        bool OnGUI_SelectKey(ref string Term, bool Inherited)            // Inherited==true means that the mTerm is empty and we are using the Label.text instead
        {
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();

            GUI.changed       = false;
            mAllowEditKeyName = GUILayout.Toggle(mAllowEditKeyName, "Term:", EditorStyles.foldout, GUILayout.ExpandWidth(false));
            if (GUI.changed && mAllowEditKeyName)
            {
                mNewKeyName = Term;
                mTermsArray = null;
            }

            bool bChanged = false;

            if (mTermsArray == null || (Term != "-" && System.Array.IndexOf(mTermsArray, Term) < 0))
            {
                UpdateTermsList(Term);
            }

            if (Inherited)
            {
                GUI.contentColor = Color.Lerp(Color.gray, Color.yellow, 0.1f);
            }

            int Index = (Term == "-" || Term == "") ? mTermsArray.Length - 1 : System.Array.IndexOf(mTermsArray, Term);

            GUI.changed = false;

            int newIndex = EditorGUILayout.Popup(Index, mTermsArray);

            GUI.contentColor = Color.white;
            if (/*newIndex != Index && newIndex>=0*/ GUI.changed)
            {
                GUI.changed = false;
                if (mLocalize.Source != null && newIndex == mTermsArray.Length - 4)  //< show terms from all sources >
                {
                    mLocalize.Source = null;
                    mTermsArray      = null;
                }
                else
                if (newIndex == mTermsArray.Length - 2)  //<inferred from text>
                {
                    mNewKeyName = Term = string.Empty;
                }
                else
                if (newIndex == mTermsArray.Length - 1)  //<none>
                {
                    mNewKeyName = Term = "-";
                }
                else
                {
                    mNewKeyName = Term = mTermsArray[newIndex];
                }


                if (GUI_SelectedTerm == 0)
                {
                    mLocalize.SetTerm(mNewKeyName);
                }
                else
                {
                    mLocalize.SetTerm(null, mNewKeyName);
                }
                mAllowEditKeyName = false;
                bChanged          = true;
            }

            LanguageSourceData source   = LocalizationManager.GetSourceContaining(Term);
            TermData           termData = source.GetTermData(Term);

            if (termData != null)
            {
                if (Inherited)
                {
                    bChanged = true;                     // if the term its inferred and a matching term its found, then use that
                }
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termData.TermType, GUILayout.Width(90));
                if (termData.TermType != NewType)
                {
                    termData.TermType = NewType;
                }
            }

            GUILayout.EndHorizontal();

            if (mAllowEditKeyName)
            {
                GUILayout.BeginHorizontal(GUILayout.Height(1));
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (mNewKeyName == null)
                {
                    mNewKeyName = string.Empty;
                }

                GUI.changed = false;
                mNewKeyName = EditorGUILayout.TextField(mNewKeyName, new GUIStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true));
                if (GUI.changed)
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    GUI.changed = false;
                }

                if (GUILayout.Button(string.Empty, string.IsNullOrEmpty(mNewKeyName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth(false)))
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    mNewKeyName = string.Empty;
                }

                GUILayout.EndHorizontal();

                string ValidatedName = mNewKeyName;
                LanguageSourceData.ValidateFullTerm(ref ValidatedName);

                bool CanUseNewName = (source.GetTermData(ValidatedName) == null);
                GUI.enabled = (!string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName = ValidatedName;
                    mTermsArray = null;                         // this recreates that terms array

                    LanguageSourceData Source = null;
                                        #if UNITY_EDITOR
                    if (mLocalize.Source != null)
                    {
                        Source = mLocalize.Source.SourceData;
                    }
                                        #endif

                    if (Source == null)
                    {
                        Source = LocalizationManager.Sources[0];
                    }
                    Term = mNewKeyName;
                    var data = Source.AddTerm(mNewKeyName, eTermType.Text, false);
                    if (data.Languages.Length > 0)
                    {
                        data.Languages[0] = mLocalize.GetMainTargetsText();
                    }
                    Source.Editor_SetDirty();
                    AssetDatabase.SaveAssets();
                    mAllowEditKeyName          = false;
                    bChanged                   = true;
                    GUIUtility.keyboardControl = 0;
                }
                GUI.enabled = (termData != null && !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button(new GUIContent("Rename", "Renames the term in the source and updates every object using it in the current scene"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName       = ValidatedName;
                    Term              = mNewKeyName;
                    mTermsArray       = null;                 // this recreates that terms array
                    mAllowEditKeyName = false;
                    bChanged          = true;
                    LocalizationEditor.TermReplacements = new Dictionary <string, string>(System.StringComparer.Ordinal);
                    LocalizationEditor.TermReplacements[termData.Term] = mNewKeyName;
                    termData.Term = mNewKeyName;
                    source.UpdateDictionary(true);
                    LocalizationEditor.ReplaceTermsInCurrentScene();
                    GUIUtility.keyboardControl = 0;
                    EditorApplication.update  += LocalizationEditor.DoParseTermsInCurrentScene;
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                bChanged |= OnGUI_SelectKey_PreviewTerms(ref Term);
            }

            GUILayout.Space(5);
            return(bChanged);
        }
Пример #5
0
        bool OnGUI_SelectKey(ref string Term, bool Inherited)            // Inherited==true means that the mTerm is empty and we are using the Label.text instead
        {
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();

            bool bChanged = false;

            mAllowEditKeyName = GUILayout.Toggle(mAllowEditKeyName, "Term:", EditorStyles.foldout, GUILayout.ExpandWidth(false));
            if (bChanged && mAllowEditKeyName)
            {
                mNewKeyName = Term;
            }

            bChanged = false;

            if (mTermsArray == null || System.Array.IndexOf(mTermsArray, Term) < 0)
            {
                UpdateTermsList(Term);
            }

            if (Inherited)
            {
                GUI.contentColor = Color.yellow * 0.8f;
            }

            int Index = System.Array.IndexOf(mTermsArray, Term);

            GUI.changed = false;

            int newIndex = EditorGUILayout.Popup(Index, mTermsArray);

            GUI.contentColor = Color.white;
            if (/*newIndex != Index && newIndex>=0*/ GUI.changed)
            {
                GUI.changed = false;
                mTermsArray [mTermsArray.Length - 1] = string.Empty;
                mNewKeyName = Term = mTermsArray[newIndex];
                if (GUI_SelectedTerm == 0)
                {
                    mLocalize.SetTerm(mNewKeyName);
                }
                else
                {
                    mLocalize.SetTerm(null, mNewKeyName);
                }
                mAllowEditKeyName = false;
                bChanged          = true;
            }
            LanguageSource source   = LocalizationManager.GetSourceContaining(Term);
            TermData       termData = source.GetTermData(Term);

            if (termData != null)
            {
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termData.TermType, GUILayout.Width(90));
                if (termData.TermType != NewType)
                {
                    termData.TermType = NewType;
                }
            }

            GUILayout.EndHorizontal();

            if (mAllowEditKeyName)
            {
                GUILayout.BeginHorizontal(GUILayout.Height(1));
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (mNewKeyName == null)
                {
                    mNewKeyName = string.Empty;
                }

                GUI.changed = false;
                mNewKeyName = EditorGUILayout.TextField(mNewKeyName, new GUIStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true));
                if (GUI.changed)
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    GUI.changed = false;
                }

                if (GUILayout.Button(string.Empty, string.IsNullOrEmpty(mNewKeyName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth(false)))
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    mNewKeyName = string.Empty;
                }

                GUILayout.EndHorizontal();

                string ValidatedName = mNewKeyName;
                LanguageSource.ValidateFullTerm(ref ValidatedName);

                bool CanUseNewName = (source.GetTermData(ValidatedName) == null);
                GUI.enabled = (!string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName = ValidatedName;
                    Term        = mNewKeyName;
                    mTermsArray = null;                         // this recreates that terms array

                    LanguageSource Source = null;
                                        #if UNITY_EDITOR
                    if (mLocalize.Source != null)
                    {
                        Source = mLocalize.Source;
                    }
                                        #endif

                    if (Source == null)
                    {
                        Source = LocalizationManager.Sources[0];
                    }

                    Source.AddTerm(mNewKeyName, eTermType.Text);
                    mAllowEditKeyName          = false;
                    bChanged                   = true;
                    GUIUtility.keyboardControl = 0;
                }
                GUI.enabled = (termData != null && !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button(new GUIContent("Rename", "Renames the term in the source and updates every object using it in the current scene"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName       = ValidatedName;
                    Term              = mNewKeyName;
                    mTermsArray       = null;                 // this recreates that terms array
                    mAllowEditKeyName = false;
                    bChanged          = true;
                    LocalizationEditor.TermReplacements = new Dictionary <string, string>();
                    LocalizationEditor.TermReplacements[termData.Term] = mNewKeyName;
                    termData.Term = mNewKeyName;
                    source.UpdateDictionary(true);
                    LocalizationEditor.ReplaceTermsInCurrentScene();
                    GUIUtility.keyboardControl = 0;
                    EditorApplication.update  += LocalizationEditor.DoParseTermsInCurrentScene;
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                bChanged |= OnGUI_SelectKey_PreviewTerms(ref Term);
            }

            GUILayout.Space(5);
            return(bChanged);
        }
Пример #6
0
 void ChangeQuote(string quote)
 {
     qLocalize.SetTerm(quote);
     aLocalize.SetTerm(quote);
     dLocalize.SetTerm(quote);
 }