void DoTableAndEntryGUI(Rect rect, SerializedProperty property)
        {
            var        tableRef = new SerializedTableReference(property.FindPropertyRelative("tableReference"));
            var        entryRef = new SerializedTableEntryReference(property.FindPropertyRelative("tableEntryReference"));
            GUIContent valueLabel;

            if (tableRef.Reference.ReferenceType != TableReference.Type.Empty && entryRef.Reference.ReferenceType != TableEntryReference.Type.Empty)
            {
                LocalizationTableCollection collection = null;
                if (m_TableType == typeof(StringTable))
                {
                    collection = LocalizationEditorSettings.GetStringTableCollection(tableRef.Reference);
                }
                else
                {
                    collection = LocalizationEditorSettings.GetAssetTableCollection(tableRef.Reference);
                }
                valueLabel = new GUIContent($"{GetTableLabel(tableRef.Reference)}/{GetEntryLabel(entryRef.Reference, collection?.SharedData)}");
            }
            else
            {
                valueLabel = Styles.none;
            }

            var dropDownPosition = EditorGUI.PrefixLabel(rect, Styles.reference);

            if (EditorGUI.DropdownButton(dropDownPosition, valueLabel, FocusType.Passive))
            {
                Type assetType;
                if (m_TableType == typeof(AssetTable))
                {
                    var assetTableCollection = m_Collection as AssetTableCollection;
                    assetType = assetTableCollection.GetEntryAssetType(entryRef.Reference);
                }
                else
                {
                    assetType = typeof(string);
                }

                var treeSelection = new TableEntryTreeView(assetType, (c, e) =>
                {
                    entryRef.Reference = e != null ? e.Id : SharedTableData.EmptyId;
                    tableRef.Reference = c != null ? c.TableCollectionNameReference : default(TableReference);
                    property.serializedObject.ApplyModifiedProperties();
                });
                PopupWindow.Show(dropDownPosition, new TreeViewPopupWindow(treeSelection)
                {
                    Width = dropDownPosition.width
                });
            }
        }
Exemple #2
0
        static void GenerateLocalizedIcon(string filePath, Locale locale, LocalizedTexture localizedTexture)
        {
            if (localizedTexture.IsEmpty)
            {
                return;
            }

            var tableCollection = LocalizationEditorSettings.GetAssetTableCollection(localizedTexture.TableReference);
            var table           = tableCollection?.GetTable(locale.Identifier) as AssetTable;
            var entry           = table?.GetEntryFromReference(localizedTexture.TableEntryReference);

            if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue))
            {
                var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale);
                if (fallBack != null)
                {
                    GenerateLocalizedIcon(filePath, fallBack, localizedTexture);
                    return;
                }

                Debug.LogWarning($"Could not find a localized Icons for {locale} from {localizedTexture}");
                return;
            }
            var iconPath = AssetDatabase.GUIDToAssetPath(entry.Guid);

            if (string.IsNullOrEmpty(iconPath))
            {
                return;
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var texture = AssetDatabase.LoadAssetAtPath(iconPath, typeof(Texture2D)) as Texture2D;

            byte[] bytes = texture.EncodeToPNG();

            //Saving the Icon as ".png" file to gradle res folder
            File.WriteAllBytes(filePath, bytes);
        }