Skip to content

Commit

Permalink
Merge pull request #62 from k-youki/fix/restraint_post_event
Browse files Browse the repository at this point in the history
add: control postevent arg to update aa setting method
  • Loading branch information
Haruma-K authored Oct 8, 2024
2 parents 5a7d405 + 8a506e3 commit 364004c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ private bool TryAddEntry(
// Set group and address.
var entryAdapter =
_addressableSettingsAdapter.CreateOrMoveEntry(addressableGroupName, assetGuid, invokeModificationEvent);
entryAdapter.SetAddress(address);
entryAdapter.SetAddress(address, invokeModificationEvent);

// Add labels to addressable settings if not exists.
var labels = _layoutRule.ProvideLabels(assetPath, assetType, isFolder, doSetup);
var addressableLabels = _addressableSettingsAdapter.GetLabels();
foreach (var label in labels)
if (!addressableLabels.Contains(label))
_addressableSettingsAdapter.AddLabel(label);
_addressableSettingsAdapter.AddLabel(label, invokeModificationEvent);

// Remove old labels.
var oldLabels = entryAdapter.Labels.ToArray();
foreach (var label in oldLabels)
entryAdapter.SetLabel(label, false);
entryAdapter.SetLabel(label, false, invokeModificationEvent);

// Add new labels.
foreach (var label in labels)
entryAdapter.SetLabel(label, true);
entryAdapter.SetLabel(label, true, invokeModificationEvent);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public IReadOnlyList<string> GetLabels()
}

/// <inheritdoc />
public void AddLabel(string label)
public void AddLabel(string label, bool invokeModificationEvent)
{
_settings.AddLabel(label);
_settings.AddLabel(label, invokeModificationEvent);
}

/// <inheritdoc />
public void RemoveLabel(string label)
public void RemoveLabel(string label, bool invokeModificationEvent)
{
_settings.RemoveLabel(label);
_settings.RemoveLabel(label, invokeModificationEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public AddressableAssetEntryAdapter(AddressableAssetEntry entry)
public string GroupName => _entry.parentGroup.Name;

/// <inheritdoc />
public void SetAddress(string address)
public void SetAddress(string address, bool invokeModificationEvent)
{
_entry.SetAddress(address);
_entry.SetAddress(address, invokeModificationEvent);
}

/// <inheritdoc />
public bool SetLabel(string label, bool enable)
public bool SetLabel(string label, bool enable, bool invokeModificationEvent)
{
return _entry.SetLabel(label, enable);
return _entry.SetLabel(label, enable, postEvent:invokeModificationEvent);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using UnityEditor.AddressableAssets.Settings;

namespace SmartAddresser.Editor.Foundation.AddressableAdapter
{
Expand Down Expand Up @@ -26,14 +27,22 @@ public interface IAddressableAssetEntryAdapter
/// Set a address of the entry.
/// </summary>
/// <param name="address"></param>
void SetAddress(string address);
/// <param name="invokeModificationEvent">
/// If true, call <see cref="AddressableAssetSettings.OnModification" /> after
/// creating or moving.
/// </param>
void SetAddress(string address, bool invokeModificationEvent);

/// <summary>
/// Set or unset a label on this entry.
/// </summary>
/// <param name="label">The label name.</param>
/// <param name="enable">Setting to true will add the label, false will remove it.</param>
/// <param name="invokeModificationEvent">
/// If true, call <see cref="AddressableAssetSettings.OnModification" /> after
/// creating or moving.
/// </param>
/// <returns></returns>
bool SetLabel(string label, bool enable);
bool SetLabel(string label, bool enable, bool invokeModificationEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,20 @@ public interface IAddressableAssetSettingsAdapter
/// Add a new label.
/// </summary>
/// <param name="label">The label name.</param>
void AddLabel(string label);
/// <param name="invokeModificationEvent">
/// If true, call <see cref="AddressableAssetSettings.OnModification" /> after
/// creating or moving.
/// </param>
void AddLabel(string label, bool invokeModificationEvent);

/// <summary>
/// Remove a label by name.
/// </summary>
/// <param name="label">The label name.</param>
void RemoveLabel(string label);
/// <param name="invokeModificationEvent">
/// If true, call <see cref="AddressableAssetSettings.OnModification" /> after
/// creating or moving.
/// </param>
void RemoveLabel(string label, bool invokeModificationEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public FakeAddressableAssetEntryAdapter(IEnumerable<string> labels = null)
public string GroupName { get; private set; }

/// <inheritdoc />
public void SetAddress(string address)
public void SetAddress(string address, bool _)
{
Address = address;
}

/// <inheritdoc />
public bool SetLabel(string label, bool enable)
public bool SetLabel(string label, bool enable, bool _)
{
if (enable)
return Labels.Add(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public IReadOnlyList<string> GetLabels()
}

/// <inheritdoc />
public void AddLabel(string label)
public void AddLabel(string label, bool _)
{
_labels.Add(label);
}

/// <inheritdoc />
public void RemoveLabel(string label)
public void RemoveLabel(string label, bool _)
{
_labels.Remove(label);
}
Expand Down

0 comments on commit 364004c

Please sign in to comment.