video plugins

This commit is contained in:
JSD\13999
2026-03-24 11:43:22 +08:00
parent 3f78e8464a
commit 1db5db6a77
117 changed files with 28171 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
/*----------------------------------------------------------------
// Copyright (C) 2025 Beijing All rights reserved.
//
// Author: huachangmiao
// Create Date: 2025/04/11
// Module Describe: Hierarchy 右键菜单创建视频播放器
//----------------------------------------------------------------*/
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public static class LeviathanVideoMenu
{
/// <summary>
/// 创建 UI 视频播放器 (RawImage)
/// </summary>
[MenuItem("GameObject/Leviathan Video/Leviathan Video Player (UI)", false, 10)]
private static void CreateUIVideoPlayer(MenuCommand menuCommand)
{
// 创建 GameObject
GameObject go = new GameObject("LeviathanVideoPlayer");
// 添加 RectTransformUI 组件需要)
RectTransform rectTransform = go.AddComponent<RectTransform>();
rectTransform.sizeDelta = new Vector2(400, 300);
// 添加 RawImage 组件LeviathanVideoDecoder 需要)
RawImage rawImage = go.AddComponent<RawImage>();
rawImage.color = Color.white;
// 添加视频解码器组件
go.AddComponent<LeviathanVideoDecoder>();
// 设置父物体
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
// 如果没有父物体,尝试放到 Canvas 下
if (go.transform.parent == null)
{
Canvas canvas = Object.FindObjectOfType<Canvas>();
if (canvas != null)
{
go.transform.SetParent(canvas.transform, false);
}
else
{
// 如果没有 Canvas创建一个
GameObject canvasGO = new GameObject("Canvas");
canvas = canvasGO.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvasGO.AddComponent<CanvasScaler>();
canvasGO.AddComponent<GraphicRaycaster>();
go.transform.SetParent(canvas.transform, false);
}
}
// 注册撤销
Undo.RegisterCreatedObjectUndo(go, "Create Leviathan Video Player (UI)");
// 选中创建的对象
Selection.activeObject = go;
}
/// <summary>
/// 创建 3D 视频播放器 (Cube)
/// </summary>
[MenuItem("GameObject/Leviathan Video/Leviathan Video Player (3D Cube)", false, 11)]
private static void Create3DVideoPlayerCube(MenuCommand menuCommand)
{
// 创建 Cube
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.name = "LeviathanVideoPlayer3D";
// 添加视频渲染器组件
go.AddComponent<LeviathanVideo3DRenderer>();
// 设置父物体
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
// 注册撤销
Undo.RegisterCreatedObjectUndo(go, "Create Leviathan Video Player (3D Cube)");
// 选中创建的对象
Selection.activeObject = go;
}
/// <summary>
/// 创建 3D 视频播放器 (Quad/Plane)
/// </summary>
[MenuItem("GameObject/Leviathan Video/Leviathan Video Player (3D Quad)", false, 12)]
private static void Create3DVideoPlayerQuad(MenuCommand menuCommand)
{
// 创建 Quad
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);
go.name = "LeviathanVideoPlayer3D";
// 添加视频渲染器组件
go.AddComponent<LeviathanVideo3DRenderer>();
// 设置父物体
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
// 注册撤销
Undo.RegisterCreatedObjectUndo(go, "Create Leviathan Video Player (3D Quad)");
// 选中创建的对象
Selection.activeObject = go;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7270087496e8e04a9f7984720cd2362
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,125 @@
#if UNITY_WEBGL
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using System.IO;
namespace LeviathanVideo.Editor
{
public static class WeChatMiniGameMenu
{
private const string SourcePath = "Assets/WX-WASM-SDK-V2-v0.1.32~";
private const string TargetPath = "Assets/WX-WASM-SDK-V2";
private const string LeviathanWasmPath = "Assets/WX-WASM-SDK-V2/Editor/template/minigame/leviathan.wasm.br";
private const string WeChatSDKGitUrl = "https://github.com/wechat-miniprogram/minigame-tuanjie-transform-sdk.git";
private static AddRequest _addRequest;
// 验证函数:只在 WX-WASM-SDK-V2 文件夹不存在时启用
[MenuItem("微信小游戏/[LeviathanVideo] SDK", true)]
public static bool ValidateInstallWeChatSDK()
{
return !Directory.Exists(TargetPath);
}
[MenuItem("微信小游戏/[LeviathanVideo] SDK", false)]
public static void InstallWeChatSDK()
{
Debug.Log($"[LeviathanVideo] 开始安装微信SDK: {WeChatSDKGitUrl}");
_addRequest = Client.Add(WeChatSDKGitUrl);
EditorApplication.update += OnInstallProgress;
}
private static void OnInstallProgress()
{
if (_addRequest == null || !_addRequest.IsCompleted)
return;
EditorApplication.update -= OnInstallProgress;
if (_addRequest.Status == StatusCode.Success)
{
Debug.Log($"[LeviathanVideo] 微信SDK安装成功: {_addRequest.Result.packageId}");
EditorUtility.DisplayDialog("安装成功",
$"微信小游戏SDK安装成功!\n\n包ID: {_addRequest.Result.packageId}\n\n请执行下一步操作:\n微信小游戏 -> [LeviathanVideo] ****首次安装微信SDK后需要执行此操作****",
"确定");
}
else if (_addRequest.Status >= StatusCode.Failure)
{
Debug.LogError($"[LeviathanVideo] 微信SDK安装失败: {_addRequest.Error.message}");
EditorUtility.DisplayDialog("安装失败", $"微信小游戏SDK安装失败!\n\n错误: {_addRequest.Error.message}", "确定");
}
_addRequest = null;
}
// 验证函数:只在 leviathan.wasm.br 文件不存在时启用
[MenuItem("微信小游戏/[LeviathanVideo] ****SDK后需要执行此操作**** ", true)]
public static bool ValidateCopyFiles()
{
// 需要 SDK 已安装 且 leviathan.wasm.br 文件不存在
return Directory.Exists(TargetPath) && !File.Exists(LeviathanWasmPath);
}
[MenuItem("微信小游戏/[LeviathanVideo] ****SDK后需要执行此操作**** ", false)]
public static void CopyFiles()
{
string sourcePath = Path.GetFullPath(SourcePath);
string targetPath = Path.GetFullPath(TargetPath);
if (!Directory.Exists(sourcePath))
{
EditorUtility.DisplayDialog("错误", $"源路径不存在: {sourcePath}", "确定");
return;
}
if (!Directory.Exists(targetPath))
{
EditorUtility.DisplayDialog("错误", $"目标路径不存在: {targetPath}", "确定");
return;
}
try
{
CopyDirectory(sourcePath, targetPath);
AssetDatabase.Refresh();
EditorUtility.DisplayDialog("完成", $"已将文件从\n{SourcePath}\n复制到\n{TargetPath}", "确定");
Debug.Log($"[Leviathan] 文件复制完成: {SourcePath} -> {TargetPath}");
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("错误", $"复制文件时出错: {e.Message}", "确定");
Debug.LogError($"[Leviathan] 复制文件失败: {e}");
}
}
private static void CopyDirectory(string sourceDir, string targetDir)
{
// 复制所有文件
foreach (string file in Directory.GetFiles(sourceDir))
{
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(targetDir, fileName);
File.Copy(file, destFile, true);
Debug.Log($"[Leviathan] 复制文件: {fileName}");
}
// 递归复制所有子目录
foreach (string dir in Directory.GetDirectories(sourceDir))
{
string dirName = Path.GetFileName(dir);
string destDir = Path.Combine(targetDir, dirName);
if (!Directory.Exists(destDir))
{
Directory.CreateDirectory(destDir);
}
CopyDirectory(dir, destDir);
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00d9ffb1d338f3a47a581531161a43da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: