bingo 项目提交
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BingoBrain.Editor
|
||||
{
|
||||
public class AssetBundleBuildKit
|
||||
{
|
||||
public const string AssetBundleRootPath = "Assets/AssetHotFix/";
|
||||
public const string AssetBundleSuffix = ".assetbundle";
|
||||
static void SetABName(string assetPath)
|
||||
{
|
||||
var importerPath = $"Assets{assetPath[Application.dataPath.Length..]}";
|
||||
importerPath = importerPath.Replace("\\", "/");
|
||||
const string assetBundleRootPath = AssetBundleRootPath;
|
||||
|
||||
if (importerPath.StartsWith(assetBundleRootPath))
|
||||
{
|
||||
var bundleName = importerPath.Replace(assetBundleRootPath, "");
|
||||
|
||||
var endIndex = bundleName.LastIndexOf("/", StringComparison.Ordinal);
|
||||
|
||||
if (endIndex <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fileInfo = new FileInfo(importerPath);
|
||||
|
||||
if ((fileInfo.Attributes & FileAttributes.Directory) == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
bundleName = bundleName.ToLower().Substring(0, endIndex).Replace("/", ".");
|
||||
|
||||
var importer = AssetImporter.GetAtPath(importerPath);
|
||||
if (importer != null)
|
||||
{
|
||||
importer.assetBundleName = $"{bundleName}{AssetBundleSuffix}";
|
||||
if (importer.assetBundleName != null)
|
||||
{
|
||||
importer.assetBundleVariant = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(importerPath);
|
||||
Debug.LogError(endIndex);
|
||||
Debug.LogError(e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void SetAssetBundlesName(string _assetsPath)
|
||||
{
|
||||
var dir = new DirectoryInfo(_assetsPath);
|
||||
|
||||
var files = dir.GetFileSystemInfos();
|
||||
|
||||
for (var i = 0; i < files.Length; i++)
|
||||
{
|
||||
if (files[i] is DirectoryInfo)
|
||||
{
|
||||
SetAssetBundlesName(files[i].FullName);
|
||||
}
|
||||
else if (!files[i].Name.EndsWith(".meta"))
|
||||
{
|
||||
SetABName(files[i].FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void ClearAssetBundlesName()
|
||||
{
|
||||
var abNames = AssetDatabase.GetAllAssetBundleNames();
|
||||
|
||||
|
||||
for (var i = 0; i < abNames.Length; i++)
|
||||
{
|
||||
AssetDatabase.RemoveAssetBundleName(abNames[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0d705bde2444bc7800da81344efcfa2
|
||||
timeCreated: 1705384501
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Comgreate;
|
||||
|
||||
namespace BingoBrain.Editor
|
||||
{
|
||||
public class BuildSome
|
||||
{
|
||||
public const string AssetBundleRootPath = "Assets/AssetHotFix/";
|
||||
public static readonly string AssetBundleBuildOutputPath =
|
||||
$"{Application.dataPath}/../AssetBundle/{AssetBundlesName}";
|
||||
public const string AssetBundlesName = "AssetBundles";
|
||||
public const string AssetBundleSuffix = ".assetbundle";
|
||||
public const string AssetBundlePassword = "4s2f6ac15sa6ds45";
|
||||
|
||||
[MenuItem("Tools/Build")]
|
||||
public static void BuildAssetBundle()
|
||||
{
|
||||
AssetBundleBuildKit.ClearAssetBundlesName();
|
||||
|
||||
AssetBundleBuildKit.SetAssetBundlesName(AssetBundleRootPath);
|
||||
|
||||
EditorApplication.isPlaying = false;
|
||||
|
||||
var dir = AssetBundleBuildOutputPath;
|
||||
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
|
||||
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
var manifest = BuildPipeline.BuildAssetBundles(dir, BuildAssetBundleOptions.ChunkBasedCompression,
|
||||
buildTarget);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EncryptAssetBundle();
|
||||
|
||||
BuildAssetBundleFileIndex(manifest);
|
||||
|
||||
Debug.Log($"[ Jarvis ] [ AssetBundle构建 ] 平台: {buildTarget.ToString()} 打包完成");
|
||||
|
||||
Application.OpenURL(dir + "/..");
|
||||
}
|
||||
|
||||
|
||||
private static void EncryptAssetBundle()
|
||||
{
|
||||
var dir = AssetBundleBuildOutputPath;
|
||||
|
||||
var filePaths = Directory.GetFiles(dir, $"*{AssetBundleSuffix}",
|
||||
SearchOption.TopDirectoryOnly);
|
||||
|
||||
|
||||
var encryptPath = $"{Application.dataPath}/../AssetBundlesEncrypt";
|
||||
|
||||
if (!Directory.Exists(encryptPath))
|
||||
{
|
||||
Directory.CreateDirectory(encryptPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.Delete(encryptPath, true);
|
||||
|
||||
Directory.CreateDirectory(encryptPath);
|
||||
}
|
||||
|
||||
foreach (var assetBundleFile in filePaths)
|
||||
{
|
||||
if (!assetBundleFile.EndsWith(".meta") && !assetBundleFile.Contains(".DS_Store"))
|
||||
{
|
||||
var assetBundleName = assetBundleFile.Replace(dir, string.Empty).Replace("\\", "");
|
||||
var encryptFilePath = Path.Combine(encryptPath, assetBundleName);
|
||||
AESForFileKit.EncryptFile(assetBundleFile, encryptFilePath,
|
||||
AssetBundlePassword);
|
||||
|
||||
File.Copy(encryptFilePath, Path.Combine(dir, assetBundleName), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Directory.Delete(encryptPath, true);
|
||||
}
|
||||
public const string AssetHotFixFileName = "AssetHotFixFile.txt";
|
||||
|
||||
private static void BuildAssetBundleFileIndex(AssetBundleManifest manifest)
|
||||
{
|
||||
var dir = AssetBundleBuildOutputPath;
|
||||
var dirFile = $"{AssetBundleBuildOutputPath}/../";
|
||||
|
||||
var filePath = Path.Combine(dirFile, AssetHotFixFileName);
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
|
||||
|
||||
var filePaths = Directory.GetFiles(dir, $"*{AssetBundleSuffix}",
|
||||
SearchOption.TopDirectoryOnly);
|
||||
|
||||
using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
||||
|
||||
using var streamWriter = new StreamWriter(fileStream);
|
||||
|
||||
var totalAssetBundlePath = $"{dir}/{AssetBundlesName}";
|
||||
|
||||
var totalAssetBundleManifestPath = $"{dir}/{AssetBundlesManifestName}";
|
||||
|
||||
var totalMD5 = MD5Kit.GetFileMD5(totalAssetBundlePath);
|
||||
streamWriter.WriteLine(GetAssetBundleFileIndex(AssetBundlesName, totalMD5));
|
||||
|
||||
var manifestMD5 = MD5Kit.GetFileMD5(totalAssetBundleManifestPath);
|
||||
streamWriter.WriteLine(GetAssetBundleFileIndex(AssetBundlesManifestName,
|
||||
manifestMD5));
|
||||
foreach (var assetBundleFile in filePaths)
|
||||
{
|
||||
if (!assetBundleFile.EndsWith(".meta") && !assetBundleFile.Contains(".DS_Store"))
|
||||
{
|
||||
var fileMD5 = MD5Kit.GetFileMD5(assetBundleFile);
|
||||
|
||||
var assetBundleName = assetBundleFile.Replace(dir, string.Empty).Replace("\\", "");
|
||||
|
||||
streamWriter.WriteLine(GetAssetBundleFileIndex(assetBundleName, fileMD5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static string GetAssetBundleFileIndex(string assetBundleName, string assetBundleFileMD5)
|
||||
{
|
||||
return $"{assetBundleName}{AssetBundleSplitChar}{assetBundleFileMD5}";
|
||||
}
|
||||
|
||||
public const string ManifestSuffix = ".manifest";
|
||||
public static readonly string AssetBundlesManifestName = $"{AssetBundlesName}{ManifestSuffix}";
|
||||
public static readonly string AssetBundleSplitChar = "|";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 737ea17132a549b08f03ba4d45d7bc56
|
||||
timeCreated: 1705384441
|
||||
@@ -0,0 +1,241 @@
|
||||
using FairyGUI;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BingoBrain.Editor
|
||||
{
|
||||
public static class FGUIContollerConstantKit
|
||||
{
|
||||
private const string content =
|
||||
@"
|
||||
|
||||
/// <summary>
|
||||
/// FGUI控制器自动生成
|
||||
/// </summary>
|
||||
namespace FGUI.{0}
|
||||
{
|
||||
public partial class className
|
||||
{
|
||||
{1} }
|
||||
}";
|
||||
|
||||
private static Dictionary<string, string> classDic = new();
|
||||
private static Dictionary<string, string> constClassDic = new();
|
||||
|
||||
private static string C_DestFolderPath =
|
||||
Application.dataPath + "/Comgreate/Logic/FGUI/ControlDefine/Common/";
|
||||
|
||||
private static string DestFolderPath =
|
||||
Application.dataPath + "/Comgreate/Logic/FGUI/ControlDefine/Project/";
|
||||
|
||||
[MenuItem("Tools/CreateCtrl")]
|
||||
public static void CreateAllControllerScripts()
|
||||
{
|
||||
UIPackage.RemoveAllPackages();
|
||||
|
||||
CreateControllerScripts(true);
|
||||
CreateControllerScripts(false);
|
||||
|
||||
UIPackage.RemoveAllPackages();
|
||||
var stage = GameObject.Find("Stage");
|
||||
if (stage != null)
|
||||
{
|
||||
Object.DestroyImmediate(stage);
|
||||
}
|
||||
|
||||
var stageCamera = GameObject.Find("Stage Camera");
|
||||
if (stageCamera != null)
|
||||
{
|
||||
Object.DestroyImmediate(stageCamera);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void CreateController_ScriptsCommon()
|
||||
{
|
||||
UIPackage.RemoveAllPackages();
|
||||
|
||||
CreateControllerScripts(true);
|
||||
|
||||
UIPackage.RemoveAllPackages();
|
||||
}
|
||||
|
||||
|
||||
public static void CreateController_ScriptsProject()
|
||||
{
|
||||
UIPackage.RemoveAllPackages();
|
||||
|
||||
CreateControllerScripts(false);
|
||||
|
||||
UIPackage.RemoveAllPackages();
|
||||
}
|
||||
|
||||
private static void CreateControllerScripts(bool isCreateCommon)
|
||||
{
|
||||
classDic.Clear();
|
||||
constClassDic.Clear();
|
||||
|
||||
string[] ids = AssetDatabase.FindAssets("_fui t:textAsset");
|
||||
foreach (var item in ids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(item);
|
||||
int pos = assetPath.LastIndexOf("_fui");
|
||||
if (pos == -1)
|
||||
continue;
|
||||
|
||||
assetPath = assetPath.Substring(0, pos);
|
||||
LoadOneUI(assetPath, isCreateCommon);
|
||||
}
|
||||
|
||||
CreateScripts(isCreateCommon);
|
||||
}
|
||||
|
||||
private static void CreateScripts(bool isCreateCommon)
|
||||
{
|
||||
if (isCreateCommon)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Directory.Exists(DestFolderPath))
|
||||
{
|
||||
Directory.Delete(DestFolderPath, true);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(DestFolderPath);
|
||||
}
|
||||
|
||||
string startPre = isCreateCommon ? C_DestFolderPath : DestFolderPath;
|
||||
foreach (var item in classDic)
|
||||
{
|
||||
if (item.Key.StartsWith(startPre))
|
||||
FileKit.CreateTxt(item.Key, item.Value, true);
|
||||
}
|
||||
|
||||
foreach (var item in constClassDic)
|
||||
{
|
||||
if (item.Key.StartsWith(startPre))
|
||||
FileKit.CreateTxt(item.Key, item.Value, true);
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
private static void LoadOneUI(string resPath, bool isCreateCommon)
|
||||
{
|
||||
string objName = new FileInfo(Path.GetFullPath(resPath)).Name;
|
||||
UIPackage pkg = UIPackage.GetByName(objName);
|
||||
if (pkg == null)
|
||||
{
|
||||
pkg = UIPackage.AddPackage(resPath);
|
||||
}
|
||||
|
||||
foreach (var item in pkg.GetItems())
|
||||
{
|
||||
if (item.type == PackageItemType.Component)
|
||||
{
|
||||
GComponent gComponent = null;
|
||||
|
||||
var tmpGomponent = pkg.CreateObject(item.name);
|
||||
gComponent = tmpGomponent as GComponent;
|
||||
|
||||
if (gComponent == null)
|
||||
{
|
||||
DisposeGObject(tmpGomponent);
|
||||
continue;
|
||||
}
|
||||
|
||||
string tmpPropertyStr = "";
|
||||
string constPropertyStr = "";
|
||||
List<string> nameList = new List<string>();
|
||||
foreach (var tmp in gComponent.Controllers)
|
||||
{
|
||||
nameList.Clear();
|
||||
for (int i = 0; i < tmp.pageCount; i++)
|
||||
{
|
||||
string name = tmp.GetPageName(i).Replace(" ", "");
|
||||
if (nameList.Contains(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nameList.Add(name);
|
||||
|
||||
string summary = @" /// <summary>
|
||||
/// {0}:{1}
|
||||
/// </summary>
|
||||
";
|
||||
summary = string.Format(summary, i, tmp.GetPageName(i));
|
||||
|
||||
tmpPropertyStr += summary;
|
||||
constPropertyStr += summary;
|
||||
string contName = tmp.name.Replace("cont_", "");
|
||||
contName = FirstLetterToUpper(contName);
|
||||
tmpPropertyStr += string.Format("public int _{0}_{1} = {2};\r\n", contName, name, i);
|
||||
constPropertyStr += string.Format("public const int {0}_{1} = {2};\r\n", contName, name, i);
|
||||
}
|
||||
}
|
||||
|
||||
List<Controller> controllers = gComponent.Controllers;
|
||||
DisposeGObject(gComponent);
|
||||
if (controllers.Count != 0)
|
||||
{
|
||||
if (isCreateCommon)
|
||||
{
|
||||
if (!pkg.name.StartsWith("C"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pkg.name.StartsWith("C"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
string objClassContent = content.Replace("{0}", pkg.name).Replace("{1}", tmpPropertyStr)
|
||||
.Replace("className", item.name);
|
||||
string constClassContent = content.Replace("{0}", pkg.name).Replace("{1}", constPropertyStr)
|
||||
.Replace("className", item.name);
|
||||
string prePath = pkg.name.StartsWith("C") ? C_DestFolderPath : DestFolderPath;
|
||||
string path = prePath + pkg.name + "/" + item.name + "_AutoCreator.cs";
|
||||
string constPath = prePath + pkg.name + "/" + item.name + "_Const.cs";
|
||||
if (!classDic.ContainsKey(path))
|
||||
{
|
||||
classDic.Add(path, objClassContent);
|
||||
constClassDic.Add(constPath, constClassContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void DisposeGObject(GObject gObject)
|
||||
{
|
||||
gObject.Dispose();
|
||||
if (gObject.displayObject != null)
|
||||
{
|
||||
if (gObject.displayObject.gameObject)
|
||||
{
|
||||
Object.Destroy(gObject.displayObject.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string FirstLetterToUpper(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
|
||||
if (str.Length > 1)
|
||||
return char.ToUpper(str[0]) + str.Substring(1);
|
||||
|
||||
return str.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b4c038f692d4d7f9790562beb637d71
|
||||
timeCreated: 1705385121
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BingoBrain.Editor
|
||||
{
|
||||
public static class FileKit
|
||||
{
|
||||
public static void CreateTxt(string path, string Txt, bool IsCover = false, bool IsAssetPath = false)
|
||||
{
|
||||
if (IsAssetPath)
|
||||
{
|
||||
path = Application.dataPath.Replace("Assets", string.Empty) + path;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(GetFullDiretoryPath(path)))
|
||||
{
|
||||
Directory.CreateDirectory(GetFullDiretoryPath(path));
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
if (!IsCover)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
File.WriteAllText(path, Txt, new UTF8Encoding(false));
|
||||
}
|
||||
|
||||
public static string GetFullDiretoryPath(string filePath)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
return filePath.Replace(fileName, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fee6df4c57174846a073a8c9de464651
|
||||
timeCreated: 1705385221
|
||||
Reference in New Issue
Block a user