143 lines
3.2 KiB
C#
143 lines
3.2 KiB
C#
#if UNITY_EDITOR
|
|
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.AddressableAssets;
|
|
using UnityEditor.AddressableAssets.Settings;
|
|
using UnityEngine;
|
|
|
|
public static class FixGameAddressables
|
|
{
|
|
private const string GamesFolder =
|
|
"Assets/RemoteResources/Games";
|
|
|
|
private const string GroupName =
|
|
"RemoteGames";
|
|
|
|
[MenuItem(
|
|
"Tools/Addressables/Corrigir endereços dos jogos"
|
|
)]
|
|
public static void FixAddresses()
|
|
{
|
|
AddressableAssetSettings settings =
|
|
AddressableAssetSettingsDefaultObject.Settings;
|
|
|
|
if (settings == null)
|
|
{
|
|
Debug.LogError(
|
|
"AddressableAssetSettings não encontrado. " +
|
|
"Abra a janela Addressables e crie as configurações."
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
AddressableAssetGroup group =
|
|
settings.FindGroup(GroupName);
|
|
|
|
if (group == null)
|
|
{
|
|
group = settings.CreateGroup(
|
|
GroupName,
|
|
false,
|
|
false,
|
|
false,
|
|
null
|
|
);
|
|
}
|
|
|
|
string[] guids = AssetDatabase.FindAssets(
|
|
"t:GameObject",
|
|
new[] { GamesFolder }
|
|
);
|
|
|
|
int configured = 0;
|
|
|
|
foreach (string guid in guids)
|
|
{
|
|
string assetPath =
|
|
AssetDatabase.GUIDToAssetPath(guid);
|
|
|
|
string fileName =
|
|
Path.GetFileNameWithoutExtension(assetPath);
|
|
|
|
// Apenas os prefabs principais usados no carregamento.
|
|
if (
|
|
fileName != "Info" &&
|
|
fileName != "Game"
|
|
)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
AddressableAssetEntry entry =
|
|
settings.CreateOrMoveEntry(
|
|
guid,
|
|
group,
|
|
false,
|
|
false
|
|
);
|
|
|
|
string address =
|
|
ConvertToGameAddress(assetPath);
|
|
|
|
entry.address = address;
|
|
|
|
Debug.Log(
|
|
"Addressable configurado: " +
|
|
address +
|
|
" -> " +
|
|
assetPath
|
|
);
|
|
|
|
configured++;
|
|
}
|
|
|
|
settings.SetDirty(
|
|
AddressableAssetSettings.ModificationEvent
|
|
.EntryMoved,
|
|
null,
|
|
true,
|
|
true
|
|
);
|
|
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log(
|
|
"Configuração concluída. " +
|
|
configured +
|
|
" prefabs Game/Info configurados."
|
|
);
|
|
}
|
|
|
|
private static string ConvertToGameAddress(
|
|
string assetPath)
|
|
{
|
|
const string prefix =
|
|
"Assets/RemoteResources/";
|
|
|
|
string address = assetPath;
|
|
|
|
if (address.StartsWith(prefix))
|
|
{
|
|
address =
|
|
address.Substring(prefix.Length);
|
|
}
|
|
|
|
string extension =
|
|
Path.GetExtension(address);
|
|
|
|
if (!string.IsNullOrEmpty(extension))
|
|
{
|
|
address = address.Substring(
|
|
0,
|
|
address.Length - extension.Length
|
|
);
|
|
}
|
|
|
|
return address.Replace("\\", "/");
|
|
}
|
|
}
|
|
|
|
#endif |