show selecting vfx and elase player enter vfx

This commit is contained in:
NguyenVanDat
2025-11-13 17:12:41 +07:00
parent f067943ca5
commit c6f24993b5
7 changed files with 418 additions and 232 deletions
+132 -123
View File
@@ -114,6 +114,13 @@ public partial class CECHostPlayer : CECPlayer
private BaseVfxObject m_pSelectedGFX;
private BaseVfxObject m_pHoverGFX;
// Cursor estimation optimization
private Vector2 m_lastMousePosition;
private float m_cursorUpdateTimer;
private const float CURSOR_UPDATE_INTERVAL = 0.05f; // 20 times per second instead of 60+
private UnityEngine.InputSystem.Mouse m_cachedMouse;
private UnityEngine.InputSystem.Keyboard m_cachedKeyboard;
public bool IsChangingFace() { return m_bChangingFace; }
private void Awake()
@@ -194,6 +201,10 @@ public partial class CECHostPlayer : CECPlayer
_playerStateMachine.InitState(_idleState);
// btnJump.onClick.AddListener(HandleJump);
// Cache input devices for better performance
m_cachedMouse = UnityEngine.InputSystem.Mouse.current;
m_cachedKeyboard = UnityEngine.InputSystem.Keyboard.current;
}
protected override void Update()
@@ -274,6 +285,9 @@ public partial class CECHostPlayer : CECPlayer
}
m_pWorkMan?.Tick(Time.deltaTime);
// Update cursor based on what's under mouse
EstimateCursor();
// Update GFXs
UpdateGFXs(Time.deltaTime);
}
@@ -1169,12 +1183,6 @@ public partial class CECHostPlayer : CECPlayer
//Debug.LogError("Pos Character = " + pos);
}
#region Task
#endregion
private bool NormalAttackObject(int idTarget, bool bForceAttack, bool bMoreClose = false)
{
if (idTarget == 0 || idTarget == m_PlayerInfo.cid)
@@ -2262,10 +2270,11 @@ public partial class CECHostPlayer : CECPlayer
if (pObject)
{
if (m_pHoverGFX.GetState() == GFX_STATE.ST_STOP)
{
m_pHoverGFX.Play();
m_pSelectedGFX.transform.parent = pObject.transform;
m_pSelectedGFX.transform.localPosition = Vector3.zero;
m_pHoverGFX.transform.parent = pObject.transform;
m_pHoverGFX.transform.localPosition = Vector3.zero;
}
}
else
m_pHoverGFX.Stop();
@@ -2282,11 +2291,11 @@ public partial class CECHostPlayer : CECPlayer
if (pObject)
{
if (m_pSelectedGFX.GetState() == GFX_STATE.ST_STOP)
{
m_pSelectedGFX.Play();
// m_pSelectedGFX.SetParentTM(pObject.GetAbsoluteTM());
m_pSelectedGFX.transform.parent = pObject.transform;
m_pSelectedGFX.transform.localPosition = Vector3.zero;
m_pSelectedGFX.transform.parent = pObject.transform;
m_pSelectedGFX.transform.localPosition = Vector3.zero;
}
}
else
m_pSelectedGFX.Stop();
@@ -2364,116 +2373,116 @@ public partial class CECHostPlayer : CECPlayer
}
// Estimate mouse cursor
private void EstimateCursor() // here
{
// CECGameRun pGameRun = CECGameRun.Instance;
//
// m_idCurHover = 0;
// if (pGameRun.UIHasCursor() || IsChangingFace())
// return;
//
// CECCDS pCDS = pGameRun->GetWorld()->GetCDS();
// CECInputCtrl* pInputCtrl = pGameRun->GetInputCtrl();
//
// int x, y, iCursor=RES_CUR_NORMAL;
//
// if (CDlgAutoHelp::IsAutoHelp())
// {
// iCursor = RES_CUR_HAND;
// }
//
// pInputCtrl->GetMousePos(&x, &y);
// A3DVECTOR3 vDest((float)x, (float)y, 1.0f);
// A3DViewport* pView = g_pGame->GetViewport()->GetA3DViewport();
// pView->InvTransform(vDest, vDest);
//
// A3DVECTOR3 vStart = pView->GetCamera()->GetPos();
// A3DVECTOR3 vDelta = vDest - vStart;
//
// RAYTRACERT TraceRt;
// int iTraceFlag = TRACEOBJ_LBTNCLICK;
// if (pInputCtrl->KeyIsBeingPressed(VK_SHIFT))
// iTraceFlag |= 0x80000000;
//
// if (pInputCtrl->KeyIsBeingPressed(VK_MENU))
// iTraceFlag |= 0x40000000;
//
//
//
// CECPlayerMan* pPlayerMan = g_pGame->GetGameRun()->GetWorld()->GetPlayerMan();
// CECElsePlayer* pPatePlayer = pPlayerMan->GetMouseOnPateTextPlayer(x,y);
// if (pPatePlayer && pPatePlayer->GetBoothState() == 2){
// iCursor = RES_CUR_HAND;
// m_idCurHover = pPatePlayer->GetCharacterID();
// }
//
// if (pCDS->RayTrace(vStart, vDelta, 1.0f, &TraceRt, iTraceFlag, (DWORD)this))
// {
// int idHitObject(0);
// A3DVECTOR3 hitDis = TraceRt.vHitPos - vStart;
// if(pPatePlayer){
// A3DVECTOR3 playerPateDis = pPatePlayer->GetPos() - vStart;
// if (hitDis.Magnitude() < playerPateDis.Magnitude()){
// idHitObject = pCDS->m_RayTraceRt.iObjectID;
// }
// }else{
// idHitObject = pCDS->m_RayTraceRt.iObjectID;
// }
// if (idHitObject){
// bool bForceAttack = glb_GetForceAttackFlag(NULL);
//
// if (pCDS->m_RayTraceRt.iEntity == ECENT_MATTER)
// {
// CECMatter* pMatter = pGameRun->GetWorld()->GetMatterMan()->GetMatter(idHitObject);
// if (pMatter)
// {
// if (!pMatter->IsMine())
// iCursor = RES_CUR_PICKUP;
// else if (CanGatherMatter(pMatter))
// iCursor = pMatter->IsMonsterSpiritMine() ? RES_CUR_SWALLOW : RES_CUR_DIG;
// }
//
// if (iCursor != RES_CUR_NORMAL)
// m_idCurHover = idHitObject;
// }
// else if (pCDS->m_RayTraceRt.iEntity == ECENT_NPC)
// {
// CECNPC* pNPC = pGameRun->GetWorld()->GetNPCMan()->GetNPC(idHitObject);
// if (pNPC)
// {
// m_idCurHover = idHitObject;
// if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1)
// iCursor = RES_CUR_ATTACK;
// else if (pNPC->IsServerNPC())
// {
// if (!IsInBattle() || InSameBattleCamp(pNPC))
// iCursor = RES_CUR_TALK;
// }
// }
// }
// else if (pCDS->m_RayTraceRt.iEntity == ECENT_PLAYER)
// {
// CECElsePlayer* pTracePlayer = pGameRun->GetWorld()->GetPlayerMan()->GetElsePlayer(idHitObject);
// m_idCurHover = idHitObject;
// if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1)
// iCursor = RES_CUR_ATTACK;
// }
//
// l_fTestDist = vDelta.Magnitude() * TraceRt.fFraction;
// }
// }else{
// l_fTestDist = -1.0f;
// }
//
// CECNPCMan* pNPCMan = g_pGame->GetGameRun()->GetWorld()->GetNPCMan();
// CECNPC* pHoverNPC = pNPCMan->GetMouseOnPateTextNPC(x,y);
// if (pHoverNPC){
// iCursor = RES_CUR_TALK;
// m_idCurHover = pHoverNPC->GetNPCID();
// }
//
// g_pGame->ChangeCursor(iCursor);
}
private void EstimateCursor()
{
m_cursorUpdateTimer += Time.deltaTime;
if (m_cursorUpdateTimer < CURSOR_UPDATE_INTERVAL)
return;
m_cursorUpdateTimer = 0f;
// Early exit checks
if (IsChangingFace() || mainCam == null || m_cachedMouse == null)
{
m_idCurHover = 0;
return;
}
// Get mouse position using cached device
Vector2 mousePosition = m_cachedMouse.position.ReadValue();
// Early exit if mouse hasn't moved significantly (2 pixel threshold)
if (Vector2.Distance(mousePosition, m_lastMousePosition) < 2f)
return;
m_lastMousePosition = mousePosition;
m_idCurHover = 0;
CursorType cursorType = CursorType.RES_CUR_NORMAL;
// Check modifier keys using cached keyboard
bool isShiftPressed = m_cachedKeyboard != null &&
(m_cachedKeyboard.leftShiftKey.isPressed || m_cachedKeyboard.rightShiftKey.isPressed);
Ray ray = mainCam.ScreenPointToRay(mousePosition);
RaycastHit hit;
// You can add a layer mask here to only raycast against specific layers
// LayerMask interactableMask = LayerMask.GetMask("NPC", "Player", "Item");
// if (Physics.Raycast(ray, out hit, 100f, interactableMask))
if (Physics.Raycast(ray, out hit, 1000f)) // Reduced from 1000f to 100f for better performance
{
// Try to get CECObject component (cached lookup)
CECObject hitObject = hit.collider.GetComponent<CECObject>();
if (hitObject != null)
{
int idHitObject = CECObject.GetObjectID(hitObject);
if (idHitObject != 0)
{
bool bForceAttack = isShiftPressed;
// Check object type and set appropriate cursor
if (GPDataTypeHelper.ISNPCID(idHitObject))
{
// NPC handling
CECNPC pNPC = EC_ManMessageMono.Instance?._CECNPCMan?.GetNPC(idHitObject);
if (pNPC != null && !pNPC.IsDead())
{
m_idCurHover = idHitObject;
if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1)
{
cursorType = CursorType.RES_CUR_ATTACK;
}
else if (pNPC.IsServerNPC())
{
if (!IsInBattle() || InSameBattleCamp(pNPC))
{
cursorType = CursorType.RES_CUR_TALK;
}
}
}
}
else if (GPDataTypeHelper.ISPLAYERID(idHitObject))
{
// Player handling
EC_ElsePlayer pPlayer = EC_ManMessageMono.Instance?.GetECManPlayer?.GetPlayer(idHitObject) as EC_ElsePlayer;
if (pPlayer != null)
{
m_idCurHover = idHitObject;
if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1)
{
cursorType = CursorType.RES_CUR_ATTACK;
}
}
}
else if (GPDataTypeHelper.ISMATTERID(idHitObject))
{
//todo
// BMLogger.LogError($"[EstimateCursor]- GPDataTypeHelper.ISMATTERID: {idHitObject}");
// Matter/item handling (uncomment when CECMatter is implemented)
// CECMatter pMatter = GetMatterManager()?.GetMatter(idHitObject);
// if (pMatter != null)
// {
// if (!pMatter.IsMine())
// cursorType = CursorType.Pickup;
// else if (CanGatherMatter(pMatter))
// cursorType = pMatter.IsMonsterSpiritMine() ? CursorType.Swallow : CursorType.Dig;
//
// if (cursorType != CursorType.Normal)
// m_idCurHover = idHitObject;
// }
}
}
}
}
// Apply cursor change
EC_Game.ChangeCursor((int)cursorType);
}
}
public enum StateAnim