mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
3
JNFrame2/Assets/Plugins/SHFrame/Editor/Inspector.meta
Normal file
3
JNFrame2/Assets/Plugins/SHFrame/Editor/Inspector.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c82324a2508f46ba992bdbdd6f6741af
|
||||
timeCreated: 1728874852
|
@@ -0,0 +1,58 @@
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架 Inspector 抽象类。
|
||||
/// </summary>
|
||||
public abstract class GameFrameworkInspector : UnityEditor.Editor
|
||||
{
|
||||
private bool m_IsCompiling = false;
|
||||
|
||||
/// <summary>
|
||||
/// 绘制事件。
|
||||
/// </summary>
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (m_IsCompiling && !EditorApplication.isCompiling)
|
||||
{
|
||||
m_IsCompiling = false;
|
||||
OnCompileComplete();
|
||||
}
|
||||
else if (!m_IsCompiling && EditorApplication.isCompiling)
|
||||
{
|
||||
m_IsCompiling = true;
|
||||
OnCompileStart();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编译开始事件。
|
||||
/// </summary>
|
||||
protected virtual void OnCompileStart()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编译完成事件。
|
||||
/// </summary>
|
||||
protected virtual void OnCompileComplete()
|
||||
{
|
||||
}
|
||||
|
||||
protected bool IsPrefabInHierarchy(UnityEngine.Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
return PrefabUtility.GetPrefabAssetType(obj) != PrefabAssetType.Regular;
|
||||
#else
|
||||
return PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5bb373d9bcd4bd45861670fa5208e05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,164 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ProcedureModule))]
|
||||
internal class ProcedureModuleInspector : GameFrameworkInspector
|
||||
{
|
||||
|
||||
private SerializedProperty m_AvailableProcedureTypeNames = null;
|
||||
private SerializedProperty m_EntranceProcedureTypeName = null;
|
||||
|
||||
private string[] m_ProcedureTypeNames = null;
|
||||
private List<string> m_CurrentAvailableProcedureTypeNames = null;
|
||||
private int m_EntranceProcedureIndex = -1;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
ProcedureModule t = (ProcedureModule)target;
|
||||
|
||||
if (string.IsNullOrEmpty(m_EntranceProcedureTypeName.stringValue))
|
||||
{
|
||||
EditorGUILayout.HelpBox("Entrance procedure is invalid.", MessageType.Error);
|
||||
}
|
||||
else if (EditorApplication.isPlaying)
|
||||
{
|
||||
EditorGUILayout.LabelField("Current Procedure", t.CurrentProcedure == null ? "None" : t.CurrentProcedure.GetType().ToString());
|
||||
}
|
||||
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||
{
|
||||
GUILayout.Label("Available Procedures", EditorStyles.boldLabel);
|
||||
if (m_ProcedureTypeNames.Length > 0)
|
||||
{
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
{
|
||||
foreach (string procedureTypeName in m_ProcedureTypeNames)
|
||||
{
|
||||
bool selected = m_CurrentAvailableProcedureTypeNames.Contains(procedureTypeName);
|
||||
if (selected != EditorGUILayout.ToggleLeft(procedureTypeName, selected))
|
||||
{
|
||||
if (!selected)
|
||||
{
|
||||
m_CurrentAvailableProcedureTypeNames.Add(procedureTypeName);
|
||||
WriteAvailableProcedureTypeNames();
|
||||
}
|
||||
else if (procedureTypeName != m_EntranceProcedureTypeName.stringValue)
|
||||
{
|
||||
m_CurrentAvailableProcedureTypeNames.Remove(procedureTypeName);
|
||||
WriteAvailableProcedureTypeNames();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("There is no available procedure.", MessageType.Warning);
|
||||
}
|
||||
|
||||
if (m_CurrentAvailableProcedureTypeNames.Count > 0)
|
||||
{
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
int selectedIndex = EditorGUILayout.Popup("Entrance Procedure", m_EntranceProcedureIndex, m_CurrentAvailableProcedureTypeNames.ToArray());
|
||||
if (selectedIndex != m_EntranceProcedureIndex)
|
||||
{
|
||||
m_EntranceProcedureIndex = selectedIndex;
|
||||
m_EntranceProcedureTypeName.stringValue = m_CurrentAvailableProcedureTypeNames[selectedIndex];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("Select available procedures first.", MessageType.Info);
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
protected override void OnCompileComplete()
|
||||
{
|
||||
base.OnCompileComplete();
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_AvailableProcedureTypeNames = serializedObject.FindProperty("m_AvailableProcedureTypeNames");
|
||||
m_EntranceProcedureTypeName = serializedObject.FindProperty("m_EntranceProcedureTypeName");
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void RefreshTypeNames()
|
||||
{
|
||||
m_ProcedureTypeNames = Type.GetRuntimeTypeNames(typeof(ProcedureBase));
|
||||
ReadAvailableProcedureTypeNames();
|
||||
int oldCount = m_CurrentAvailableProcedureTypeNames.Count;
|
||||
m_CurrentAvailableProcedureTypeNames = m_CurrentAvailableProcedureTypeNames.Where(x => m_ProcedureTypeNames.Contains(x)).ToList();
|
||||
if (m_CurrentAvailableProcedureTypeNames.Count != oldCount)
|
||||
{
|
||||
WriteAvailableProcedureTypeNames();
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(m_EntranceProcedureTypeName.stringValue))
|
||||
{
|
||||
m_EntranceProcedureIndex = m_CurrentAvailableProcedureTypeNames.IndexOf(m_EntranceProcedureTypeName.stringValue);
|
||||
if (m_EntranceProcedureIndex < 0)
|
||||
{
|
||||
m_EntranceProcedureTypeName.stringValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private void ReadAvailableProcedureTypeNames()
|
||||
{
|
||||
m_CurrentAvailableProcedureTypeNames = new List<string>();
|
||||
int count = m_AvailableProcedureTypeNames.arraySize;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
m_CurrentAvailableProcedureTypeNames.Add(m_AvailableProcedureTypeNames.GetArrayElementAtIndex(i).stringValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteAvailableProcedureTypeNames()
|
||||
{
|
||||
m_AvailableProcedureTypeNames.ClearArray();
|
||||
if (m_CurrentAvailableProcedureTypeNames == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentAvailableProcedureTypeNames.Sort();
|
||||
int count = m_CurrentAvailableProcedureTypeNames.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
m_AvailableProcedureTypeNames.InsertArrayElementAtIndex(i);
|
||||
m_AvailableProcedureTypeNames.GetArrayElementAtIndex(i).stringValue = m_CurrentAvailableProcedureTypeNames[i];
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(m_EntranceProcedureTypeName.stringValue))
|
||||
{
|
||||
m_EntranceProcedureIndex = m_CurrentAvailableProcedureTypeNames.IndexOf(m_EntranceProcedureTypeName.stringValue);
|
||||
if (m_EntranceProcedureIndex < 0)
|
||||
{
|
||||
m_EntranceProcedureTypeName.stringValue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b7cfce7101724148bff891cf2d4b1ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc.meta
Normal file
3
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 491bee99e8764148b5c48943de8eca58
|
||||
timeCreated: 1728874937
|
@@ -0,0 +1,18 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置路径属性。
|
||||
/// </summary>
|
||||
public abstract class ConfigPathAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a44584e09310c440b42613540114652
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,179 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志脚本宏定义。
|
||||
/// </summary>
|
||||
public static class LogScriptingDefineSymbols
|
||||
{
|
||||
private const string EnableLogScriptingDefineSymbol = "ENABLE_LOG";
|
||||
private const string EnableDebugAndAboveLogScriptingDefineSymbol = "ENABLE_DEBUG_AND_ABOVE_LOG";
|
||||
private const string EnableInfoAndAboveLogScriptingDefineSymbol = "ENABLE_INFO_AND_ABOVE_LOG";
|
||||
private const string EnableWarningAndAboveLogScriptingDefineSymbol = "ENABLE_WARNING_AND_ABOVE_LOG";
|
||||
private const string EnableErrorAndAboveLogScriptingDefineSymbol = "ENABLE_ERROR_AND_ABOVE_LOG";
|
||||
private const string EnableFatalAndAboveLogScriptingDefineSymbol = "ENABLE_FATAL_AND_ABOVE_LOG";
|
||||
private const string EnableDebugLogScriptingDefineSymbol = "ENABLE_DEBUG_LOG";
|
||||
private const string EnableInfoLogScriptingDefineSymbol = "ENABLE_INFO_LOG";
|
||||
private const string EnableWarningLogScriptingDefineSymbol = "ENABLE_WARNING_LOG";
|
||||
private const string EnableErrorLogScriptingDefineSymbol = "ENABLE_ERROR_LOG";
|
||||
private const string EnableFatalLogScriptingDefineSymbol = "ENABLE_FATAL_LOG";
|
||||
|
||||
private static readonly string[] AboveLogScriptingDefineSymbols = new string[]
|
||||
{
|
||||
EnableDebugAndAboveLogScriptingDefineSymbol,
|
||||
EnableInfoAndAboveLogScriptingDefineSymbol,
|
||||
EnableWarningAndAboveLogScriptingDefineSymbol,
|
||||
EnableErrorAndAboveLogScriptingDefineSymbol,
|
||||
EnableFatalAndAboveLogScriptingDefineSymbol
|
||||
};
|
||||
|
||||
private static readonly string[] SpecifyLogScriptingDefineSymbols = new string[]
|
||||
{
|
||||
EnableDebugLogScriptingDefineSymbol,
|
||||
EnableInfoLogScriptingDefineSymbol,
|
||||
EnableWarningLogScriptingDefineSymbol,
|
||||
EnableErrorLogScriptingDefineSymbol,
|
||||
EnableFatalLogScriptingDefineSymbol
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 禁用所有日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Disable All Logs", false, 30)]
|
||||
public static void DisableAllLogs()
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableLogScriptingDefineSymbol);
|
||||
|
||||
foreach (string specifyLogScriptingDefineSymbol in SpecifyLogScriptingDefineSymbols)
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(specifyLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
foreach (string aboveLogScriptingDefineSymbol in AboveLogScriptingDefineSymbols)
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(aboveLogScriptingDefineSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启所有日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable All Logs", false, 31)]
|
||||
public static void EnableAllLogs()
|
||||
{
|
||||
DisableAllLogs();
|
||||
ScriptingDefineSymbols.AddScriptingDefineSymbol(EnableLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启调试及以上级别的日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable Debug And Above Logs", false, 32)]
|
||||
public static void EnableDebugAndAboveLogs()
|
||||
{
|
||||
SetAboveLogScriptingDefineSymbol(EnableDebugAndAboveLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启信息及以上级别的日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable Info And Above Logs", false, 33)]
|
||||
public static void EnableInfoAndAboveLogs()
|
||||
{
|
||||
SetAboveLogScriptingDefineSymbol(EnableInfoAndAboveLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启警告及以上级别的日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable Warning And Above Logs", false, 34)]
|
||||
public static void EnableWarningAndAboveLogs()
|
||||
{
|
||||
SetAboveLogScriptingDefineSymbol(EnableWarningAndAboveLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启错误及以上级别的日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable Error And Above Logs", false, 35)]
|
||||
public static void EnableErrorAndAboveLogs()
|
||||
{
|
||||
SetAboveLogScriptingDefineSymbol(EnableErrorAndAboveLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启严重错误及以上级别的日志脚本宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("SHFrame/Log Scripting Define Symbols/Enable Fatal And Above Logs", false, 36)]
|
||||
public static void EnableFatalAndAboveLogs()
|
||||
{
|
||||
SetAboveLogScriptingDefineSymbol(EnableFatalAndAboveLogScriptingDefineSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置日志脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="aboveLogScriptingDefineSymbol">要设置的日志脚本宏定义。</param>
|
||||
public static void SetAboveLogScriptingDefineSymbol(string aboveLogScriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(aboveLogScriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string i in AboveLogScriptingDefineSymbols)
|
||||
{
|
||||
if (i == aboveLogScriptingDefineSymbol)
|
||||
{
|
||||
DisableAllLogs();
|
||||
ScriptingDefineSymbols.AddScriptingDefineSymbol(aboveLogScriptingDefineSymbol);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置日志脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="specifyLogScriptingDefineSymbols">要设置的日志脚本宏定义。</param>
|
||||
public static void SetSpecifyLogScriptingDefineSymbols(string[] specifyLogScriptingDefineSymbols)
|
||||
{
|
||||
if (specifyLogScriptingDefineSymbols == null || specifyLogScriptingDefineSymbols.Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool removed = false;
|
||||
foreach (string specifyLogScriptingDefineSymbol in specifyLogScriptingDefineSymbols)
|
||||
{
|
||||
if (string.IsNullOrEmpty(specifyLogScriptingDefineSymbol))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (string i in SpecifyLogScriptingDefineSymbols)
|
||||
{
|
||||
if (i == specifyLogScriptingDefineSymbol)
|
||||
{
|
||||
if (!removed)
|
||||
{
|
||||
removed = true;
|
||||
DisableAllLogs();
|
||||
}
|
||||
|
||||
ScriptingDefineSymbols.AddScriptingDefineSymbol(specifyLogScriptingDefineSymbol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 741cdd24b13dbc447bfc730187792597
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,157 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 脚本宏定义。
|
||||
/// </summary>
|
||||
public static class ScriptingDefineSymbols
|
||||
{
|
||||
private static readonly BuildTargetGroup[] BuildTargetGroups = new BuildTargetGroup[]
|
||||
{
|
||||
BuildTargetGroup.Standalone,
|
||||
BuildTargetGroup.iOS,
|
||||
BuildTargetGroup.Android,
|
||||
BuildTargetGroup.WSA,
|
||||
BuildTargetGroup.WebGL
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 检查指定平台是否存在指定的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="buildTargetGroup">要检查脚本宏定义的平台。</param>
|
||||
/// <param name="scriptingDefineSymbol">要检查的脚本宏定义。</param>
|
||||
/// <returns>指定平台是否存在指定的脚本宏定义。</returns>
|
||||
public static bool HasScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptingDefineSymbol))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] scriptingDefineSymbols = GetScriptingDefineSymbols(buildTargetGroup);
|
||||
foreach (string i in scriptingDefineSymbols)
|
||||
{
|
||||
if (i == scriptingDefineSymbol)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为指定平台增加指定的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="buildTargetGroup">要增加脚本宏定义的平台。</param>
|
||||
/// <param name="scriptingDefineSymbol">要增加的脚本宏定义。</param>
|
||||
public static void AddScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> scriptingDefineSymbols = new List<string>(GetScriptingDefineSymbols(buildTargetGroup))
|
||||
{
|
||||
scriptingDefineSymbol
|
||||
};
|
||||
|
||||
SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为指定平台移除指定的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="buildTargetGroup">要移除脚本宏定义的平台。</param>
|
||||
/// <param name="scriptingDefineSymbol">要移除的脚本宏定义。</param>
|
||||
public static void RemoveScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> scriptingDefineSymbols = new List<string>(GetScriptingDefineSymbols(buildTargetGroup));
|
||||
while (scriptingDefineSymbols.Contains(scriptingDefineSymbol))
|
||||
{
|
||||
scriptingDefineSymbols.Remove(scriptingDefineSymbol);
|
||||
}
|
||||
|
||||
SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为所有平台增加指定的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="scriptingDefineSymbol">要增加的脚本宏定义。</param>
|
||||
public static void AddScriptingDefineSymbol(string scriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups)
|
||||
{
|
||||
AddScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为所有平台移除指定的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="scriptingDefineSymbol">要移除的脚本宏定义。</param>
|
||||
public static void RemoveScriptingDefineSymbol(string scriptingDefineSymbol)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scriptingDefineSymbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups)
|
||||
{
|
||||
RemoveScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定平台的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="buildTargetGroup">要获取脚本宏定义的平台。</param>
|
||||
/// <returns>平台的脚本宏定义。</returns>
|
||||
public static string[] GetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup)
|
||||
{
|
||||
return PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定平台的脚本宏定义。
|
||||
/// </summary>
|
||||
/// <param name="buildTargetGroup">要设置脚本宏定义的平台。</param>
|
||||
/// <param name="scriptingDefineSymbols">要设置的脚本宏定义。</param>
|
||||
public static void SetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup, string[] scriptingDefineSymbols)
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Join(";", scriptingDefineSymbols));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 420190c1c055c6f4a9a23e452e7d770f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
118
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc/Type.cs
Normal file
118
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc/Type.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型相关的实用函数。
|
||||
/// </summary>
|
||||
internal static class Type
|
||||
{
|
||||
private static readonly string[] RuntimeAssemblyNames =
|
||||
{
|
||||
"SHFrame",
|
||||
"SHFrame.Runtime",
|
||||
};
|
||||
|
||||
private static readonly string[] RuntimeOrEditorAssemblyNames =
|
||||
{
|
||||
"SHFrame",
|
||||
"SHFrame.Runtime",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置路径。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">配置类型。</typeparam>
|
||||
/// <returns>配置路径。</returns>
|
||||
internal static string GetConfigurationPath<T>() where T : ConfigPathAttribute
|
||||
{
|
||||
foreach (System.Type type in Utility.Assembly.GetTypes())
|
||||
{
|
||||
if (!type.IsAbstract || !type.IsSealed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
|
||||
{
|
||||
if (fieldInfo.FieldType == typeof(string) && fieldInfo.IsDefined(typeof(T), false))
|
||||
{
|
||||
return (string)fieldInfo.GetValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
|
||||
{
|
||||
if (propertyInfo.PropertyType == typeof(string) && propertyInfo.IsDefined(typeof(T), false))
|
||||
{
|
||||
return (string)propertyInfo.GetValue(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在运行时程序集中获取指定基类的所有子类的名称。
|
||||
/// </summary>
|
||||
/// <param name="typeBase">基类类型。</param>
|
||||
/// <returns>指定基类的所有子类的名称。</returns>
|
||||
internal static string[] GetRuntimeTypeNames(System.Type typeBase)
|
||||
{
|
||||
return GetTypeNames(typeBase, RuntimeAssemblyNames);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在运行时或编辑器程序集中获取指定基类的所有子类的名称。
|
||||
/// </summary>
|
||||
/// <param name="typeBase">基类类型。</param>
|
||||
/// <returns>指定基类的所有子类的名称。</returns>
|
||||
internal static string[] GetRuntimeOrEditorTypeNames(System.Type typeBase)
|
||||
{
|
||||
return GetTypeNames(typeBase, RuntimeOrEditorAssemblyNames);
|
||||
}
|
||||
|
||||
private static string[] GetTypeNames(System.Type typeBase, string[] assemblyNames)
|
||||
{
|
||||
List<string> typeNames = new List<string>();
|
||||
foreach (string assemblyName in assemblyNames)
|
||||
{
|
||||
Assembly assembly = null;
|
||||
try
|
||||
{
|
||||
assembly = Assembly.Load(assemblyName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
System.Type[] types = assembly.GetTypes();
|
||||
foreach (System.Type type in types)
|
||||
{
|
||||
if (type.IsClass && !type.IsAbstract && typeBase.IsAssignableFrom(type))
|
||||
{
|
||||
typeNames.Add(type.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typeNames.Sort();
|
||||
return typeNames.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
11
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc/Type.cs.meta
Normal file
11
JNFrame2/Assets/Plugins/SHFrame/Editor/Misc/Type.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82f73088e6e538649abbb7e35e3d6bf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -5,7 +5,7 @@
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de",
|
||||
"GUID:ac484fe5e443f4146a129450c27f000f"
|
||||
"GUID:23aed7c57bb0a5d49aeaef92abb5bfff"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
@@ -8,7 +8,7 @@ namespace SHFrame
|
||||
[InitializeOnLoad]
|
||||
public class SceneSwitchLeftButton
|
||||
{
|
||||
private static readonly string SceneMain = "Boot";
|
||||
private static readonly string SceneMain = "HotMain";
|
||||
|
||||
static SceneSwitchLeftButton()
|
||||
{
|
||||
|
@@ -86,7 +86,7 @@ namespace SHFrame
|
||||
|
||||
AudioAgents = new List<AudioAgent>(32);
|
||||
InstanceRoot = new GameObject(Utility.Text.Format("Audio Category - {0}", _audioMixerGroup.name)).transform;
|
||||
InstanceRoot.SetParent(GameModule.Audio.InstanceRoot);
|
||||
InstanceRoot.SetParent(SHFrameModule.Audio.InstanceRoot);
|
||||
for (int index = 0; index < _maxChannel; index++)
|
||||
{
|
||||
AudioAgent audioAgent = new AudioAgent();
|
||||
|
@@ -343,9 +343,9 @@ namespace SHFrame
|
||||
if (_instanceRoot == null)
|
||||
{
|
||||
_instanceRoot = new GameObject("AudioModule Instances").transform;
|
||||
_instanceRoot.SetParent(GameModule.Audio.transform);
|
||||
_instanceRoot.SetParent(SHFrameModule.Audio.transform);
|
||||
_instanceRoot.localScale = Vector3.one;
|
||||
GameModule.Audio.InstanceRoot = _instanceRoot;
|
||||
SHFrameModule.Audio.InstanceRoot = _instanceRoot;
|
||||
}
|
||||
|
||||
try
|
||||
|
@@ -85,7 +85,7 @@ namespace SHFrame
|
||||
}
|
||||
_modules.Clear();
|
||||
|
||||
GameModule.Shutdown(shutdownType);
|
||||
SHFrameModule.Shutdown(shutdownType);
|
||||
|
||||
if (shutdownType == ShutdownType.None)
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ namespace SHFrame
|
||||
/// <summary>
|
||||
/// 游戏模块。
|
||||
/// </summary>
|
||||
public partial class GameModule : MonoBehaviour
|
||||
public partial class SHFrameModule : MonoBehaviour
|
||||
{
|
||||
private static readonly Dictionary<Type, Module> _moduleMaps = new Dictionary<Type, Module>(ModuleImpSystem.DesignModuleCount);
|
||||
|
||||
@@ -24,75 +24,25 @@ namespace SHFrame
|
||||
}
|
||||
|
||||
private static RootModule _base;
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取调试模块。
|
||||
// /// </summary>
|
||||
// public static DebuggerModule Debugger
|
||||
// {
|
||||
// get => _debugger ??= Get<DebuggerModule>();
|
||||
// private set => _debugger = value;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static DebuggerModule _debugger;
|
||||
|
||||
/// <summary>
|
||||
/// 获取音频模块。
|
||||
/// </summary>
|
||||
public static AudioModule Audio => _audio ??= Get<AudioModule>();
|
||||
private static AudioModule _audio;
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机模块。
|
||||
/// </summary>
|
||||
public static FSM.FsmModule Fsm => _fsm ??= Get<FSM.FsmModule>();
|
||||
|
||||
private static FSM.FsmModule _fsm;
|
||||
|
||||
/// <summary>
|
||||
/// 流程管理模块。
|
||||
/// </summary>
|
||||
public static ProcedureModule Procedure => _procedure ??= Get<ProcedureModule>();
|
||||
|
||||
private static ProcedureModule _procedure;
|
||||
|
||||
/// <summary>
|
||||
/// 获取对象池模块。
|
||||
/// </summary>
|
||||
public static ObjectPoolModule ObjectPool => _objectPool ??= Get<ObjectPoolModule>();
|
||||
|
||||
private static ObjectPoolModule _objectPool;
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取资源模块。
|
||||
// /// </summary>
|
||||
// public static ResourceModule Resource => _resource ??= Get<ResourceModule>();
|
||||
//
|
||||
// private static ResourceModule _resource;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取音频模块。
|
||||
/// </summary>
|
||||
public static AudioModule Audio => _audio ??= Get<AudioModule>();
|
||||
|
||||
private static AudioModule _audio;
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取配置模块。
|
||||
// /// </summary>
|
||||
// public static SettingModule Setting => _setting ??= Get<SettingModule>();
|
||||
//
|
||||
// private static SettingModule _setting;
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取多语言模块。
|
||||
// /// </summary>
|
||||
// public static LocalizationModule Localization => _localization ??= Get<LocalizationModule>();
|
||||
//
|
||||
// private static LocalizationModule _localization;
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取计时器模块。
|
||||
// /// </summary>
|
||||
// public static TimerModule Timer => _timer ??= Get<TimerModule>();
|
||||
//
|
||||
// private static TimerModule _timer;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -111,7 +61,6 @@ namespace SHFrame
|
||||
|
||||
T module = ModuleSystem.GetModule<T>();
|
||||
|
||||
|
||||
Log.Assert(condition: module != null, $"{typeof(T)} is null");
|
||||
|
||||
_moduleMaps.Add(type, module);
|
||||
@@ -123,7 +72,7 @@ namespace SHFrame
|
||||
{
|
||||
Log.Info("GameModule Active");
|
||||
_gameModuleRoot = gameObject;
|
||||
_gameModuleRoot.name = $"[{nameof(GameModule)}]";
|
||||
_gameModuleRoot.name = $"[{nameof(SHFrameModule)}]";
|
||||
DontDestroyOnLoad(_gameModuleRoot);
|
||||
}
|
||||
|
||||
@@ -136,15 +85,9 @@ namespace SHFrame
|
||||
_gameModuleRoot = null;
|
||||
}
|
||||
_moduleMaps.Clear();
|
||||
|
||||
_base = null;
|
||||
// _debugger = null;
|
||||
_fsm = null;
|
||||
_procedure = null;
|
||||
_objectPool = null;
|
||||
// _resource = null;
|
||||
_audio = null;
|
||||
// _setting = null;
|
||||
_procedure = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "SHFrame",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23aed7c57bb0a5d49aeaef92abb5bfff
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
JNFrame2/Assets/Plugins/SHFrame/Runtime/SHGame.meta
Normal file
3
JNFrame2/Assets/Plugins/SHFrame/Runtime/SHGame.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e005776846e48c4a5e41f261eea14df
|
||||
timeCreated: 1728875736
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5644558033ff4e3cb5af03aa0afdb5e0
|
||||
timeCreated: 1728875898
|
@@ -0,0 +1,99 @@
|
||||
using System.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Plugins.SHFrame.SHGame.YooAsset;
|
||||
using SHFrame;
|
||||
using SHFrame.FSM;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace Plugins.SHFrame.SHGame.Procedure
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化资源包
|
||||
/// </summary>
|
||||
public class ProcedureInitializePackage : ProcedureBase
|
||||
{
|
||||
|
||||
public static EPlayMode PlayMode = EPlayMode.OfflinePlayMode;
|
||||
public static string RawFilePackageName = "RawFilePackage";
|
||||
public static string DefaultPackageName = "DefaultPackage";
|
||||
|
||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
InitPackage(procedureOwner).Forget();
|
||||
}
|
||||
|
||||
private async UniTask InitPackage(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
|
||||
Log.Debug($"YooAssets 开始初始化");
|
||||
|
||||
// 1.初始化资源系统
|
||||
YooAssets.Initialize();
|
||||
|
||||
var rawFilePackage = await InitYooPackage(RawFilePackageName, true);
|
||||
var defaultPackage = await InitYooPackage(DefaultPackageName, false);
|
||||
Log.Debug($"YooAssets 初始化完成");
|
||||
|
||||
// 设置该资源包为默认的资源包,可以使用YooAssets相关加载接口加载该资源包内容。
|
||||
YooAssets.SetDefaultPackage(defaultPackage);
|
||||
|
||||
// 切换到更新资源清单
|
||||
ChangeState<ProcedureUpdatePackageManifest>(procedureOwner);
|
||||
|
||||
}
|
||||
|
||||
private async UniTask<ResourcePackage> InitYooPackage(string packageName, bool isRaw)
|
||||
{
|
||||
// 创建资源包
|
||||
var package = YooAssets.TryGetPackage(packageName) ?? YooAssets.CreatePackage(packageName);
|
||||
|
||||
InitializationOperation initOperation = null;
|
||||
switch (PlayMode)
|
||||
{
|
||||
case EPlayMode.EditorSimulateMode:
|
||||
Log.Debug($"编辑器模拟模式");
|
||||
// 编辑器模拟模式
|
||||
EDefaultBuildPipeline buildPipeline = isRaw ? EDefaultBuildPipeline.RawFileBuildPipeline : EDefaultBuildPipeline.ScriptableBuildPipeline;
|
||||
var initParametersEditorSimulateMode = new EditorSimulateModeParameters();
|
||||
initParametersEditorSimulateMode.EditorFileSystemParameters =
|
||||
FileSystemParameters.CreateDefaultEditorFileSystemParameters(
|
||||
EditorSimulateModeHelper.SimulateBuild(buildPipeline, packageName)
|
||||
);
|
||||
initOperation = package.InitializeAsync(initParametersEditorSimulateMode);
|
||||
break;
|
||||
case EPlayMode.OfflinePlayMode:
|
||||
Log.Debug($"单机模式");
|
||||
// 单机模式
|
||||
var createParameters = new OfflinePlayModeParameters
|
||||
{
|
||||
BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters()
|
||||
};
|
||||
initOperation = package.InitializeAsync(createParameters);
|
||||
break;
|
||||
case EPlayMode.HostPlayMode:
|
||||
Log.Debug($"在线模式");
|
||||
//联机运行模式
|
||||
string defaultHostServer = "http://127.0.0.1/CDN/Android/v1.0";
|
||||
string fallbackHostServer = "http://127.0.0.1/CDN/Android/v1.0";
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
var cacheFileSystem = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
var buildinFileSystem = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
|
||||
var initParameters = new HostPlayModeParameters();
|
||||
initParameters.BuildinFileSystemParameters = buildinFileSystem;
|
||||
initParameters.CacheFileSystemParameters = cacheFileSystem;
|
||||
initOperation = package.InitializeAsync(initParameters);
|
||||
break;
|
||||
}
|
||||
|
||||
Log.Debug($"执行初始化");
|
||||
await initOperation;
|
||||
|
||||
return package;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 426ff69263b7461194f0e87ff5b32100
|
||||
timeCreated: 1728876063
|
@@ -0,0 +1,70 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SHFrame;
|
||||
using SHFrame.FSM;
|
||||
using YooAsset;
|
||||
|
||||
namespace Plugins.SHFrame.SHGame.Procedure
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新资源清单
|
||||
/// </summary>
|
||||
public class ProcedureUpdatePackageManifest : ProcedureBase
|
||||
{
|
||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
UpdateManifest(procedureOwner).Forget();
|
||||
}
|
||||
|
||||
private async UniTask UpdateManifest(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
bool result = await UpdatePackageManifest(ProcedureInitializePackage.RawFilePackageName);
|
||||
if (!result) return;
|
||||
|
||||
result = await UpdatePackageManifest(ProcedureInitializePackage.DefaultPackageName);
|
||||
if (!result) return;
|
||||
|
||||
//切换到更新资源版本
|
||||
ChangeState<ProcedureUpdatePackageVersion>(procedureOwner);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新资源清单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async UniTask<bool> UpdatePackageManifest(string packageName)
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage(packageName);
|
||||
|
||||
//2.获取资源版本
|
||||
RequestPackageVersionOperation updateVerOperation = package.RequestPackageVersionAsync(false);
|
||||
await updateVerOperation.ToUniTask();
|
||||
|
||||
// TODO 如果初始化失败弹出提示界面
|
||||
if (updateVerOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
//初始化失败了 弹出提示
|
||||
Log.Error($"{package.PackageName} 获取远程资源版本信息失败: {updateVerOperation.Error}");
|
||||
return false;
|
||||
}
|
||||
|
||||
string packageVersion = updateVerOperation.PackageVersion;
|
||||
Log.Debug($"Init {package.PackageName} version : {packageVersion}");
|
||||
|
||||
//3.更新补丁清单
|
||||
UpdatePackageManifestOperation updateManifestOperation = package.UpdatePackageManifestAsync(packageVersion);
|
||||
await updateManifestOperation.ToUniTask();
|
||||
|
||||
if (updateManifestOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
//更新失败了 弹出提示
|
||||
Log.Error($"{package.PackageName} 更新资源版本清单失败: {updateManifestOperation.Error}");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa136220570f473bb1154a1aaf29a140
|
||||
timeCreated: 1728877120
|
@@ -0,0 +1,45 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SHFrame;
|
||||
using SHFrame.FSM;
|
||||
using YooAsset;
|
||||
|
||||
namespace Plugins.SHFrame.SHGame.Procedure
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新资源版本号
|
||||
/// </summary>
|
||||
public class ProcedureUpdatePackageVersion : ProcedureBase
|
||||
{
|
||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
UpdatePackages(procedureOwner).Forget();
|
||||
}
|
||||
|
||||
private async UniTask UpdatePackages(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
bool result = await UpdatePackageVersion(ProcedureInitializePackage.RawFilePackageName);
|
||||
if (!result) return;
|
||||
result = await UpdatePackageVersion(ProcedureInitializePackage.DefaultPackageName);
|
||||
if (!result) return;
|
||||
}
|
||||
|
||||
|
||||
private async UniTask<bool> UpdatePackageVersion(string packageName)
|
||||
{
|
||||
ResourcePackage package = YooAssets.GetPackage(packageName);
|
||||
//2.获取资源版本
|
||||
RequestPackageVersionOperation updateVerOperation = package.RequestPackageVersionAsync(false);
|
||||
await updateVerOperation.ToUniTask();
|
||||
|
||||
// TODO 如果初始化失败弹出提示界面
|
||||
if (updateVerOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Log.Error($"{package.PackageName} 获取远程资源版本信息失败: {updateVerOperation.Error}");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a53059ce506d495ab8adb95ae52979d0
|
||||
timeCreated: 1728877770
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc65a4d37b5c4c51953baaaee48d2c76
|
||||
timeCreated: 1728876983
|
@@ -0,0 +1,105 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace Plugins.SHFrame.SHGame.YooAsset
|
||||
{
|
||||
public class RemoteServices : IRemoteServices
|
||||
{
|
||||
private string defaultHostServer;
|
||||
private string fallbackHostServer;
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
this.defaultHostServer = defaultHostServer;
|
||||
this.fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
public string GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return defaultHostServer;
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return fallbackHostServer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件解密流
|
||||
/// </summary>
|
||||
public class BundleStream : FileStream
|
||||
{
|
||||
public const byte KEY = 64;
|
||||
|
||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||
{
|
||||
}
|
||||
|
||||
public BundleStream(string path, FileMode mode) : base(path, mode)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
var index = base.Read(array, offset, count);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] ^= KEY;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件流加载解密类
|
||||
/// </summary>
|
||||
public class FileStreamDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c2a4207de1f4b1995db5f2f3a8d6e62
|
||||
timeCreated: 1728649446
|
Reference in New Issue
Block a user