public TableEntrySelected(LocalizedTable table, uint id, Locale locale, MetadataType supportedType)
 {
     m_Table        = table;
     m_Locale       = locale;
     m_KeyId        = id;
     m_MetadataType = new MetadataTypeAttribute(supportedType);
 }
Exemplo n.º 2
0
 void OnTableModified(LocalizedTableCollection col, LocalizedTable tbl)
 {
     if (col == m_Collection)
     {
         RefreshTables();
     }
 }
        protected override void RemoveTableFromAddressables(LocalizedTable table, bool createUndo)
        {
            if (table is AssetTable assetTable)
            {
                // This can be called when a table is about to be deleted or when it is removed from the collection.
                // If the asset is removed from the collection it will still exists but not be part of a build, essentially is is turned off.
                // A user may want to turn the asset back on at a later time and have all the assets restored, so when we remove the table we need
                // to keep its entries so that they can be added again.
                // We can do this by saving the state using JsonUtility and then restoring it afterwards.

                // Save the state
                var json = JsonUtility.ToJson(table);

                // We need to make a copy as the original will be modified as we remove each item.
                var valuesCopy = assetTable.Values.ToArray();
                foreach (var entry in valuesCopy)
                {
                    RemoveAssetFromTable(assetTable, entry.KeyId);
                }

                // Restore the entries
                JsonUtility.FromJsonOverwrite(json, table);
            }

            base.RemoveTableFromAddressables(table, createUndo);
        }
        public static void ShowWindow(LocalizedTable selectedTable)
        {
            var window = GetWindow <AssetTablesWindow>(false, "Asset Tables", true);

            window.minSize = k_MinWindowSize;
            window.Show();
            window.EditTable(selectedTable);
        }
        // Gets list of all text keys from table
        private static List <string> GetKeys(LocalizedTable table)
        {
            List <string> keys = new List <string>();

            foreach (SharedTableData.SharedTableEntry entry in table.SharedData.Entries)
            {
                keys.Add(entry.Key);
            }
            return(keys);
        }
 void OnTableRemovedFromCollection(LocalizedTableCollection collection, LocalizedTable table)
 {
     if (m_GuidToCollection != null)
     {
         if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(table, out var guid, out long _))
         {
             Debug.LogError("Failed to extract table guid: " + table?.name, table);
             return;
         }
         m_GuidToCollection.Remove(guid);
     }
 }
        public LocalizedTableCollection FindCollectionForTable(LocalizedTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(table, out var guid, out long _))
            {
                return(FindCollectionFromDependencyGuid(guid));
            }
            return(null);
        }
        /// <summary>
        /// Searches for the selectedTable in the AssetTableCollection list, if found it selects this collection and sends the value changeds event.
        /// </summary>
        /// <param name="selectedTable">Table to search for.</param>
        public void SetValueFromTable(LocalizedTable selectedTable)
        {
            var choices = GetChoices();

            foreach (var assetTableCollection in choices)
            {
                if (assetTableCollection.TableType == selectedTable.GetType() && assetTableCollection.TableName == selectedTable.TableName)
                {
                    value = assetTableCollection;
                    return;
                }
            }
        }
        public void EditTable(LocalizedTable selectedTable)
        {
            var toolbar = m_Root.Q <AssetTablesWindowToolbar>();

            toolbar.EditButton.value = true;
            m_AssetTablesField.SetValueFromTable(selectedTable);

            #if !UNITY_2019_1_OR_NEWER
            // If EditTable is called during OnEnable then the change event will not be sent.
            if (m_AssetTablesField.panel == null)
            {
                ShowTableEditor(m_AssetTablesField.value);
            }
            #endif
        }
Exemplo n.º 10
0
        public virtual void OnEnable()
        {
            Undo.undoRedoPerformed += ResolveTableCollection;
            LocalizationEditorSettings.EditorEvents.TableAddedToCollection     += OnCollectionTableChange;
            LocalizationEditorSettings.EditorEvents.TableRemovedFromCollection += OnCollectionTableChange;
            LocalizationEditorSettings.EditorEvents.CollectionAdded            += OnCollectionChange;
            LocalizationEditorSettings.EditorEvents.CollectionRemoved          += OnCollectionChange;

            if (target == null)
            {
                return;
            }

            m_TargetTable       = target as LocalizedTable;
            m_LocaleId          = serializedObject.FindProperty("m_LocaleId");
            m_SharedTableData   = serializedObject.FindProperty("m_SharedData");
            m_TableEditorButton = new GUIContent("Open Table Editor", EditorGUIUtility.ObjectContent(target, target.GetType()).image);
            ResolveTableCollection();
        }
Exemplo n.º 11
0
        protected virtual void AddOrUpdateAssetTableInternal(LocalizedTable table)
        {
            if (!EditorUtility.IsPersistent(table))
            {
                Debug.LogError("Only persistent assets can be addressable. The asset needs to be saved on disk.");
                return;
            }

            var aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(true);

            if (aaSettings == null)
            {
                return;
            }

            var isStringTable = table is StringTableBase;

            // Has the asset already been added?
            var guid  = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(table));
            var entry = aaSettings.FindAssetEntry(guid);

            if (entry == null)
            {
                var groupName = isStringTable ? StringTableGroupName : AssetTableGroupName;
                var group     = GetGroup(aaSettings, groupName, true);
                entry = aaSettings.CreateOrMoveEntry(guid, group, true);
            }

            entry.address = string.Format("{0} - {1}", table.LocaleIdentifier.Code, table.TableName);
            entry.labels.Clear(); // Locale may have changed so clear the old one.

            // Label the table type
            var label = isStringTable ? LocalizedStringDatabase.StringTableLabel : LocalizedAssetDatabase.AssetTableLabel;

            aaSettings.AddLabel(label);
            entry.SetLabel(label, true);

            // Label the locale
            aaSettings.AddLabel(table.LocaleIdentifier.Code);
            entry.SetLabel(table.LocaleIdentifier.Code, true);
        }
Exemplo n.º 12
0
 void OnCollectionTableChange(LocalizedTableCollection col, LocalizedTable table) => ResolveTableCollection();
Exemplo n.º 13
0
 /// <summary>
 /// Add or update the Addressables data for the table.
 /// Ensures the table is in the correct group and has all the required labels.
 /// </summary>
 /// <param name="table"></param>
 public static void AddOrUpdateAssetTable(LocalizedTable table)
 {
     Instance.AddOrUpdateAssetTableInternal(table);
 }
Exemplo n.º 14
0
 internal virtual void RaiseTableRemovedFromCollection(LocalizedTableCollection collection, LocalizedTable table) => TableRemovedFromCollection?.Invoke(collection, table);
Exemplo n.º 15
0
 internal virtual void RaiseTableAddedToCollection(LocalizedTableCollection collection, LocalizedTable table) => TableAddedToCollection?.Invoke(collection, table);