修复技能输入并更新战斗资源
This commit is contained in:
@@ -46,9 +46,9 @@ namespace XGame
|
||||
private const float JoystickPadding = 100.0f;
|
||||
private const float JoystickDeadZone = 0.18f;
|
||||
private const float JoystickAcquireRadiusMultiplier = 1.6f;
|
||||
private const float CameraMinDistance = 2.0f;
|
||||
private const float CameraMaxDistance = 8f;
|
||||
private const float CameraDefaultDistance = 4.5f;
|
||||
private const float CameraMinDistance = 4.0f;
|
||||
private const float CameraMaxDistance = 15f;
|
||||
private const float CameraDefaultDistance = 6.0f;
|
||||
private const float CameraMinPitch = 20f;
|
||||
private const float CameraMaxPitch = 75f;
|
||||
private const float CameraMouseOrbitSensitivity = 0.2f;
|
||||
@@ -102,6 +102,9 @@ namespace XGame
|
||||
private bool actionPadLoading;
|
||||
private bool actorBehaviorCatalogLoading;
|
||||
private bool actorBehaviorCatalogLoaded;
|
||||
private bool hasPendingActionButtonEvent;
|
||||
private ActionButtonEvent pendingActionButtonEvent;
|
||||
private Vector3 pendingActionButtonForward;
|
||||
private static int materialLogCount;
|
||||
|
||||
public void Initialize(Action<FrameworkOpcode, byte[]> sendFramework, int playerId, string playerName, int figure)
|
||||
@@ -453,6 +456,11 @@ namespace XGame
|
||||
|
||||
private Vector3 GetMoveDirection()
|
||||
{
|
||||
if (IsSelfBehaviorActive())
|
||||
{
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
Camera cam = Camera.main;
|
||||
Vector3 forward = cam != null ? cam.transform.forward : Vector3.forward;
|
||||
Vector3 right = cam != null ? cam.transform.right : Vector3.right;
|
||||
@@ -466,6 +474,12 @@ namespace XGame
|
||||
Input.GetKey(KeyCode.D));
|
||||
}
|
||||
|
||||
private bool IsSelfBehaviorActive()
|
||||
{
|
||||
return actorBehaviorRuntime != null
|
||||
&& actorBehaviorRuntime.HasActiveBehavior(selfPlayerId);
|
||||
}
|
||||
|
||||
public static Vector3 MapMoveInputForTest(
|
||||
Vector2 joystickInput,
|
||||
Vector3 cameraForward,
|
||||
@@ -1008,6 +1022,7 @@ namespace XGame
|
||||
actorBehaviorRuntime.RegisterCatalog(catalog);
|
||||
actorBehaviorCatalogLoaded = true;
|
||||
UpdateActorBehaviorActors();
|
||||
ConsumePendingActionButtonEvent();
|
||||
}
|
||||
|
||||
private void RegisterActorBehavior(Avatar avatar)
|
||||
@@ -1164,19 +1179,52 @@ namespace XGame
|
||||
{
|
||||
if (LobbyActorBehaviorRuntime.IsSecondaryATrigger(evt))
|
||||
{
|
||||
QueuePendingActionButtonEvent(evt, GetSelfSkillForward());
|
||||
Debug.LogWarning("[LobbyWorldController] actor behavior catalog is not ready.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BehaviorStartResult result = actorBehaviorRuntime.HandleActionButton(evt, selfPlayerId, GetSelfSkillForward());
|
||||
HandleReadyActionButtonEvent(evt, GetSelfSkillForward());
|
||||
}
|
||||
|
||||
private void QueuePendingActionButtonEvent(ActionButtonEvent evt, Vector3 fallbackForward)
|
||||
{
|
||||
if (hasPendingActionButtonEvent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hasPendingActionButtonEvent = true;
|
||||
pendingActionButtonEvent = evt;
|
||||
pendingActionButtonForward = fallbackForward;
|
||||
}
|
||||
|
||||
private void ConsumePendingActionButtonEvent()
|
||||
{
|
||||
if (!hasPendingActionButtonEvent || !actorBehaviorCatalogLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ActionButtonEvent evt = pendingActionButtonEvent;
|
||||
Vector3 fallbackForward = pendingActionButtonForward;
|
||||
hasPendingActionButtonEvent = false;
|
||||
pendingActionButtonEvent = default;
|
||||
pendingActionButtonForward = Vector3.zero;
|
||||
HandleReadyActionButtonEvent(evt, fallbackForward);
|
||||
}
|
||||
|
||||
private void HandleReadyActionButtonEvent(ActionButtonEvent evt, Vector3 fallbackForward)
|
||||
{
|
||||
BehaviorStartResult result = actorBehaviorRuntime.HandleActionButton(evt, selfPlayerId, fallbackForward);
|
||||
if (result.Success)
|
||||
{
|
||||
DrainActorBehaviorEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.Error != "button ignored")
|
||||
if (result.Error != "button ignored" && result.Error != "actor already has active behavior")
|
||||
{
|
||||
Debug.LogWarning("[LobbyWorldController] start behavior failed: " + result.Error);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ namespace XGame.VirtualInput
|
||||
private float pointerDownTime;
|
||||
private bool holdStarted;
|
||||
private float nextHoldTickTime;
|
||||
private Vector2 pointerDownScreenPosition;
|
||||
private Vector2 lastScreenPosition;
|
||||
private ActionButtonEvent lastDragEvent;
|
||||
|
||||
@@ -278,6 +279,7 @@ namespace XGame.VirtualInput
|
||||
pointerDownTime = now;
|
||||
nextHoldTickTime = now + holdThresholdSeconds + holdTickIntervalSeconds;
|
||||
holdStarted = false;
|
||||
pointerDownScreenPosition = screenPosition;
|
||||
lastScreenPosition = screenPosition;
|
||||
lastDragEvent = MakeEvent(ActionButtonPhase.Down, screenPosition, pointerId, now);
|
||||
SetAimVisible(false);
|
||||
@@ -344,9 +346,9 @@ namespace XGame.VirtualInput
|
||||
return ActionButtonPhase.Cancel;
|
||||
}
|
||||
|
||||
return MakeEvent(ActionButtonPhase.Release, screenPosition, activePointerId, Time.unscaledTime).Distance01 >= releaseDistanceThreshold01
|
||||
? ActionButtonPhase.Release
|
||||
: ActionButtonPhase.Tap;
|
||||
return IsInsideButton(screenPosition) && !HasMeaningfulDrag(screenPosition)
|
||||
? ActionButtonPhase.Tap
|
||||
: ActionButtonPhase.Release;
|
||||
}
|
||||
|
||||
private ActionButtonEvent MakeEvent(ActionButtonPhase phase, Vector2 screenPosition, int pointerId, float now)
|
||||
@@ -378,6 +380,18 @@ namespace XGame.VirtualInput
|
||||
return RectTransformUtility.RectangleContainsScreenPoint(cancelArea, screenPosition, GetUICamera(cancelArea));
|
||||
}
|
||||
|
||||
private bool IsInsideButton(Vector2 screenPosition)
|
||||
{
|
||||
RectTransform rect = rectTransform != null ? rectTransform : transform as RectTransform;
|
||||
return rect != null && RectTransformUtility.RectangleContainsScreenPoint(rect, screenPosition, GetUICamera(rect));
|
||||
}
|
||||
|
||||
private bool HasMeaningfulDrag(Vector2 screenPosition)
|
||||
{
|
||||
float threshold = GetScreenRadius() * maxDragRadiusMultiplier * releaseDistanceThreshold01;
|
||||
return (screenPosition - pointerDownScreenPosition).magnitude >= Mathf.Max(1f, threshold);
|
||||
}
|
||||
|
||||
private void RefreshVisuals()
|
||||
{
|
||||
bool interactable = IsInteractable;
|
||||
@@ -424,6 +438,7 @@ namespace XGame.VirtualInput
|
||||
pointerDown = false;
|
||||
activePointerId = int.MinValue;
|
||||
holdStarted = false;
|
||||
pointerDownScreenPosition = Vector2.zero;
|
||||
lastScreenPosition = Vector2.zero;
|
||||
lastDragEvent = default;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user