[feat] 添加跨平台资源收集

pull/62/head
Sayo 2023-01-30 12:07:34 +08:00
parent cc75594747
commit 6488e96127
4 changed files with 101 additions and 3 deletions

View File

@ -46,6 +46,16 @@ namespace YooAsset.Editor
public string AssetTags = string.Empty;
/// <summary>
/// 可寻址路径
/// </summary>
public string Address = string.Empty;
/// <summary>
/// 跨平台
/// </summary>
public bool IsMultiPlatform = false;
/// <summary>
/// 收集器是否有效
/// </summary>
@ -160,6 +170,20 @@ namespace YooAsset.Editor
{
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
{
if (IsMultiPlatform)
{
string platform = "Windows";
#if UNITY_ANDROID
platform = "Android";
#elif UNITY_IOS
platform = "iOS";
#elif UNITY_STANDALONE_OSX
platform = "OSX";
#endif
if (!assetPath.Contains(platform))
continue;
}
if (result.ContainsKey(assetPath) == false)
{
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
@ -281,7 +305,7 @@ namespace YooAsset.Editor
return string.Empty;
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName, Address, IsMultiPlatform));
return adressValue;
}
private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)

View File

@ -582,6 +582,18 @@ namespace YooAsset.Editor
label.style.width = 90;
elementBottom.Add(label);
}
{
var textField = new TextField();
textField.name = "TextField0";
textField.label = "Address";
textField.style.unityTextAlign = TextAnchor.MiddleLeft;
textField.style.flexGrow = 1f;
elementBottom.Add(textField);
var label = textField.Q<Label>();
textField.style.width = 200;
label.style.minWidth = 63;
}
{
var popupField = new PopupField<string>(_collectorTypeList, 0);
popupField.name = "PopupField0";
@ -611,6 +623,14 @@ namespace YooAsset.Editor
popupField.style.width = 150;
elementBottom.Add(popupField);
}
{
var IsMultiPlatform = new Toggle();
IsMultiPlatform.name = "IsMultiPlatform";
IsMultiPlatform.text = "MultiPlatform";
IsMultiPlatform.style.unityTextAlign = TextAnchor.MiddleCenter;
IsMultiPlatform.style.flexGrow = 0f;
elementTop.Add(IsMultiPlatform);
}
{
var textField = new TextField();
textField.name = "TextField1";
@ -674,6 +694,15 @@ namespace YooAsset.Editor
RemoveCollectorBtn_clicked(collector);
};
// Address
var textFiled0 = element.Q<TextField>("TextField0");
textFiled0.SetValueWithoutNotify(collector.Address);
textFiled0.RegisterValueChangedCallback(evt =>
{
collector.Address = evt.newValue;
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
});
// Collector Path
var objectField1 = element.Q<ObjectField>("ObjectField1");
objectField1.SetValueWithoutNotify(collectObject);
@ -750,6 +779,15 @@ namespace YooAsset.Editor
}
});
// MultiPlatform
var IsMultiPlatform = element.Q<Toggle>("IsMultiPlatform");
IsMultiPlatform.SetValueWithoutNotify(collector.IsMultiPlatform);
IsMultiPlatform.RegisterValueChangedCallback(evt =>
{
collector.IsMultiPlatform = evt.newValue;
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
});
// Tags
var textFiled1 = element.Q<TextField>("TextField1");
textFiled1.SetValueWithoutNotify(collector.AssetTags);
@ -796,7 +834,7 @@ namespace YooAsset.Editor
if (_enableAddressableToogle.value)
{
IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName);
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName, collector.Address, collector.IsMultiPlatform);
string addressValue = instance.GetAssetAddress(ruleData);
showInfo = $"[{addressValue}] {showInfo}";
}

View File

@ -31,4 +31,36 @@ namespace YooAsset.Editor
return $"{collectorName}_{fileName}";
}
}
[DisplayName("以Address+文件路径为定位地址")]
public class AddressByAddressAndFilePath : IAddressRule
{
string IAddressRule.GetAssetAddress(AddressRuleData data)
{
if (Path.HasExtension(data.CollectPath))
{
return data.Address;
}
else
{
string path = data.AssetPath.Replace(data.CollectPath, "");
if (data.IsMultiPlatform)
{
string platform = "Windows";
#if UNITY_ANDROID
platform = "Android";
#elif UNITY_IOS
platform = "iOS";
#elif UNITY_STANDALONE_OSX
platform = "OSX";
#endif
path = path.Replace($"{platform}/", "");
}
string fileName = Path.GetFileName(data.AssetPath);
return $"{data.Address}{path}";
}
}
}
}

View File

@ -6,12 +6,16 @@ namespace YooAsset.Editor
public string AssetPath;
public string CollectPath;
public string GroupName;
public string Address;
public bool IsMultiPlatform;
public AddressRuleData(string assetPath, string collectPath, string groupName)
public AddressRuleData(string assetPath, string collectPath, string groupName, string address, bool isMultiPlatform)
{
AssetPath = assetPath;
CollectPath = collectPath;
GroupName = groupName;
Address = address;
IsMultiPlatform = isMultiPlatform;
}
}