diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs index e1886b01..93eed7b0 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PackageManager.cs @@ -386,7 +386,7 @@ public static void SwitchDefaultPackage(string packageName) _currentPackageName = package.PackageName; _currentPackage = package; } - else Logging.Print($"Switch default package failed! Cannot found package: {packageName}."); + else Logging.Print($"Switch default package failed! Cannot find package: {packageName}."); } /// diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchFsm/PatchFsmStates.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchFsm/PatchFsmStates.cs index 208f5a1a..6130abcd 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchFsm/PatchFsmStates.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchFsm/PatchFsmStates.cs @@ -207,7 +207,7 @@ private async UniTask _AppVersionComparison(AppConfig hostCfg) } else { - Logging.Print("Cannot found bundle config from StreamingAssets."); + Logging.Print("Cannot find bundle config from StreamingAssets."); return; } } diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Utility/BundleUtility.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Utility/BundleUtility.cs index 841e0216..be3a30da 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Utility/BundleUtility.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Utility/BundleUtility.cs @@ -262,7 +262,7 @@ public static async UniTask RequestAndCopyFileFromStreamingAssets(string sourceF if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError) { - Logging.Print("Request failed. Cannot found file in StreamingAssets."); + Logging.Print("Request failed. Cannot find file in StreamingAssets."); Logging.Print(request.error); } else diff --git a/Assets/OxGFrame/CHANGELOG.md b/Assets/OxGFrame/CHANGELOG.md index f8b6efb6..432691ec 100644 --- a/Assets/OxGFrame/CHANGELOG.md +++ b/Assets/OxGFrame/CHANGELOG.md @@ -1,5 +1,75 @@ # CHANGELOG +## [2.12.1] - 2024-11-08 +- Added MediaFrame (Audio, Video) with an option to specify a sourceClip, handled by the prefab container for playback. +```csharp + // Audio + public static async UniTask Play(string assetName, AudioClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + public static async UniTask Play(string packageName, string assetName, AudioClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + + // Video + public static async UniTask Play(string assetName, VideoClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + public static async UniTask Play(string packageName, string assetName, VideoClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) +``` +- Added CoreFrame binding parameters that will compare with the parent class's binding parameters and remove any overlapping parts. +```csharp +TestAUI ↓↓↓ + + #region Binding Components + [HideInInspector] public GameObject a; + protected GameObject _b; + + /// + /// Auto Binding Section + /// + protected override void OnAutoBind() + { + base.OnAutoBind(); + this.a = this.collector.GetNode("A"); + this._b = this.collector.GetNode("B"); + } + #endregion + +TestBUI : TestAUI ↓↓↓ + #region Binding Components + protected ButtonPlus _cBtnPlus; + + /// + /// Auto Binding Section + /// + protected override void OnAutoBind() + { + base.OnAutoBind(); + this._cBtnPlus = this.collector.GetNodeComponent("C*BtnPlus"); + } + #endregion + +TestCUI : TestBUI ↓↓↓ + #region Binding Components + protected GameObject _d; + + /// + /// Auto Binding Section + /// + protected override void OnAutoBind() + { + base.OnAutoBind(); + this._d = this.collector.GetNode("D"); + } + #endregion +``` +- Added some methods to CoreFrames.USFrame. +```csharp + public static Scene CreateScene(string sceneName, CreateSceneParameters parameters) + public static bool MergeScenes(Scene sourceScene, Scene targetScene) + public static bool MoveGameObjectToScene(GameObject go, Scene targetScene) + public static bool MoveGameObjectToActiveScene(GameObject go) +``` +- Modified the CoreFrame Attrs binding format to a single-line format. +- Modified the configuration file’s default value from 127.0.0.1 to http://127.0.0.1. +- Fixed handling for MediaFrame when the clip is null. +- Fixed an issue in which the CoreFrame object returned Null when calling Show on an already showing object. It now returns the cached object instead. + ## [2.12.0] - 2024-10-24 (rule changed) - Modified CloseAll, HideAll, RevealAll rules of method for UIFrame and SRFrame. - Set the default group id to 0, but if you don't want to execute based on the group id and want to do all, can set the group id to -1. diff --git a/Assets/OxGFrame/CenterFrame/Scripts/Runtime/Common/CenterBase.cs b/Assets/OxGFrame/CenterFrame/Scripts/Runtime/Common/CenterBase.cs index 1bdcf6a2..92a0d1ff 100644 --- a/Assets/OxGFrame/CenterFrame/Scripts/Runtime/Common/CenterBase.cs +++ b/Assets/OxGFrame/CenterFrame/Scripts/Runtime/Common/CenterBase.cs @@ -142,7 +142,7 @@ protected TClass GetFromCache(int id) { if (!this.HasInCache(id)) { - Logging.Print(string.Format("Cannot found. Id: {0}", id)); + Logging.Print(string.Format("Cannot find. Id: {0}", id)); return default; } diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs index 945f415b..f1635241 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs @@ -17,6 +17,9 @@ public static class CoreFrames /// internal const int DEFAULT_GROUP_ID = 0; + /// + /// User Interface + /// public static class UIFrame { public static bool ignoreTimeScale @@ -377,6 +380,9 @@ public static void HideAllAndExcluded(int groupId, params string[] withoutAssetN #endregion } + /// + /// Scene Resource + /// public static class SRFrame { public static bool ignoreTimeScale @@ -684,6 +690,9 @@ public static void HideAllAndExcluded(int groupId, params string[] withoutAssetN #endregion } + /// + /// Unity Scene + /// public static class USFrame { public static void InitInstance() @@ -696,6 +705,26 @@ public static int SceneCount() return USManager.sceneCount; } + public static Scene CreateScene(string sceneName, CreateSceneParameters parameters) + { + return USManager.GetInstance().CreateScene(sceneName, parameters); + } + + public static bool MergeScenes(Scene sourceScene, Scene targetScene) + { + return USManager.GetInstance().MergeScenes(sourceScene, targetScene); + } + + public static bool MoveGameObjectToScene(GameObject go, Scene targetScene) + { + return USManager.GetInstance().MoveGameObjectToScene(go, targetScene); + } + + public static bool MoveGameObjectToActiveScene(GameObject go) + { + return USManager.GetInstance().MoveGameObjectToActiveScene(go); + } + public static Scene GetActiveScene() { return USManager.GetInstance().GetActiveScene(); @@ -1413,6 +1442,9 @@ internal static bool RefineBuildScenePath(ref string sceneName) } } + /// + /// Clone Prefab + /// public static class CPFrame { public static void InitInstance() diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs index c15bd94a..f2d6a442 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs @@ -2,6 +2,7 @@ using OxGFrame.AssetLoader; using OxGFrame.AssetLoader.Cacher; using OxGKit.LoggingSystem; +using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; @@ -35,6 +36,54 @@ public static USManager GetInstance() return _instance; } + public Scene CreateScene(string sceneName, CreateSceneParameters parameters) + { + return SceneManager.CreateScene(sceneName, parameters); + } + + public bool MergeScenes(Scene sourceScene, Scene targetScene) + { + try + { + SceneManager.MergeScenes(sourceScene, targetScene); + return true; + } + catch (Exception ex) + { + Logging.PrintException(ex); + return false; + } + } + + public bool MoveGameObjectToScene(GameObject go, Scene targetScene) + { + try + { + SceneManager.MoveGameObjectToScene(go, targetScene); + return true; + } + catch (Exception ex) + { + Logging.PrintException(ex); + return false; + } + } + + public bool MoveGameObjectToActiveScene(GameObject go) + { + try + { + Scene targetScene = this.GetActiveScene(); + SceneManager.MoveGameObjectToScene(go, targetScene); + return true; + } + catch (Exception ex) + { + Logging.PrintException(ex); + return false; + } + } + public Scene GetActiveScene() { return SceneManager.GetActiveScene(); diff --git a/Assets/OxGFrame/GSIFrame/Scripts/Runtime/GSIManagerBase.cs b/Assets/OxGFrame/GSIFrame/Scripts/Runtime/GSIManagerBase.cs index 353353ce..1d99bf4b 100644 --- a/Assets/OxGFrame/GSIFrame/Scripts/Runtime/GSIManagerBase.cs +++ b/Assets/OxGFrame/GSIFrame/Scripts/Runtime/GSIManagerBase.cs @@ -295,7 +295,7 @@ protected void InitGameStage() // 開始進行 GameStage 初始流程 if (this._currentGameStage != null) this._currentGameStage.BeginInit().Forget(); #if UNITY_EDITOR - else Logging.Print(string.Format("Cannot found GameStage. Id: {0}", this._currentId)); + else Logging.Print(string.Format("Cannot find GameStage. Id: {0}", this._currentId)); #endif } diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Editor/AudioBaseEditor.cs b/Assets/OxGFrame/MediaFrame/Scripts/Editor/AudioBaseEditor.cs index b2bf0ea7..09f569d6 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Editor/AudioBaseEditor.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Editor/AudioBaseEditor.cs @@ -51,7 +51,7 @@ protected virtual async void DrawAudioLengthView() case SourceType.Audio: audioClip = this._target.audioClip; if (audioClip != null) this._audioLength.floatValue = this._target.audioLength = this._target.audioClip.length; - else Debug.LogError("Cannot found AudioClip"); + else Debug.LogError("Cannot find AudioClip"); break; case SourceType.StreamingAssets: diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioBase.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioBase.cs index 22088bd9..a9eb7de5 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioBase.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioBase.cs @@ -39,19 +39,23 @@ public class AudioBase : MediaBase [SerializeField, ConditionalField(nameof(_mixerGroupSourceType), false, MixerGroupSourceType.Find)] protected string _mixerGroupName = ""; - public override async UniTask Init() + public override async UniTask Init() { this._audioSource = this.GetComponent(); - await this._InitAudio(); + bool isInitialized = await this._InitAudio(); - this._isInit = true; // Mark all init is finished. + if (isInitialized) + this._isInit = true; // Mark all init is finished. + + return this._isInit; } - private async UniTask _InitAudio() + private async UniTask _InitAudio() { this.isPrepared = false; - if (this._audioSource == null) return; + if (this._audioSource == null) + return false; // Get Audio switch (this.sourceType) @@ -66,8 +70,8 @@ private async UniTask _InitAudio() if (this.audioClip == null) { - Logging.Print($"Cannot found AudioClip: {this.mediaName}"); - return; + Logging.Print($"Cannot find AudioClip: {this.mediaName}"); + return false; } // Get Mixer Group @@ -93,6 +97,8 @@ private async UniTask _InitAudio() this.isPrepared = true; Logging.Print($"【Init Once】 Audio length: {this._mediaLength} (s)"); + + return this.isPrepared; } public async UniTask GetAudioFromStreamingAssets(bool cached) diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioManager.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioManager.cs index 518107e7..7c96820e 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioManager.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/AudioFrame/AudioManager.cs @@ -43,7 +43,7 @@ public static AudioManager GetInstance() lock (_locker) { _instance = FindObjectOfType(); - if (_instance == null) Logging.PrintWarning("Cannot found 【AudioManager Component】, Please to check your 【AudioManager GameObject】."); + if (_instance == null) Logging.PrintWarning("Cannot find 【AudioManager Component】, Please to check your 【AudioManager GameObject】."); } } return _instance; @@ -393,9 +393,9 @@ private void _Play(AudioBase audBase, int loops, float volume) /// /// /// - public override async UniTask Play(string packageName, string assetName, Transform parent = null, int loops = 0, float volume = 0f) + public override async UniTask Play(string packageName, string assetName, UnityEngine.Object sourceClip, Transform parent = null, int loops = 0, float volume = 0f) { - if (string.IsNullOrEmpty(assetName)) return new AudioBase[] { }; + if (string.IsNullOrEmpty(assetName)) return new AudioBase[] { null }; AudioBase[] audBases = this.GetMediaComponents(assetName); bool isResume = false; @@ -420,11 +420,11 @@ public override async UniTask Play(string packageName, string asset GameObject go = await this.LoadAssetIntoCache(packageName, assetName); Transform spawnParent = null; if (parent == null) spawnParent = this.transform; - AudioBase audBase = await this.CloneAsset(assetName, go, parent, spawnParent); + AudioBase audBase = await this.CloneAsset(assetName, go, sourceClip, parent, spawnParent); if (audBase == null) { Logging.PrintWarning(string.Format("Asset not found at this path!!!【Audio】: {0}", assetName)); - return new AudioBase[] { }; + return new AudioBase[] { null }; } this._Play(audBase, loops, volume); diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaBase.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaBase.cs index d6ff5c5c..8be83dc3 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaBase.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaBase.cs @@ -101,7 +101,7 @@ internal void HandleFixedUpdate(float dt) /// /// 初始用 /// - public abstract UniTask Init(); + public abstract UniTask Init(); /// /// 固定每幀被調用 diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaManager.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaManager.cs index 027f3687..dd197754 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaManager.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/Implement/MediaManager.cs @@ -1,9 +1,12 @@ using Cysharp.Threading.Tasks; using OxGFrame.AssetLoader; +using OxGFrame.MediaFrame.AudioFrame; using OxGFrame.MediaFrame.Cacher; +using OxGFrame.MediaFrame.VideoFrame; using OxGKit.LoggingSystem; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Video; namespace OxGFrame.MediaFrame { @@ -187,7 +190,7 @@ protected async UniTask LoadAssetIntoCache(string packageName, strin /// /// /// - protected async virtual UniTask CloneAsset(string assetName, GameObject go, Transform parent, Transform spwanParent) where U : T + protected async virtual UniTask CloneAsset(string assetName, GameObject go, UnityEngine.Object sourceClip, Transform parent, Transform spwanParent) where U : T { if (go == null) return default; @@ -199,7 +202,8 @@ protected async virtual UniTask CloneAsset(string assetName, GameObject go // 激活檢查, 如果主體 Active 為 false 必須打開 if (!instGo.activeSelf) instGo.SetActive(true); - this._listAllCache.Add(mBase); // 先加入緩存 + // 先加入緩存 + this._listAllCache.Add(mBase); this.SetParent(mBase, parent); // 設置管理名稱 @@ -207,11 +211,32 @@ protected async virtual UniTask CloneAsset(string assetName, GameObject go mediaName = (mediaName.IndexOf('/') != -1) ? mediaName.Substring(mediaName.LastIndexOf('/')).Replace("/", string.Empty) : mediaName; mBase.SetNames(assetName, mediaName); - await mBase.Init(); + // 如果判斷有 clip 來源, 會重新 assign + if (sourceClip != null) + { + if (typeof(U) == typeof(AudioBase)) + { + // 處理 AudioBase 類型 + (mBase as AudioBase).audioClip = sourceClip as AudioClip; + } + else if (typeof(U) == typeof(VideoBase)) + { + // 處理 VideoBase 類型 + (mBase as VideoBase).videoClip = sourceClip as VideoClip; + } + } + + bool isInitialized = await mBase.Init(); + if (!isInitialized) + { + this.Destroy(mBase); + return default; + } // >>> 需在 Init 之後, 以下設定開始生效 <<< - if (mBase == null || mBase.gameObject.IsDestroyed()) return default; + if (mBase == null || mBase.gameObject.IsDestroyed()) + return default; mBase.gameObject.SetActive(false); @@ -239,7 +264,7 @@ public async UniTask Preload(string packageName, string[] assetNames) protected virtual void SetParent(T mBase, Transform parent) { } #region Play - public abstract UniTask Play(string packageName, string assetName, Transform parent = null, int loops = 0, float volume = 0f); + public abstract UniTask Play(string packageName, string assetName, UnityEngine.Object sourceClip, Transform parent = null, int loops = 0, float volume = 0f); public abstract void ResumeAll(); #endregion diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/MediaFrames.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/MediaFrames.cs index 98f0fb5f..56f749ea 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/MediaFrames.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/MediaFrames.cs @@ -4,6 +4,7 @@ using OxGFrame.MediaFrame.VideoFrame; using UnityEngine; using UnityEngine.Audio; +using UnityEngine.Video; namespace OxGFrame.MediaFrame { @@ -110,13 +111,26 @@ public static async UniTask Preload(string packageName, string[] assetNames) public static async UniTask Play(string assetName, Transform parent = null, int loops = 0, float volume = 0f) { var packageName = AssetPatcher.GetDefaultPackageName(); - var media = await AudioManager.GetInstance().Play(packageName, assetName, parent, loops, volume); + var media = await AudioManager.GetInstance().Play(packageName, assetName, null, parent, loops, volume); return media[0]; } public static async UniTask Play(string packageName, string assetName, Transform parent = null, int loops = 0, float volume = 0f) { - var media = await AudioManager.GetInstance().Play(packageName, assetName, parent, loops, volume); + var media = await AudioManager.GetInstance().Play(packageName, assetName, null, parent, loops, volume); + return media[0]; + } + + public static async UniTask Play(string assetName, AudioClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + var media = await AudioManager.GetInstance().Play(packageName, assetName, sourceClip, parent, loops, volume); + return media[0]; + } + + public static async UniTask Play(string packageName, string assetName, AudioClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + { + var media = await AudioManager.GetInstance().Play(packageName, assetName, sourceClip, parent, loops, volume); return media[0]; } @@ -211,13 +225,26 @@ public static async UniTask Preload(string packageName, string[] assetNames) public static async UniTask Play(string assetName, Transform parent = null, int loops = 0, float volume = 0f) { var packageName = AssetPatcher.GetDefaultPackageName(); - var media = await VideoManager.GetInstance().Play(packageName, assetName, parent, loops, volume); + var media = await VideoManager.GetInstance().Play(packageName, assetName, null, parent, loops, volume); return media[0]; } public static async UniTask Play(string packageName, string assetName, Transform parent = null, int loops = 0, float volume = 0f) { - var media = await VideoManager.GetInstance().Play(packageName, assetName, parent, loops, volume); + var media = await VideoManager.GetInstance().Play(packageName, assetName, null, parent, loops, volume); + return media[0]; + } + + public static async UniTask Play(string assetName, VideoClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + var media = await VideoManager.GetInstance().Play(packageName, assetName, sourceClip, parent, loops, volume); + return media[0]; + } + + public static async UniTask Play(string packageName, string assetName, VideoClip sourceClip, Transform parent = null, int loops = 0, float volume = 0f) + { + var media = await VideoManager.GetInstance().Play(packageName, assetName, sourceClip, parent, loops, volume); return media[0]; } diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoBase.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoBase.cs index 0a4650eb..11150294 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoBase.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoBase.cs @@ -38,12 +38,15 @@ public class VideoBase : MediaBase [SerializeField] protected VideoAspectRatio _aspectRatio = VideoAspectRatio.FitHorizontally; - public override async UniTask Init() + public override async UniTask Init() { this._videoPlayer = this.GetComponent(); - await this._InitVideo(); + bool isInitialized = await this._InitVideo(); - this._isInit = true; // Mark all init is finished. + if (isInitialized) + this._isInit = true; // Mark all init is finished. + + return this._isInit; } protected bool TrySetUrl(string url) @@ -60,11 +63,12 @@ protected bool TrySetUrl(string url) return true; } - private async UniTask _InitVideo() + private async UniTask _InitVideo() { this.isPrepared = false; - if (this._videoPlayer == null) return; + if (this._videoPlayer == null) + return false; switch (this.sourceType) { @@ -73,8 +77,8 @@ private async UniTask _InitVideo() this._videoPlayer.clip = this.videoClip; if (this.videoClip == null) { - Logging.Print($"Cannot found VideoClip: {this.mediaName}"); - return; + Logging.Print($"Cannot find VideoClip: {this.mediaName}"); + return false; } break; case SourceType.StreamingAssets: @@ -83,8 +87,8 @@ private async UniTask _InitVideo() string url = System.IO.Path.Combine(Application.streamingAssetsPath, this.fullPathName); if (!this.TrySetUrl(url)) { - Logging.Print($"Cannot found VideoClip: {this.mediaName}"); - return; + Logging.Print($"Cannot find VideoClip: {this.mediaName}"); + return false; } } break; @@ -95,8 +99,8 @@ private async UniTask _InitVideo() string url = (!string.IsNullOrEmpty(urlSet)) ? $"{urlSet.Trim()}{this.urlSet.url.Trim()}" : this.urlSet.url.Trim(); if (!this.TrySetUrl(url)) { - Logging.Print($"Cannot found VideoClip: {this.mediaName}"); - return; + Logging.Print($"Cannot find VideoClip: {this.mediaName}"); + return false; } } break; @@ -105,9 +109,20 @@ private async UniTask _InitVideo() this._videoPlayer.Prepare(); Logging.Print($"{this.mediaName} video is preparing..."); var cts = new CancellationTokenSource(); - cts.CancelAfterSlim(TimeSpan.FromSeconds(5f)); - await UniTask.WaitUntil(() => { return this._videoPlayer.isPrepared; }, PlayerLoopTiming.FixedUpdate, cts.Token); - Logging.Print($"{this.mediaName} video is prepared"); + cts.CancelAfterSlim(TimeSpan.FromSeconds(15f)); + try + { + await UniTask.WaitUntil(() => { return this._videoPlayer.isPrepared; }, PlayerLoopTiming.FixedUpdate, cts.Token); + Logging.Print($"{this.mediaName} video is prepared"); + } + catch (OperationCanceledException ex) + { + if (ex.CancellationToken == cts.Token) + { + Logging.PrintException(ex); + return false; + } + } this._videoPlayer.SetDirectAudioMute(0, true); this._videoPlayer.playOnAwake = false; @@ -131,6 +146,8 @@ private async UniTask _InitVideo() this.isPrepared = true; Logging.Print($"【Init Once】 Video length: {this._mediaLength} (s)"); + + return this.isPrepared; } /// diff --git a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoManager.cs b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoManager.cs index 80ccb50b..f959ceca 100644 --- a/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoManager.cs +++ b/Assets/OxGFrame/MediaFrame/Scripts/Runtime/Core/VideoFrame/VideoManager.cs @@ -68,9 +68,9 @@ private void _Play(VideoBase vidBase, int loops, float volume) /// /// /// - public override async UniTask Play(string packageName, string assetName, Transform parent = null, int loops = 0, float volume = 0f) + public override async UniTask Play(string packageName, string assetName, UnityEngine.Object sourceClip, Transform parent = null, int loops = 0, float volume = 0f) { - if (string.IsNullOrEmpty(assetName)) return new VideoBase[] { }; + if (string.IsNullOrEmpty(assetName)) return new VideoBase[] { null }; VideoBase[] vidBases = this.GetMediaComponents(assetName); bool isResume = false; @@ -91,11 +91,11 @@ public override async UniTask Play(string packageName, string asset GameObject go = await this.LoadAssetIntoCache(packageName, assetName); Transform spawnParent = null; if (parent == null) spawnParent = this.gameObject.transform; - VideoBase vidBase = await this.CloneAsset(assetName, go, parent, spawnParent); + VideoBase vidBase = await this.CloneAsset(assetName, go, sourceClip, parent, spawnParent); if (vidBase == null) { Logging.PrintWarning(string.Format("Asset not found at this path!!!【Video】: {0}", assetName)); - return new VideoBase[] { }; + return new VideoBase[] { null }; } this._Play(vidBase, loops, volume); diff --git a/Assets/OxGFrame/Samples~/AudioFrameDemo/AudioFrameDemo.unity b/Assets/OxGFrame/Samples~/AudioFrameDemo/AudioFrameDemo.unity index 4b7d826b..670c11a4 100644 --- a/Assets/OxGFrame/Samples~/AudioFrameDemo/AudioFrameDemo.unity +++ b/Assets/OxGFrame/Samples~/AudioFrameDemo/AudioFrameDemo.unity @@ -7091,6 +7091,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 56493ef957b1c8d40ae014247f91a934, type: 3} m_Name: m_EditorClassIdentifier: + clips: + - {fileID: 8300000, guid: b8ce5ca072e6e1a4caa78d9927dab6db, type: 3} + - {fileID: 8300000, guid: ddf4c2454856b1941b9506eba8f82ce2, type: 3} --- !u!4 &1190862928 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/b_General/201.prefab b/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/b_General/201.prefab index ea2a4c08..fed533bf 100644 --- a/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/b_General/201.prefab +++ b/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/b_General/201.prefab @@ -143,15 +143,16 @@ MonoBehaviour: m_EditorClassIdentifier: ignoreTimeScale: 1 loops: 0 + autoEndToStop: 1 onStopAndDestroy: 1 onDestroyAndUnload: 0 - autoEndToStop: 1 audioType: soundType: 1 priority: 128 audioFileType: 13 sourceType: 0 audioClip: {fileID: 8300000, guid: b8ce5ca072e6e1a4caa78d9927dab6db, type: 3} + requestCached: 1 fullPathName: urlSet: getUrlPathFromCfg: 1 @@ -160,7 +161,7 @@ MonoBehaviour: file: {fileID: 0} fullPathName: url: General/button_click.mp3 - audioLength: 2.0636735 + audioLength: 0 _mixerGroupSourceType: 1 _mixerGroup: {fileID: 0} _mixerName: MasterMixer diff --git a/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/c_Interact/301.prefab b/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/c_Interact/301.prefab index 0f99b46a..bb1bfd39 100644 --- a/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/c_Interact/301.prefab +++ b/Assets/OxGFrame/Samples~/AudioFrameDemo/Resources/Audio/c_Interact/301.prefab @@ -143,15 +143,16 @@ MonoBehaviour: m_EditorClassIdentifier: ignoreTimeScale: 1 loops: 0 + autoEndToStop: 1 onStopAndDestroy: 1 onDestroyAndUnload: 0 - autoEndToStop: 1 audioType: soundType: 1 priority: 128 audioFileType: 13 sourceType: 0 audioClip: {fileID: 8300000, guid: ddf4c2454856b1941b9506eba8f82ce2, type: 3} + requestCached: 1 fullPathName: urlSet: getUrlPathFromCfg: 1 @@ -160,7 +161,7 @@ MonoBehaviour: file: {fileID: 0} fullPathName: url: Fight/impact.mp3 - audioLength: 1.7502041 + audioLength: 0 _mixerGroupSourceType: 1 _mixerGroup: {fileID: 0} _mixerName: MasterMixer diff --git a/Assets/OxGFrame/Samples~/AudioFrameDemo/Scripts/AudioFrameDemo.cs b/Assets/OxGFrame/Samples~/AudioFrameDemo/Scripts/AudioFrameDemo.cs index 573571fe..5074785e 100644 --- a/Assets/OxGFrame/Samples~/AudioFrameDemo/Scripts/AudioFrameDemo.cs +++ b/Assets/OxGFrame/Samples~/AudioFrameDemo/Scripts/AudioFrameDemo.cs @@ -24,6 +24,8 @@ public static class AudioPrefs public class AudioFrameDemo : MonoBehaviour { + public AudioClip[] clips; + private void Awake() { // If Init instance can more efficiency @@ -55,7 +57,8 @@ public void PauseBGM() #region Audio 【General SFX】 public async void PlayGeneralFX() { - await MediaFrames.AudioFrame.Play(AudioPrefs.a201); + // You can assign a clip to prefab and play it, or load a clip from prefab and play it + await MediaFrames.AudioFrame.Play(AudioPrefs.a201, this.clips[0]); } public void StopGeneralFX() @@ -83,7 +86,8 @@ public void PauseGeneralFX() #region Audio 【Interact SFX】 public async void PlayFightFX() { - await MediaFrames.AudioFrame.Play(AudioPrefs.a301); + // You can assign a clip to prefab and play it, or load a clip from prefab and play it + await MediaFrames.AudioFrame.Play(AudioPrefs.a301, this.clips[1]); } public void StopFightFX() diff --git a/Assets/OxGFrame/Samples~/VideoFrameDemo/Scripts/VideoFrameDemo.cs b/Assets/OxGFrame/Samples~/VideoFrameDemo/Scripts/VideoFrameDemo.cs index 45b3245b..3bbf86d8 100644 --- a/Assets/OxGFrame/Samples~/VideoFrameDemo/Scripts/VideoFrameDemo.cs +++ b/Assets/OxGFrame/Samples~/VideoFrameDemo/Scripts/VideoFrameDemo.cs @@ -1,6 +1,7 @@ using OxGFrame.MediaFrame; using UnityEngine; using UnityEngine.UI; +using UnityEngine.Video; public static class VideoPrefs { @@ -17,6 +18,8 @@ public static class VideoPrefs public class VideoFrameDemo : MonoBehaviour { + public VideoClip[] clips; + private void Awake() { // If Init instance can more efficiency @@ -29,7 +32,8 @@ private void Awake() public async void PlayVideoCamera() { // if render mode is Camera just play directly - await MediaFrames.VideoFrame.Play(VideoPrefs.VideoCamExample); + // You can assign a clip to prefab and play it, or load a clip from prefab and play it + await MediaFrames.VideoFrame.Play(VideoPrefs.VideoCamExample, this.clips[0]); } public void StopVideoCamera() @@ -51,7 +55,8 @@ public void PauseVideoCamera() #region Video cast to 【RenderTexture】 public async void PlayVideoRenderTexture() { - var video = await MediaFrames.VideoFrame.Play(VideoPrefs.VideoRtExample); + // You can assign a clip to prefab and play it, or load a clip from prefab and play it + var video = await MediaFrames.VideoFrame.Play(VideoPrefs.VideoRtExample, this.clips[1]); // Get Video if (video != null) diff --git a/Assets/OxGFrame/Samples~/VideoFrameDemo/VideoFrameDemo.unity b/Assets/OxGFrame/Samples~/VideoFrameDemo/VideoFrameDemo.unity index 28548a8a..a31f20d0 100644 --- a/Assets/OxGFrame/Samples~/VideoFrameDemo/VideoFrameDemo.unity +++ b/Assets/OxGFrame/Samples~/VideoFrameDemo/VideoFrameDemo.unity @@ -3402,6 +3402,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fe251c1b9b35a7346a96e88f47683980, type: 3} m_Name: m_EditorClassIdentifier: + clips: + - {fileID: 32900000, guid: 12f7b111392fa11449c23f7a982dd405, type: 3} + - {fileID: 32900000, guid: 4c8f2885b109e7b43a3e3a0049cce218, type: 3} rawImage: {fileID: 1323699754} --- !u!4 &2084247922 Transform: diff --git a/Assets/OxGFrame/package.json b/Assets/OxGFrame/package.json index 8dcb7a11..128d7802 100644 --- a/Assets/OxGFrame/package.json +++ b/Assets/OxGFrame/package.json @@ -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.12.0", + "version": "2.12.1", "unity": "2021.3", "license": "MIT", "samples": [