Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-03 11:02:29 +02:00
commit 27d6b94b7c
8167 changed files with 1116569 additions and 0 deletions

View File

@ -0,0 +1,87 @@
using UnityEngine;
using UnityEngine.InputSystem;
/// <summary>
/// Controls hand animations based on user input, managing trigger and grip actions through Unity's Input System.
/// </summary>
public class HandAnimationController : MonoBehaviour
{
// Input action for the trigger button
[SerializeField] private InputActionProperty _triggerAction;
// Input action for the grip button
[SerializeField] private InputActionProperty _gripAction;
// Controls animations for the hand
private Animator _animator;
// Identifier for the trigger animation parameter
private int _triggerAnimationParameterID;
// Identifier for the grip animation parameter
private int _gripAnimationParameterID;
/// <summary>
/// Initializes necessary components and variables.
/// </summary>
private void Awake()
{
_animator = GetComponent<Animator>();
_triggerAnimationParameterID = Animator.StringToHash("Trigger");
_gripAnimationParameterID = Animator.StringToHash("Grip");
}
/// <summary>
/// Subscribes to input events when the script is enabled.
/// </summary>
private void OnEnable()
{
_triggerAction.action.performed += XRController_SelectAction_Performed;
_gripAction.action.performed += XRController_ActivateAction_Performed;
_triggerAction.action.canceled += XRController_SelectAction_Canceled;
_gripAction.action.canceled += XRController_ActivateAction_Canceled;
}
/// <summary>
/// Unsubscribes from input events to prevent issues when the script is disabled.
/// </summary>
private void OnDisable()
{
_triggerAction.action.performed -= XRController_SelectAction_Performed;
_gripAction.action.performed -= XRController_ActivateAction_Performed;
_triggerAction.action.canceled -= XRController_SelectAction_Canceled;
_gripAction.action.canceled -= XRController_ActivateAction_Canceled;
}
/// <summary>
/// Handles trigger input to control the corresponding animation.
/// </summary>
private void XRController_SelectAction_Performed(InputAction.CallbackContext obj)
{
float triggerInputValue = obj.ReadValue<float>();
_animator.SetFloat(_triggerAnimationParameterID, triggerInputValue);
}
/// <summary>
/// Handles grip input to control the corresponding animation.
/// </summary>
private void XRController_ActivateAction_Performed(InputAction.CallbackContext obj)
{
float gripInputValue = obj.ReadValue<float>();
_animator.SetFloat(_gripAnimationParameterID, gripInputValue);
}
/// <summary>
/// Resets trigger animation when the trigger action is canceled.
/// </summary>
private void XRController_SelectAction_Canceled(InputAction.CallbackContext obj)
{
float triggerInputValue = 0;
_animator.SetFloat(_triggerAnimationParameterID, triggerInputValue);
}
/// <summary>
/// Resets grip animation when the grip action is canceled.
/// </summary>
private void XRController_ActivateAction_Canceled(InputAction.CallbackContext obj)
{
float gripInputValue = 0;
_animator.SetFloat(_gripAnimationParameterID, gripInputValue);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 015c6d985a534be46b0a96e0247c9dbb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,66 @@
using Unity.XR.CoreUtils;
using UnityEngine;
/// <summary>
/// Make the object look at the XR Origin's camera
/// </summary>
public class LookAtPlayer : MonoBehaviour
{
[Tooltip("Follow x axis")]
[SerializeField] private bool _lookX = false;
[Tooltip("Follow y axis")]
[SerializeField] private bool _lookY = false;
[Tooltip("Follow z axis")]
[SerializeField] private bool _lookZ = false;
// Reference to the main camera
private GameObject cameraObject = null;
// Original rotation of the object
private Vector3 originalRotation = Vector3.zero;
/// <summary>
/// Initializes necessary components and variables.
/// </summary>
private void Awake()
{
// Find the main camera
if (Camera.main != null)
cameraObject = Camera.main.gameObject;
else
{
Debug.LogError("Main camera not found. Make sure the camera is tagged as 'MainCamera'");
}
originalRotation = transform.eulerAngles;
}
/// <summary>
/// LateUpdate is called once per frame after all Update functions have been called.
/// </summary>
private void LateUpdate()
{
// Adjust the object's rotation to face the camera
LookAt();
}
/// <summary>
/// Adjusts the object's rotation to face the camera based on specified axes.
/// </summary>
private void LookAt()
{
// Calculate the direction from the object to the camera
Vector3 direction = transform.position - cameraObject.transform.position;
// Calculate the new rotation angles using LookRotation
Vector3 newRotation = Quaternion.LookRotation(direction, transform.up).eulerAngles;
// Apply rotation based on specified axes
newRotation.x = _lookX ? newRotation.x : originalRotation.x;
newRotation.y = _lookY ? newRotation.y : originalRotation.y;
newRotation.z = _lookZ ? newRotation.z : originalRotation.z;
// Set the object's rotation using the new angles
transform.rotation = Quaternion.Euler(newRotation);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03758c906c801d14ab26fe203e793fe8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,54 @@
using Convai.Scripts;
using Convai.Scripts.Utils;
using UnityEngine;
/// <summary>
/// Positions the VR transcript UI relative to the active ConvaiNPC based on appearance changes.
/// </summary>
public class VRTranscriptUIPositionSetter : MonoBehaviour
{
// Offset for positioning the UI relative to the ConvaiNPC
[SerializeField] private Vector3 _offset;
/// <summary>
/// Subscribes to events when the script is enabled.
/// </summary>
private void OnEnable()
{
ConvaiNPCManager.Instance.OnActiveNPCChanged += ConvaiNPCManager_OnActiveNPCChanged;
}
/// <summary>
/// Unsubscribes from events to prevent issues when the script is disabled.
/// </summary>
private void OnDisable()
{
ConvaiNPCManager.Instance.OnActiveNPCChanged -= ConvaiNPCManager_OnActiveNPCChanged;
}
/// <summary>
/// Updates the position of the current UI when the active ConvaiNPC changes.
/// </summary>
/// <param name="convaiNpc">The newly active ConvaiNPC.</param>
private void ConvaiNPCManager_OnActiveNPCChanged(ConvaiNPC convaiNPC)
{
if (convaiNPC == null)
{
return;
}
UpdateCurrentUIPosition(convaiNPC);
}
/// <summary>
/// Updates the position of the current UI based on the location and offset of the active ConvaiNPC.
/// </summary>
/// <param name="convaiNPC">The active ConvaiNPC.</param>
private void UpdateCurrentUIPosition(ConvaiNPC convaiNPC)
{
Transform npcTransform = convaiNPC.transform;
Vector3 targetOffset = _offset.x * npcTransform.right + _offset.y * npcTransform.up + _offset.z * npcTransform.forward;
Debug.Log("NEW POSITION: "+ targetOffset);
transform.position = npcTransform.position + targetOffset;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 068e80eca13510841ba379fbcd57ff2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: