(client) feat:实现指定位置生成实体
This commit is contained in:
@ -384,6 +384,142 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &465209085
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 465209086}
|
||||||
|
- component: {fileID: 465209088}
|
||||||
|
- component: {fileID: 465209087}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: prompt
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &465209086
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 465209085}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1672332560}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 110, y: -160}
|
||||||
|
m_SizeDelta: {x: 200, y: 300}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &465209087
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 465209085}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_text: "\u8BF4\u660E\u6587\u672C"
|
||||||
|
m_isRightToLeft: 0
|
||||||
|
m_fontAsset: {fileID: 11400000, guid: 317edb274e9c5144a9916937bdbf7716, type: 2}
|
||||||
|
m_sharedMaterial: {fileID: -1361428157011412921, guid: 317edb274e9c5144a9916937bdbf7716, type: 2}
|
||||||
|
m_fontSharedMaterials: []
|
||||||
|
m_fontMaterial: {fileID: 0}
|
||||||
|
m_fontMaterials: []
|
||||||
|
m_fontColor32:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 2533359615
|
||||||
|
m_fontColor: {r: 1, g: 1, b: 1, a: 0.5882353}
|
||||||
|
m_enableVertexGradient: 0
|
||||||
|
m_colorMode: 3
|
||||||
|
m_fontColorGradient:
|
||||||
|
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_fontColorGradientPreset: {fileID: 0}
|
||||||
|
m_spriteAsset: {fileID: 0}
|
||||||
|
m_tintAllSprites: 0
|
||||||
|
m_StyleSheet: {fileID: 0}
|
||||||
|
m_TextStyleHashCode: -1183493901
|
||||||
|
m_overrideHtmlColors: 0
|
||||||
|
m_faceColor:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4294967295
|
||||||
|
m_fontSize: 12
|
||||||
|
m_fontSizeBase: 12
|
||||||
|
m_fontWeight: 400
|
||||||
|
m_enableAutoSizing: 0
|
||||||
|
m_fontSizeMin: 18
|
||||||
|
m_fontSizeMax: 72
|
||||||
|
m_fontStyle: 1
|
||||||
|
m_HorizontalAlignment: 1
|
||||||
|
m_VerticalAlignment: 256
|
||||||
|
m_textAlignment: 65535
|
||||||
|
m_characterSpacing: 0
|
||||||
|
m_wordSpacing: 0
|
||||||
|
m_lineSpacing: 0
|
||||||
|
m_lineSpacingMax: 0
|
||||||
|
m_paragraphSpacing: 0
|
||||||
|
m_charWidthMaxAdj: 0
|
||||||
|
m_TextWrappingMode: 1
|
||||||
|
m_wordWrappingRatios: 0.4
|
||||||
|
m_overflowMode: 0
|
||||||
|
m_linkedTextComponent: {fileID: 0}
|
||||||
|
parentLinkedComponent: {fileID: 0}
|
||||||
|
m_enableKerning: 0
|
||||||
|
m_ActiveFontFeatures: 6e72656b
|
||||||
|
m_enableExtraPadding: 0
|
||||||
|
checkPaddingRequired: 0
|
||||||
|
m_isRichText: 1
|
||||||
|
m_EmojiFallbackSupport: 1
|
||||||
|
m_parseCtrlCharacters: 1
|
||||||
|
m_isOrthographic: 1
|
||||||
|
m_isCullingEnabled: 0
|
||||||
|
m_horizontalMapping: 0
|
||||||
|
m_verticalMapping: 0
|
||||||
|
m_uvLineOffset: 0
|
||||||
|
m_geometrySortingOrder: 0
|
||||||
|
m_IsTextObjectScaleStatic: 0
|
||||||
|
m_VertexBufferAutoSizeReduction: 0
|
||||||
|
m_useMaxVisibleDescender: 1
|
||||||
|
m_pageToDisplay: 1
|
||||||
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
|
m_isVolumetricText: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_baseMaterial: {fileID: 0}
|
||||||
|
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
--- !u!222 &465209088
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 465209085}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
--- !u!1 &603423466
|
--- !u!1 &603423466
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -1205,6 +1341,142 @@ MonoBehaviour:
|
|||||||
needPause: 1
|
needPause: 1
|
||||||
isInputOccupied: 0
|
isInputOccupied: 0
|
||||||
actionButton: 27
|
actionButton: 27
|
||||||
|
--- !u!1 &1620768398
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1620768399}
|
||||||
|
- component: {fileID: 1620768401}
|
||||||
|
- component: {fileID: 1620768400}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Text (TMP) (1)
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1620768399
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1620768398}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1672332560}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 1}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: -15}
|
||||||
|
m_SizeDelta: {x: 200, y: 20}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &1620768400
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1620768398}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_text: "\u6309Esc\u8FD4\u56DE\uFF0C\u70B9\u51FB\u4EFB\u610F\u4F4D\u7F6E\u751F\u6210"
|
||||||
|
m_isRightToLeft: 0
|
||||||
|
m_fontAsset: {fileID: 11400000, guid: 317edb274e9c5144a9916937bdbf7716, type: 2}
|
||||||
|
m_sharedMaterial: {fileID: -1361428157011412921, guid: 317edb274e9c5144a9916937bdbf7716, type: 2}
|
||||||
|
m_fontSharedMaterials: []
|
||||||
|
m_fontMaterial: {fileID: 0}
|
||||||
|
m_fontMaterials: []
|
||||||
|
m_fontColor32:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 2533359615
|
||||||
|
m_fontColor: {r: 1, g: 1, b: 1, a: 0.5882353}
|
||||||
|
m_enableVertexGradient: 0
|
||||||
|
m_colorMode: 3
|
||||||
|
m_fontColorGradient:
|
||||||
|
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_fontColorGradientPreset: {fileID: 0}
|
||||||
|
m_spriteAsset: {fileID: 0}
|
||||||
|
m_tintAllSprites: 0
|
||||||
|
m_StyleSheet: {fileID: 0}
|
||||||
|
m_TextStyleHashCode: -1183493901
|
||||||
|
m_overrideHtmlColors: 0
|
||||||
|
m_faceColor:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4294967295
|
||||||
|
m_fontSize: 12
|
||||||
|
m_fontSizeBase: 12
|
||||||
|
m_fontWeight: 400
|
||||||
|
m_enableAutoSizing: 0
|
||||||
|
m_fontSizeMin: 18
|
||||||
|
m_fontSizeMax: 72
|
||||||
|
m_fontStyle: 1
|
||||||
|
m_HorizontalAlignment: 2
|
||||||
|
m_VerticalAlignment: 512
|
||||||
|
m_textAlignment: 65535
|
||||||
|
m_characterSpacing: 0
|
||||||
|
m_wordSpacing: 0
|
||||||
|
m_lineSpacing: 0
|
||||||
|
m_lineSpacingMax: 0
|
||||||
|
m_paragraphSpacing: 0
|
||||||
|
m_charWidthMaxAdj: 0
|
||||||
|
m_TextWrappingMode: 1
|
||||||
|
m_wordWrappingRatios: 0.4
|
||||||
|
m_overflowMode: 0
|
||||||
|
m_linkedTextComponent: {fileID: 0}
|
||||||
|
parentLinkedComponent: {fileID: 0}
|
||||||
|
m_enableKerning: 0
|
||||||
|
m_ActiveFontFeatures: 6e72656b
|
||||||
|
m_enableExtraPadding: 0
|
||||||
|
checkPaddingRequired: 0
|
||||||
|
m_isRichText: 1
|
||||||
|
m_EmojiFallbackSupport: 1
|
||||||
|
m_parseCtrlCharacters: 1
|
||||||
|
m_isOrthographic: 1
|
||||||
|
m_isCullingEnabled: 0
|
||||||
|
m_horizontalMapping: 0
|
||||||
|
m_verticalMapping: 0
|
||||||
|
m_uvLineOffset: 0
|
||||||
|
m_geometrySortingOrder: 0
|
||||||
|
m_IsTextObjectScaleStatic: 0
|
||||||
|
m_VertexBufferAutoSizeReduction: 0
|
||||||
|
m_useMaxVisibleDescender: 1
|
||||||
|
m_pageToDisplay: 1
|
||||||
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
|
m_isVolumetricText: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_baseMaterial: {fileID: 0}
|
||||||
|
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
--- !u!222 &1620768401
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1620768398}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
--- !u!1 &1672332559
|
--- !u!1 &1672332559
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -1235,6 +1507,8 @@ RectTransform:
|
|||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1988809572}
|
- {fileID: 1988809572}
|
||||||
|
- {fileID: 1620768399}
|
||||||
|
- {fileID: 465209086}
|
||||||
m_Father: {fileID: 1236970686}
|
m_Father: {fileID: 1236970686}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
@ -1258,6 +1532,7 @@ MonoBehaviour:
|
|||||||
needPause: 1
|
needPause: 1
|
||||||
isInputOccupied: 1
|
isInputOccupied: 1
|
||||||
actionButton: 0
|
actionButton: 0
|
||||||
|
promptText: {fileID: 465209087}
|
||||||
--- !u!1 &1891846098
|
--- !u!1 &1891846098
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -1652,6 +1927,10 @@ PrefabInstance:
|
|||||||
propertyPath: actionButton
|
propertyPath: actionButton
|
||||||
value: 282
|
value: 282
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7904664609186573076, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
|
||||||
|
propertyPath: entityPlacementUI
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1672332561}
|
||||||
- target: {fileID: 8099462081536526843, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
|
- target: {fileID: 8099462081536526843, guid: 72cde32427f7d914692a7b0d22fb791d, type: 3}
|
||||||
propertyPath: m_AnchorMax.x
|
propertyPath: m_AnchorMax.x
|
||||||
value: 1
|
value: 1
|
||||||
|
@ -8,214 +8,170 @@ using Object = UnityEngine.Object;
|
|||||||
|
|
||||||
namespace Base
|
namespace Base
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// UI窗口输入控制和管理类
|
||||||
|
/// 负责根据输入显示/隐藏UI,并根据UI状态管理游戏暂停。
|
||||||
|
/// </summary>
|
||||||
public class UIInputControl : Utils.MonoSingleton<UIInputControl>, ITickUI
|
public class UIInputControl : Utils.MonoSingleton<UIInputControl>, ITickUI
|
||||||
{
|
{
|
||||||
public Dictionary<KeyCode, UIBase> UIwindowKeys = new();
|
// 存储场景中所有UIBase的实例
|
||||||
private List<UIBase> noKeyWindows = new();
|
private List<UIBase> _allWindows = new List<UIBase>();
|
||||||
private List<UIBase> allWindows = new(); // 新增:所有窗口的集合
|
// 缓存当前可见的窗口
|
||||||
|
private readonly List<UIBase> _visibleWindows = new List<UIBase>();
|
||||||
|
|
||||||
public void TickUI()
|
private bool needUpdate = false;
|
||||||
|
/// <summary>
|
||||||
|
/// 查找并注册场景中所有的UI窗口,包括非激活状态的
|
||||||
|
/// </summary>
|
||||||
|
private void RegisterAllWindows()
|
||||||
{
|
{
|
||||||
foreach (var kvp in UIwindowKeys)
|
_allWindows.Clear();
|
||||||
|
|
||||||
|
// 获取当前活动场景中的所有 GameObject
|
||||||
|
var activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||||
|
if (!activeScene.isLoaded)
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(kvp.Key))
|
Debug.LogWarning("当前场景未加载,无法注册窗口!");
|
||||||
{
|
return;
|
||||||
HandleWindowActivation(kvp.Value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init()
|
// 遍历场景中的所有根对象,并查找其子对象中的 UIBase
|
||||||
|
foreach (var rootGameObject in activeScene.GetRootGameObjects())
|
||||||
{
|
{
|
||||||
UIwindowKeys.Clear();
|
var windows = rootGameObject.GetComponentsInChildren<UIBase>(true);
|
||||||
noKeyWindows.Clear();
|
_allWindows.AddRange(windows);
|
||||||
allWindows.Clear(); // 清空所有窗口集合
|
|
||||||
|
|
||||||
var uiInstances = Resources.FindObjectsOfTypeAll<UIBase>();
|
|
||||||
|
|
||||||
foreach (var uiBase in uiInstances)
|
|
||||||
{
|
|
||||||
allWindows.Add(uiBase); // 添加到所有窗口集合
|
|
||||||
|
|
||||||
var key = uiBase.actionButton;
|
|
||||||
if (key == KeyCode.None)
|
|
||||||
{
|
|
||||||
noKeyWindows.Add(uiBase);
|
|
||||||
uiBase.Hide();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UIwindowKeys.ContainsKey(key))
|
// 去重(如果有重复的窗口)
|
||||||
{
|
_allWindows = _allWindows.Distinct().ToList();
|
||||||
Debug.LogWarning($"Key '{key}' is already assigned to another window. Skipping...");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
UIwindowKeys[key] = uiBase;
|
// 初始化所有窗口为隐藏状态
|
||||||
uiBase.Hide();
|
foreach (var window in _allWindows)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleWindowActivation(UIBase targetWindow)
|
|
||||||
{
|
{
|
||||||
bool wasTargetVisible = targetWindow.IsVisible;
|
if (window != null && window.gameObject != null)
|
||||||
bool shouldCloseExclusive = false;
|
|
||||||
bool exclusiveWindowWasOpen = false;
|
|
||||||
|
|
||||||
// 第一次遍历:检查是否有需要关闭的独占窗口
|
|
||||||
foreach (var window in allWindows)
|
|
||||||
{
|
|
||||||
if (window == targetWindow) continue;
|
|
||||||
|
|
||||||
if (window.IsVisible && window.exclusive)
|
|
||||||
{
|
|
||||||
// 记录有独占窗口打开且需要关闭
|
|
||||||
shouldCloseExclusive = true;
|
|
||||||
exclusiveWindowWasOpen = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 第二次遍历:根据条件关闭窗口
|
|
||||||
foreach (var window in allWindows)
|
|
||||||
{
|
|
||||||
if (window == targetWindow) continue;
|
|
||||||
|
|
||||||
if (window.IsVisible)
|
|
||||||
{
|
|
||||||
// 关闭所有独占窗口(无论是新窗口打开还是关闭)
|
|
||||||
// 或当目标窗口是独占窗口时关闭所有其他窗口
|
|
||||||
if (window.exclusive || targetWindow.exclusive || shouldCloseExclusive)
|
|
||||||
{
|
{
|
||||||
window.Hide();
|
window.Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needUpdate = true;
|
||||||
|
Debug.Log($"窗口数量{_allWindows.Count}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切换目标窗口状态
|
/// <summary>
|
||||||
if (wasTargetVisible)
|
/// UI逻辑更新循环,需要被外部的某个管理器在Update中调用
|
||||||
|
/// </summary>
|
||||||
|
public void TickUI()
|
||||||
{
|
{
|
||||||
targetWindow.Hide();
|
//使用这个是为了让输入独占窗口关闭自己后不会立即激活其他窗口的按键,延迟一帧
|
||||||
|
if (needUpdate)
|
||||||
|
{
|
||||||
|
// 更新可见窗口缓存和暂停状态
|
||||||
|
UpdateVisibleWindowsCache();
|
||||||
|
UpdatePauseState();
|
||||||
|
needUpdate = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(_visibleWindows.Any(window => window.isInputOccupied))
|
||||||
|
return;
|
||||||
|
foreach (var window in _allWindows)
|
||||||
|
{
|
||||||
|
// 检查窗口是否设置了有效的激活按键,并且该按键在本帧被按下
|
||||||
|
if (window.actionButton == KeyCode.None || !Input.GetKeyDown(window.actionButton)) continue;
|
||||||
|
if (window.IsVisible)
|
||||||
|
{
|
||||||
|
// 如果窗口当前是可见的,且未占用输入,则通过按键隐藏它
|
||||||
|
if (!window.isInputOccupied)
|
||||||
|
{
|
||||||
|
Hide(window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
targetWindow.Show();
|
// 如果窗口当前是隐藏的,则显示它
|
||||||
|
Show(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新暂停状态(优化版)
|
|
||||||
UpdatePauseState(exclusiveWindowWasOpen, targetWindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePauseState(bool exclusiveWindowWasOpen, UIBase targetWindow)
|
|
||||||
{
|
|
||||||
bool needPause = false;
|
|
||||||
|
|
||||||
foreach (var window in allWindows)
|
|
||||||
{
|
|
||||||
if (window.IsVisible && window.needPause)
|
|
||||||
{
|
|
||||||
needPause = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 只在状态改变时更新
|
|
||||||
if (Base.Clock.Instance.Pause != needPause)
|
|
||||||
{
|
|
||||||
Base.Clock.Instance.Pause = needPause;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模拟按键输入切换窗口
|
/// 公开的显示窗口方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyCode">要模拟的按键</param>
|
/// <param name="windowToShow">要显示的窗口</param>
|
||||||
public void SimulateKeyPress(KeyCode keyCode)
|
public void Show(UIBase windowToShow)
|
||||||
{
|
{
|
||||||
if (UIwindowKeys.TryGetValue(keyCode, out UIBase targetWindow))
|
if (!windowToShow || windowToShow.IsVisible) return;
|
||||||
|
|
||||||
|
// 如果窗口是独占的,隐藏所有其他窗口
|
||||||
|
if (windowToShow.exclusive)
|
||||||
{
|
{
|
||||||
HandleWindowActivation(targetWindow); // 调用内部逻辑处理
|
List<UIBase> windowsToHide = new List<UIBase>(_visibleWindows);
|
||||||
|
foreach (var visibleWindow in windowsToHide)
|
||||||
|
{
|
||||||
|
Hide(visibleWindow);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
// 显示目标窗口并更新缓存与暂停状态
|
||||||
|
windowToShow.Show();
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 公开的隐藏窗口方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="windowToHide">要隐藏的窗口</param>
|
||||||
|
public void Hide(UIBase windowToHide)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"No window is assigned to the key '{keyCode}'.");
|
if (!windowToHide || !windowToHide.IsVisible) return;
|
||||||
|
|
||||||
|
// 隐藏目标窗口并更新缓存与暂停状态
|
||||||
|
windowToHide.Hide();
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据当前所有可见窗口的 needPause 属性来更新游戏时钟的暂停状态
|
||||||
|
/// </summary>
|
||||||
|
private void UpdatePauseState()
|
||||||
|
{
|
||||||
|
bool shouldPause = _visibleWindows.Any(w => w.needPause);
|
||||||
|
if (Base.Clock.Instance.Pause != shouldPause)
|
||||||
|
{
|
||||||
|
Base.Clock.Instance.Pause = shouldPause;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 打开指定的窗口(无论是否有激活键)
|
/// 更新当前可见窗口的缓存列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="window">要打开的窗口</param>
|
private void UpdateVisibleWindowsCache()
|
||||||
public void OpenWindow(UIBase window)
|
|
||||||
{
|
{
|
||||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
_visibleWindows.Clear();
|
||||||
|
foreach (var window in _allWindows)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("Cannot open the specified window as it is not registered.");
|
if (window.IsVisible)
|
||||||
return;
|
{
|
||||||
|
_visibleWindows.Add(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 关闭指定的窗口(无论是否有激活键)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="window">要关闭的窗口</param>
|
|
||||||
public void CloseWindow(UIBase window)
|
|
||||||
{
|
|
||||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
|
||||||
{
|
|
||||||
Debug.LogWarning("Cannot close the specified window as it is not registered.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 切换指定窗口的显示状态(无论是否有激活键)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="window">要切换的窗口</param>
|
|
||||||
public void ToggleWindow(UIBase window)
|
|
||||||
{
|
|
||||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
|
||||||
{
|
|
||||||
Debug.LogWarning("Cannot toggle the specified window as it is not registered.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleWindowActivation(window); // 调用内部逻辑处理,标记为函数调用
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 在对象销毁时清理事件监听
|
|
||||||
/// </summary>
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 在对象启动时初始化
|
|
||||||
/// </summary>
|
|
||||||
protected override void OnStart()
|
protected override void OnStart()
|
||||||
{
|
{
|
||||||
// 注册场景加载事件
|
|
||||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||||
|
|
||||||
// 初始化时调用一次
|
// RegisterAllWindows();
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 场景加载完成后重新初始化
|
|
||||||
/// </summary>
|
|
||||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||||
{
|
{
|
||||||
// 场景加载完成后调用 Init 方法
|
RegisterAllWindows();
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,14 +9,4 @@ namespace Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MonsterAttributes
|
|
||||||
{
|
|
||||||
public int health = 10;
|
|
||||||
public int moveSpeed = 1;
|
|
||||||
public int attack = 1;
|
|
||||||
public int defense = 0;
|
|
||||||
public int attackSpeed = 2;
|
|
||||||
public int attackRange = 3;
|
|
||||||
public int attackTargetCount = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -101,3 +101,4 @@ namespace Entity
|
|||||||
Managers.EntityManage.Instance.GenerateDefaultEntity(entity.Position);
|
Managers.EntityManage.Instance.GenerateDefaultEntity(entity.Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ namespace UI
|
|||||||
{
|
{
|
||||||
public GameObject menuContent;
|
public GameObject menuContent;
|
||||||
|
|
||||||
|
public EntityPlacementUI entityPlacementUI;
|
||||||
|
|
||||||
public Prefab.TextPrefab textTemplate;
|
public Prefab.TextPrefab textTemplate;
|
||||||
public Prefab.ButtonPrefab buttonTemplate;
|
public Prefab.ButtonPrefab buttonTemplate;
|
||||||
|
|
||||||
@ -84,10 +86,10 @@ namespace UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 实例化预制件
|
// 实例化预制件
|
||||||
GameObject instance = Instantiate(prefab.gameObject, parent);
|
var instance = Instantiate(prefab.gameObject, parent);
|
||||||
|
|
||||||
// 获取实例化对象的脚本组件
|
// 获取实例化对象的脚本组件
|
||||||
T instantiatedComponent = instance.GetComponent<T>();
|
var instantiatedComponent = instance.GetComponent<T>();
|
||||||
|
|
||||||
if (instantiatedComponent == null)
|
if (instantiatedComponent == null)
|
||||||
{
|
{
|
||||||
@ -99,7 +101,16 @@ namespace UI
|
|||||||
|
|
||||||
private void GenerateEntityCallback(PawnDef pawnDef)
|
private void GenerateEntityCallback(PawnDef pawnDef)
|
||||||
{
|
{
|
||||||
Managers.EntityManage.Instance.GenerateEntity(pawnDef, new(0, 0));
|
entityPlacementUI.currentAction = () =>
|
||||||
|
{
|
||||||
|
// 将鼠标屏幕坐标转换为世界坐标,并确保 Z 值为 0
|
||||||
|
if (!Camera.main) return;
|
||||||
|
var worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||||
|
worldPosition.z = 0;
|
||||||
|
Managers.EntityManage.Instance.GenerateEntity(pawnDef, worldPosition);
|
||||||
|
};
|
||||||
|
entityPlacementUI.Prompt = $"当前生成器:\n名称:{pawnDef.label}\n描述:{pawnDef.description}";
|
||||||
|
Base.UIInputControl.Instance.Show(entityPlacementUI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,34 @@
|
|||||||
using Base;
|
using Base;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public delegate void NonReturnCallback();
|
||||||
public class EntityPlacementUI:UIBase,ITickUI
|
public class EntityPlacementUI:UIBase,ITickUI
|
||||||
{
|
{
|
||||||
public UnityAction currentAction = null;
|
public TMP_Text promptText;
|
||||||
|
|
||||||
|
public NonReturnCallback currentAction;
|
||||||
|
|
||||||
|
public string Prompt
|
||||||
|
{
|
||||||
|
get => promptText.text;
|
||||||
|
set => promptText.text = value;
|
||||||
|
}
|
||||||
public void TickUI()
|
public void TickUI()
|
||||||
{
|
{
|
||||||
if (!IsVisible||currentAction==null)
|
if (!IsVisible)
|
||||||
return;
|
return;
|
||||||
if (Input.GetMouseButton(0))
|
|
||||||
{
|
|
||||||
currentAction.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Escape))
|
if (Input.GetKeyDown(KeyCode.Escape))
|
||||||
{
|
{
|
||||||
Hide();
|
Base.UIInputControl.Instance.Hide(this);
|
||||||
|
}
|
||||||
|
if (currentAction!=null&&Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
currentAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ namespace UI
|
|||||||
{
|
{
|
||||||
public void ContinueButton()
|
public void ContinueButton()
|
||||||
{
|
{
|
||||||
Base.UIInputControl.Instance.CloseWindow(this);
|
Base.UIInputControl.Instance.Hide(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExitButton()
|
public void ExitButton()
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user