Skip to content

Commit

Permalink
update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
gmhevinci committed Feb 17, 2023
1 parent 69c7a51 commit 145ca93
Showing 1 changed file with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,51 @@ public class PackEffectTexture : IPackRule
{
private const string PackDirectory = "Assets/Effect/Textures/";

string IPackRule.GetBundleName(PackRuleData data)
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
{
string assetPath = data.AssetPath;
if (assetPath.StartsWith(PackDirectory) == false)
throw new Exception($"Only support folder : {PackDirectory}");

string assetName = Path.GetFileName(assetPath).ToLower();
string firstChar = assetName.Substring(0, 1);
return $"{PackDirectory}effect_texture_{firstChar}";
string bundleName = $"{PackDirectory}effect_texture_{firstChar}";
var packRuleResult = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return packRuleResult;
}

bool IPackRule.IsRawFilePackRule()
{
return false;
}
}

[DisplayName("打包视频(自定义)")]
public class PackVideo : IPackRule
{
public PackRuleResult GetPackRuleResult(PackRuleData data)
{
string bundleName = RemoveExtension(data.AssetPath);
string fileExtension = Path.GetExtension(data.AssetPath);
fileExtension = fileExtension.Remove(0, 1);
PackRuleResult result = new PackRuleResult(bundleName, fileExtension);
return result;
}

bool IPackRule.IsRawFilePackRule()
{
return true;
}

private string RemoveExtension(string str)
{
if (string.IsNullOrEmpty(str))
return str;

int index = str.LastIndexOf(".");
if (index == -1)
return str;
else
return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test"
}
}

0 comments on commit 145ca93

Please sign in to comment.