Skip to content

Commit

Permalink
optimized MediaFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Aug 24, 2023
1 parent 277cff3 commit 75bd310
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);

// 1. 检测配置合法性
AssetBundleCollectorSettingData.Setting.CheckConfigError();
AssetBundleCollectorSettingData.Setting.CheckPackageConfigError(packageName);

// 2. 获取所有收集器收集的资源
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,13 @@ private List<string> GetAllDependencies(string mainAssetPath)
List<string> result = new List<string>(depends.Length);
foreach (string assetPath in depends)
{
// 注意:排除主资源对象
if (assetPath == mainAssetPath)
continue;

if (IsValidateAsset(assetPath, false))
{
// 注意:排除主资源对象
if (assetPath != mainAssetPath)
result.Add(assetPath);
result.Add(assetPath);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ public void ClearAll()
}

/// <summary>
/// 检测配置错误
/// 检测包裹配置错误
/// </summary>
public void CheckConfigError()
public void CheckPackageConfigError(string packageName)
{
var package = GetPackage(packageName);
package.CheckConfigError();
}

/// <summary>
/// 检测所有配置错误
/// </summary>
public void CheckAllPackageConfigError()
{
foreach (var package in Packages)
{
Expand All @@ -72,9 +81,9 @@ public void CheckConfigError()
}

/// <summary>
/// 修复配置错误
/// 修复所有配置错误
/// </summary>
public bool FixConfigError()
public bool FixAllPackageConfigError()
{
bool isFixed = false;
foreach (var package in Packages)
Expand All @@ -92,16 +101,8 @@ public bool FixConfigError()
/// </summary>
public List<string> GetPackageAllTags(string packageName)
{
foreach (var package in Packages)
{
if (package.PackageName == packageName)
{
return package.GetAllTags();
}
}

Debug.LogWarning($"Not found package : {packageName}");
return new List<string>();
var package = GetPackage(packageName);
return package.GetAllTags();
}

/// <summary>
Expand All @@ -112,19 +113,25 @@ public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
if (string.IsNullOrEmpty(packageName))
throw new Exception("Build package name is null or mepty !");

var package = GetPackage(packageName);
CollectCommand command = new CollectCommand(buildMode, packageName,
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}

/// <summary>
/// 获取包裹类
/// </summary>
public AssetBundleCollectorPackage GetPackage(string packageName)
{
foreach (var package in Packages)
{
if (package.PackageName == packageName)
{
CollectCommand command = new CollectCommand(buildMode, packageName,
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
return package;
}

throw new Exception($"Not found collector pacakge : {packageName}");
throw new Exception($"Not found pacakge : {packageName}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static void SaveFile()
/// </summary>
public static void FixFile()
{
bool isFixed = Setting.FixConfigError();
bool isFixed = Setting.FixAllPackageConfigError();
if (isFixed)
{
IsDirty = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static void OpenWindow()
private List<RuleDisplayName> _filterRuleList;

private Button _settingsButton;
private VisualElement _helpBoxContainer;
private VisualElement _setting1Container;
private VisualElement _setting2Container;
private Toggle _showPackageToogle;
Expand Down Expand Up @@ -82,6 +83,9 @@ public void CreateGUI()

visualAsset.CloneTree(root);

// 警示栏
_helpBoxContainer = root.Q("HelpBoxContainer");

// 公共设置相关
_settingsButton = root.Q<Button>("SettingsButton");
_settingsButton.clicked += SettingsBtn_clicked;
Expand Down Expand Up @@ -328,6 +332,24 @@ private void RefreshWindow()
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);

// 警示框
_helpBoxContainer.Clear();
if (_enableAddressableToogle.value && _locationToLowerToogle.value)
{
var helpBox = new HelpBox("无法同时开启[Enable Addressable]选项和[Location To Lower]选项", HelpBoxMessageType.Error);
_helpBoxContainer.Add(helpBox);
}
if (AssetBundleCollectorSettingData.Setting.Packages.Count > 1 && _uniqueBundleNameToogle.value == false)
{
var helpBox = new HelpBox("检测到当前配置存在多个Package,建议开启[Unique Bundle Name]选项", HelpBoxMessageType.Warning);
_helpBoxContainer.Add(helpBox);
}
if (_helpBoxContainer.childCount > 0)
_helpBoxContainer.style.display = DisplayStyle.Flex;
else
_helpBoxContainer.style.display = DisplayStyle.None;

// 设置栏
if (_showSettings)
{
_setting1Container.style.display = DisplayStyle.Flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
<ui:Button text="Settings" display-tooltip-when-elided="true" name="SettingsButton" />
<ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,24 @@ private void TopBar4_clicked()
private void FillIncludeListView(ReportBundleInfo bundleInfo)
{
List<ReportAssetInfo> containsList = new List<ReportAssetInfo>();
HashSet<string> mainAssetDic = new HashSet<string>();
foreach (var assetInfo in _buildReport.AssetInfos)
{
if (assetInfo.MainBundleName == bundleInfo.BundleName)
{
mainAssetDic.Add(assetInfo.AssetPath);
containsList.Add(assetInfo);
}
}
foreach (string assetPath in bundleInfo.AllBuiltinAssets)
{
if (mainAssetDic.Contains(assetPath) == false)
{
var assetInfo = new ReportAssetInfo();
assetInfo.AssetPath = assetPath;
assetInfo.AssetGUID = "--";
containsList.Add(assetInfo);
}
}

_includeListView.Clear();
Expand All @@ -376,6 +390,16 @@ private VisualElement MakeIncludeListViewItem()
element.Add(label);
}

{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}

{
var label = new Label();
label.name = "Label2";
Expand All @@ -397,6 +421,10 @@ private void BindIncludeListViewItem(VisualElement element, int index)
var label1 = element.Q<Label>("Label1");
label1.text = assetInfo.AssetPath;

// Asset Source
var label3 = element.Q<Label>("Label3");
label3.text = assetInfo.AssetGUID != "--" ? "Main Asset" : "Builtin Asset";

// GUID
var label2 = element.Q<Label>("Label2");
label2.text = assetInfo.AssetGUID;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Asset Source" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ public class ShaderVariantElement
public class ShaderVariantInfo
{
/// <summary>
/// Shader asset path in editor.
/// 着色器资源路径.
/// </summary>
public string AssetPath;

/// <summary>
/// Shader name.
/// 着色器名称
/// </summary>
public string ShaderName;

/// <summary>
/// Shader variants elements list.
/// 着色器变种总数
/// </summary>
public int ShaderVariantCount = 0;

/// <summary>
/// 着色器变种列表
/// </summary>
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
}
Expand Down Expand Up @@ -71,6 +76,7 @@ public void AddShaderVariant(string assetPath, string shaderName, PassType passT
element.PassType = passType;
element.Keywords = keywords;
info.ShaderVariantElements.Add(element);
info.ShaderVariantCount++;
}
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
{
Expand Down
4 changes: 4 additions & 0 deletions Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## [2.7.6] - 2023-08-24
- Optimized AudioBase and VideoBase of MediaFrame update behaviour call by MediaManager.
- Updated YooAsset new commit files.

## [2.7.5] - 2023-08-23
- Optimized UIBase and SRBase of CoreFrame update behaviour call by FrameManager.
- Optimized CPBase of CoreFrame update behaviour, if need to update have to call by self to drive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void Update()
{
if (fStack.Count() != fBases.Length) break;

// 僅刷新顯示中的物件
// 僅刷新激活的物件
if (this.CheckIsShowing(fBase)) fBase.DriveUpdate(dt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AudioBase : MediaBase
[Tooltip("Depends on Requester.InitCacheCapacityForAudio"), ConditionalField(nameof(sourceType), true, SourceType.Audio)]
public bool requestCached = true;
// SourceType => StreamingAssets
[Tooltip("Default path is [StreamingAssets]. Just set that inside path and file name, Don't forget file name must include extension, ex: Audio/example.mp3"), ConditionalField(nameof(sourceType), false, SourceType.Streaming)]
[Tooltip("Default path is [StreamingAssets]. Just set that inside path and file name, Don't forget file name must with extension, ex: Audio/example.mp3"), ConditionalField(nameof(sourceType), false, SourceType.Streaming)]
public string fullPathName = "";
// SourceType => Url
[ConditionalField(nameof(sourceType), false, SourceType.Url)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ public async UniTask<string> GetFileText()
protected Action _endEvent = null; // 停止播放時的事件調用
public bool isPrepared { get; protected set; } = false; // 影音準備好的標記

private void FixedUpdate()
internal void DriveFixedUpdate(float dt)
{
if (!this._isInit) return;

if (!this.ignoreTimeScale) this.OnFixedUpdate(Time.fixedDeltaTime);
else this.OnFixedUpdate(Time.fixedUnscaledDeltaTime);
if (!this.ignoreTimeScale) this.OnFixedUpdate(dt);
else this.OnFixedUpdate(dt);
}

#region IMediaBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ internal abstract class MediaManager<T> : MonoBehaviour where T : MediaBase
protected HashSet<string> _loadingFlags = new HashSet<string>(); // 用來標記正在加載中的資源 (暫存緩存)
protected List<T> _listAllCache = new List<T>(); // 【常駐】所有進入播放的影音柱列緩存 (只會在 Destroy 時, Remove 對應的緩存)

private void FixedUpdate()
{
if (this._listAllCache.Count > 0)
{
float dt1 = Time.fixedDeltaTime;
float dt2 = Time.fixedUnscaledDeltaTime;

int count = this._listAllCache.Count;
for (int i = 0; i < count; i++)
{
if (this._listAllCache.Count != count) break;

// 僅刷新激活的物件
if (this._listAllCache[i].gameObject.activeSelf)
{
if (this._listAllCache[i].ignoreTimeScale) this._listAllCache[i].DriveFixedUpdate(dt2);
else this._listAllCache[i].DriveFixedUpdate(dt1);
}
}
}
}

/// <summary>
/// 檢查是否有資源緩存
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class VideoBase : MediaBase
[Tooltip("Drag video clip. This is not supports [WebGL]"), ConditionalField(nameof(sourceType), false, SourceType.Video)]
public VideoClip videoClip = null;
// SourceType => StreamingAssets
[Tooltip("Default path is [StreamingAssets]. Just set that inside path and file name, Don't forget file name must include extension, ex: Video/example.mp4"), ConditionalField(nameof(sourceType), false, SourceType.Streaming)]
[Tooltip("Default path is [StreamingAssets]. Just set that inside path and file name, Don't forget file name must with extension, ex: Video/example.mp4"), ConditionalField(nameof(sourceType), false, SourceType.Streaming)]
public string fullPathName = "";
// SourceType => Url
[ConditionalField(nameof(sourceType), false, SourceType.Url)]
Expand Down
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.michaelo.oxgframe",
"displayName": "OxGFrame",
"description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.",
"version": "2.7.5",
"version": "2.7.6",
"unity": "2021.3",
"license": "MIT",
"samples": [
Expand Down

0 comments on commit 75bd310

Please sign in to comment.