game: handling paper spawn pt2

This commit is contained in:
kookiekenobi 2025-02-13 05:49:32 +08:00
parent e2c9d671dc
commit 0b8ecee514
3 changed files with 82 additions and 3 deletions

View file

@ -3682,12 +3682,18 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 202364687, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
insertIndex: -1
addedObject: {fileID: 1903054097}
- targetCorrespondingSourceObject: {fileID: 202364687, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
insertIndex: -1
addedObject: {fileID: 1903054104}
- targetCorrespondingSourceObject: {fileID: 1670256624, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
insertIndex: -1
addedObject: {fileID: 1333053557}
- targetCorrespondingSourceObject: {fileID: 1670256624, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
insertIndex: -1
addedObject: {fileID: 1333053556}
- targetCorrespondingSourceObject: {fileID: 1670256624, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
insertIndex: -1
addedObject: {fileID: 1333053563}
m_SourcePrefab: {fileID: 100100000, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
--- !u!1 &442984533
GameObject:
@ -4607,6 +4613,7 @@ MonoBehaviour:
dayEnded: 0
shiftStarted: 0
currentNPC: {fileID: 0}
currentStampDoc: {fileID: 0}
frontWalkPoints:
- {fileID: 1521924626}
- {fileID: 2036976913}
@ -11500,6 +11507,27 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 1
m_PhysicsTriggerInteraction: 1
--- !u!135 &1333053563
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1333053550}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 0.03
m_Center: {x: 0, y: 0, z: -0.04}
--- !u!1001 &1351099538
PrefabInstance:
m_ObjectHideFlags: 0
@ -15832,6 +15860,27 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 1
m_PhysicsTriggerInteraction: 1
--- !u!135 &1903054104
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1903054091}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 0.03
m_Center: {x: 0, y: 0, z: -0.04}
--- !u!1 &1921590481
GameObject:
m_ObjectHideFlags: 0
@ -17441,8 +17490,8 @@ Transform:
m_GameObject: {fileID: 8749144193474612399}
serializedVersion: 2
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0.0000013709068}
m_LocalPosition: {x: 0.04051976, y: 0.509, z: -0.0033783794}
m_LocalScale: {x: 0.4277714, y: 0.016763842, z: 0.9744956}
m_LocalPosition: {x: 0.04051976, y: 0.523, z: -0.0033783794}
m_LocalScale: {x: 0.4277714, y: 0.042896997, z: 0.9744956}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 270371481}

View file

@ -23,6 +23,7 @@ public class GameManager : MonoBehaviour
public bool shiftStarted;
public GameObject currentNPC;
public GameObject currentStampDoc;
[Header("Walk Points (FOR DEBUGGING")]
public Transform[] frontWalkPoints;

View file

@ -3,6 +3,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.Interactables;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.XR;
public class PaperSpawn : MonoBehaviour
{
@ -10,12 +12,31 @@ public class PaperSpawn : MonoBehaviour
private XRDirectInteractor playerHand;
private bool handInPaperSpawn = false;
private InputDevice targetDevice;
void Start()
{
List<InputDevice> devices = new List<InputDevice>();
InputDevices.GetDevicesAtXRNode(XRNode.RightHand, devices);
if (devices.Count > 0)
{
targetDevice = devices[0];
}
else
{
Debug.LogWarning("No XR Controller detected!");
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("PlayerHand"))
{
handInPaperSpawn = true;
playerHand = other.GetComponent<XRDirectInteractor>();
Debug.Log("Player hand in paper area!");
}
}
@ -25,6 +46,8 @@ public class PaperSpawn : MonoBehaviour
{
handInPaperSpawn = false;
playerHand = null;
Debug.Log("Player hand left paper area!");
}
}
@ -32,8 +55,12 @@ public class PaperSpawn : MonoBehaviour
{
if (handInPaperSpawn && playerHand != null && !playerHand.hasSelection)
{
if (Input.GetButtonDown("Select"))
bool isGrabbing = false;
targetDevice.TryGetFeatureValue(CommonUsages.gripButton, out isGrabbing);
if (isGrabbing)
{
Debug.Log("Player hand grabbing in paper area!");
SpawnPaper();
}
}
@ -44,6 +71,8 @@ public class PaperSpawn : MonoBehaviour
GameObject spawnedPaper = Instantiate(paperPrefab, playerHand.transform.position, Quaternion.identity);
XRGrabInteractable grabComponent = spawnedPaper.GetComponent<XRGrabInteractable>();
Debug.Log("Paper Spawned!");
if (grabComponent != null)
{
playerHand.interactionManager.SelectEnter((IXRSelectInteractor)playerHand, (IXRSelectInteractable)grabComponent);