Merge pull request #62 from DumoeDss/main

[feat] 添加自定义Address规则与跨平台资源收集
pull/70/head
何冠峰 2023-02-22 17:10:03 +08:00 committed by GitHub
commit 5a98a68c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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>
@ -163,6 +173,20 @@ namespace YooAsset.Editor
{
if (IsValidateAsset(assetPath, isRawFilePackRule) && 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, isRawFilePackRule);
@ -305,7 +329,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(CollectCommand command, 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;
}
}