Add pickup nearest button
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:543e09f5571b2d48dd57646eee06f8efbc71e6aaa62d6e8a98a529dec44b7364
|
||||
size 322591
|
||||
oid sha256:f85e6e6bc4d5b6af2e103cf46a846213439f86c209bed0512839f28b8c23a7c6
|
||||
size 326984
|
||||
|
||||
@@ -3,6 +3,7 @@ using BrewMonster.Network;
|
||||
using BrewMonster.Scripts;
|
||||
using CSNetwork.GPDataType;
|
||||
using PerfectWorld.Scripts;
|
||||
using PerfectWorld.Scripts.Managers;
|
||||
using CSNetwork;
|
||||
using UnityEngine;
|
||||
using static BrewMonster.Scripts.CECHPWork;
|
||||
@@ -610,6 +611,36 @@ namespace BrewMonster
|
||||
return bOK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HUD / shortcut: walk to and pick up the nearest ground item or money (not mines) within range.
|
||||
/// </summary>
|
||||
/// <param name="maxSearchRadiusH">Max horizontal distance to search (meters).</param>
|
||||
/// <returns>True if a matter was found and <see cref="PickupObject"/> started.</returns>
|
||||
public bool TryPickupNearestGroundMatter(float maxSearchRadiusH = 80f)
|
||||
{
|
||||
if (IsDead() || m_pWorkMan == null)
|
||||
return false;
|
||||
|
||||
if (m_pWorkMan.IsSitting())
|
||||
{
|
||||
UnityGameSession.c2s_CmdStandUp();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CanDo(ActionCanDo.CANDO_MOVETO))
|
||||
return false;
|
||||
|
||||
EC_ManMatter matterMan = EC_ManMessageMono.Instance?.EC_ManMatter;
|
||||
if (matterMan == null)
|
||||
return false;
|
||||
|
||||
CECMatter nearest = matterMan.GetNearestPickupableMatter(GetPos(), maxSearchRadiusH);
|
||||
if (nearest == null)
|
||||
return false;
|
||||
|
||||
return PickupObject(nearest.GetMatterID(), false);
|
||||
}
|
||||
|
||||
// Check whether host can gather specified matter / Check whether host can gather specified matter
|
||||
public bool CanGatherMatter(CECMatter pMatter)
|
||||
{
|
||||
|
||||
@@ -314,6 +314,31 @@ namespace PerfectWorld.Scripts.Managers
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nearest ground item or money matter within horizontal <paramref name="maxRadiusH"/> of <paramref name="hostPos"/>.
|
||||
/// Mines (gather nodes) are excluded — use direct click / gather flow for those.
|
||||
/// </summary>
|
||||
public CECMatter GetNearestPickupableMatter(A3DVECTOR3 hostPos, float maxRadiusH)
|
||||
{
|
||||
CECMatter best = null;
|
||||
float bestDist = float.MaxValue;
|
||||
foreach (var kv in m_MatterTab)
|
||||
{
|
||||
CECMatter m = kv.Value;
|
||||
if (m == null || !m)
|
||||
continue;
|
||||
if (m.IsMine())
|
||||
continue;
|
||||
|
||||
float d = m.CalcDist(hostPos, false);
|
||||
if (d > maxRadiusH || d >= bestDist)
|
||||
continue;
|
||||
bestDist = d;
|
||||
best = m;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
public CECMatter CreateMatter(info_matter info)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// HUD button: pick up the nearest ground item or money (host trace + TryPickupNearestGroundMatter).
|
||||
/// Assign to a Button or leave unassigned to use the component's own Button.
|
||||
/// </summary>
|
||||
public class PickupNearestButtonHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button button;
|
||||
[Tooltip("Horizontal search radius around the player (meters).")]
|
||||
[SerializeField] private float maxSearchRadius = 80f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (button == null)
|
||||
button = GetComponent<Button>();
|
||||
if (button != null)
|
||||
button.onClick.AddListener(OnPickupNearestClicked);
|
||||
else
|
||||
Debug.LogWarning("PickupNearestButtonHandler: No Button component found.");
|
||||
}
|
||||
|
||||
public void OnPickupNearestClicked()
|
||||
{
|
||||
var host = CECGameRun.Instance?.GetHostPlayer();
|
||||
if (host == null)
|
||||
{
|
||||
Debug.LogWarning("PickupNearestButtonHandler: Host player not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
host.TryPickupNearestGroundMatter(maxSearchRadius);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (button != null)
|
||||
button.onClick.RemoveListener(OnPickupNearestClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e67d421887e31f4ea9eee290568e9d2
|
||||
Reference in New Issue
Block a user