예제 #1
0
 /// <summary>
 /// 从Inspector的序列化字段m_PhrasesProp读取OriginalPhrases对象,根据该对象设置Language下拉菜单
 /// </summary>
 void SetupLanguages()
 {
     m_AvailableLanguages = new string[m_PhrasesProp.arraySize];
     for (int i = 0; i < m_AvailableLanguages.Length; i++)
     {
         SerializedProperty element         = m_PhrasesProp.GetArrayElementAtIndex(i);
         OriginalPhrases    originalPhrases = element.objectReferenceValue as OriginalPhrases;
         m_AvailableLanguages[i] = originalPhrases.language;
     }
 }
예제 #2
0
        void OriginalPhrasesSetup()
        {
            m_OriginalPhrases       = m_OriginalPhrasesProp.objectReferenceValue as OriginalPhrases;
            m_PhrasesProp.arraySize = m_OriginalPhrases.phrases.Count;

            serializedObject.ApplyModifiedProperties();

            for (int i = 0; i < m_PhrasesProp.arraySize; i++)
            {
                m_TranslatedPhrases.phrases[i].key = m_OriginalPhrases.phrases[i].key;
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (m_PhrasesProp.arraySize > 0 && AllOriginalPhrasesNonNull())
            {
                m_LanguageIndexProp.intValue = EditorGUILayout.Popup("Language", m_LanguageIndexProp.intValue, m_AvailableLanguages);

                OriginalPhrases selectedPhrases = m_Translator.phrases[m_LanguageIndexProp.intValue];
                for (int i = 0; i < selectedPhrases.phrases.Count; i++)
                {
                    Rect labelRect = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    labelRect.width *= 0.25f;

                    EditorGUI.LabelField(labelRect, selectedPhrases.phrases[i].key);

                    labelRect.x     += labelRect.width;
                    labelRect.width *= 3f;

                    EditorGUI.LabelField(labelRect, selectedPhrases.phrases[i].value);
                }
            }

            Rect phrasesNameRect = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight));

            phrasesNameRect.width *= 0.5f;

            m_PhrasesProp.isExpanded = EditorGUI.Foldout(phrasesNameRect, m_PhrasesProp.isExpanded, "Phrases");

            phrasesNameRect.x      += phrasesNameRect.width;
            m_PhrasesProp.arraySize = EditorGUI.IntField(phrasesNameRect, GUIContent.none, m_PhrasesProp.arraySize);

            if (m_PhrasesProp.isExpanded)
            {
                EditorGUI.indentLevel++;
                EditorGUI.BeginChangeCheck();
                for (int i = 0; i < m_PhrasesProp.arraySize; i++)
                {
                    SerializedProperty element = m_PhrasesProp.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(element);
                }
                if (EditorGUI.EndChangeCheck() && AllOriginalPhrasesNonNull())
                {
                    SetupLanguages();
                }
                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();
        }
예제 #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (m_PhrasesProp.arraySize > 0 && AllOriginalPhrasesNonNull())
            {
                #region DrawDefaultInspector
                // Loop through properties and create one field (including children) for each top level property.
                SerializedProperty property = serializedObject.GetIterator();
                bool expanded = true;
                while (property.NextVisible(expanded))
                {
                    if ("m_Script" == property.propertyPath)
                    {
                        using (new EditorGUI.DisabledScope("m_Script" == property.propertyPath))
                        {
                            EditorGUILayout.PropertyField(property, true);
                        }
                    }
                    expanded = false;
                }
                #endregion

                m_LanguageIndexProp.intValue = EditorGUILayout.Popup("Language", m_LanguageIndexProp.intValue, m_AvailableLanguages);

                OriginalPhrases selectedPhrases = m_Translator.phrases[m_LanguageIndexProp.intValue];
                for (int i = 0; i < selectedPhrases.phrases.Count; i++)
                {
                    Rect labelRect = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    labelRect.width *= 0.25f;

                    EditorGUI.LabelField(labelRect, selectedPhrases.phrases[i].key);

                    labelRect.x     += labelRect.width;
                    labelRect.width *= 3f;

                    EditorGUI.LabelField(labelRect, selectedPhrases.phrases[i].value);
                }
            }

            Rect phrasesNameRect = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight));
            phrasesNameRect.width *= 0.5f;

            m_PhrasesProp.isExpanded = EditorGUI.Foldout(phrasesNameRect, m_PhrasesProp.isExpanded, "Phrases");

            phrasesNameRect.x      += phrasesNameRect.width;
            m_PhrasesProp.arraySize = EditorGUI.IntField(phrasesNameRect, GUIContent.none, m_PhrasesProp.arraySize);

            if (m_PhrasesProp.isExpanded)
            {
                EditorGUI.indentLevel++;
                EditorGUI.BeginChangeCheck();
                for (int i = 0; i < m_PhrasesProp.arraySize; i++)
                {
                    SerializedProperty element = m_PhrasesProp.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(element);
                }
                if (EditorGUI.EndChangeCheck() && AllOriginalPhrasesNonNull())
                {
                    SetupLanguages();
                }
                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();
        }