From 6dadb918d1ade669a9a308579555f95d5a3665a4 Mon Sep 17 00:00:00 2001 From: yauwailam Date: Fri, 7 Feb 2025 14:14:11 +0800 Subject: [PATCH] start ui done --- Game/Assets/Camera effects/Camerashake.cs | 5 + Game/Assets/Followplayercam.cs | 86 ----- Game/Assets/Scenes/Start.unity | 319 +++++++++++++++++- Game/Assets/Scripts/BrushTeeth.cs | 6 +- Game/Assets/Scripts/Followplayercam.cs | 46 +++ .../{ => Scripts}/Followplayercam.cs.meta | 0 Game/Assets/Scripts/Sceneloader.cs | 26 ++ Game/Assets/Scripts/Sceneloader.cs.meta | 11 + .../ProjectSettings/EditorBuildSettings.asset | 6 + 9 files changed, 416 insertions(+), 89 deletions(-) delete mode 100644 Game/Assets/Followplayercam.cs create mode 100644 Game/Assets/Scripts/Followplayercam.cs rename Game/Assets/{ => Scripts}/Followplayercam.cs.meta (100%) create mode 100644 Game/Assets/Scripts/Sceneloader.cs create mode 100644 Game/Assets/Scripts/Sceneloader.cs.meta diff --git a/Game/Assets/Camera effects/Camerashake.cs b/Game/Assets/Camera effects/Camerashake.cs index d936272..aa87d90 100644 --- a/Game/Assets/Camera effects/Camerashake.cs +++ b/Game/Assets/Camera effects/Camerashake.cs @@ -1,3 +1,8 @@ +/* +Author: Wai Lam +Date: 6/2/25 +Description: Make the camera shake +*/ using System.Collections; using System.Collections.Generic; using UnityEngine; diff --git a/Game/Assets/Followplayercam.cs b/Game/Assets/Followplayercam.cs deleted file mode 100644 index fae4c6a..0000000 --- a/Game/Assets/Followplayercam.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Followplayercam : MonoBehaviour -{ - // public Transform playerCamera; - // public float distanceFromPlayer = 2.0f; - // public float heightOffset = 0.0f; - // public float positionSmoothTime = 0.3f; // Controls delay for position - // public float rotationSmoothTime = 0.15f; // Controls delay for rotation - // - // private Vector3 smoothedPosition; - // private Vector3 velocity = Vector3.zero; - // - // void Start() - // { - // if (playerCamera == null) - // { - // Debug.LogError("Player Camera is not assigned!"); - // return; - // } - // - // smoothedPosition = GetTargetPosition(); - // transform.position = smoothedPosition; - // transform.rotation = GetTargetRotation(); - // } - // - // void LateUpdate() - // { - // if (playerCamera != null) - // { - // Vector3 targetPosition = GetTargetPosition(); - // - // // Apply smooth damping for slight delay - // smoothedPosition = Vector3.SmoothDamp( - // smoothedPosition, - // targetPosition, - // ref velocity, - // positionSmoothTime - // ); - // transform.position = smoothedPosition; - // - // // Apply smooth rotation with slight delay - // transform.rotation = Quaternion.Slerp( - // transform.rotation, - // GetTargetRotation(), - // Time.deltaTime / rotationSmoothTime - // ); - // } - // } - // - // private Vector3 GetTargetPosition() - // { - // return playerCamera.position + playerCamera.forward * distanceFromPlayer + Vector3.up * heightOffset; - // } - // - // private Quaternion GetTargetRotation() - // { - // Vector3 lookAtPoint = new Vector3(playerCamera.position.x, transform.position.y, playerCamera.position.z); - // return Quaternion.LookRotation(lookAtPoint - transform.position); - // } - [Header("Target to Follow")] - public Transform target; // Usually the Main Camera (XR Rig's Head) - - [Header("Follow Settings")] - public float followSpeed = 5f; // How quickly it follows the target - public Vector3 offset = new Vector3(0, -0.2f, 1.5f); // Position offset - public bool followRotation = true; // Toggle for rotating with the head - - private void LateUpdate() - { - if (target == null) return; - - // Smooth Position Follow - Vector3 desiredPosition = target.position + target.TransformDirection(offset); - transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * followSpeed); - - // Smooth Rotation Follow - if (followRotation) - { - Quaternion desiredRotation = Quaternion.Euler(0, target.eulerAngles.y, 0); - transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, Time.deltaTime * followSpeed); - } - } -} diff --git a/Game/Assets/Scenes/Start.unity b/Game/Assets/Scenes/Start.unity index b93f3fb..8356d64 100644 --- a/Game/Assets/Scenes/Start.unity +++ b/Game/Assets/Scenes/Start.unity @@ -346,6 +346,139 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1000962761 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1000962762} + - component: {fileID: 1000962765} + - component: {fileID: 1000962764} + - component: {fileID: 1000962763} + m_Layer: 5 + m_Name: Button + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1000962762 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1000962761} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1498853049} + m_Father: {fileID: 1774110362} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 160, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1000962763 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1000962761} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1000962764} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1184216213} + m_TargetAssemblyTypeName: Sceneloader, Assembly-CSharp + m_MethodName: LoadScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &1000962764 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1000962761} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1000962765 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1000962761} + m_CullTransparentMesh: 1 --- !u!1 &1111814439 GameObject: m_ObjectHideFlags: 0 @@ -480,6 +613,185 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1111814439} m_CullTransparentMesh: 1 +--- !u!1 &1184216212 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1184216214} + - component: {fileID: 1184216213} + m_Layer: 0 + m_Name: Sceneloader + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1184216213 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1184216212} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3ba058da590cf7c42be0ee9768d115d2, type: 3} + m_Name: + m_EditorClassIdentifier: + sceneName: House +--- !u!4 &1184216214 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1184216212} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.69926685, y: 1.36144, z: 0.032030016} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1498853048 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1498853049} + - component: {fileID: 1498853051} + - component: {fileID: 1498853050} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1498853049 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1498853048} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1000962762} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1498853050 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1498853048} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: Start + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4281479730 + m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 24 + m_fontSizeBase: 24 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1498853051 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1498853048} + m_CullTransparentMesh: 1 --- !u!1001 &1558242618 PrefabInstance: m_ObjectHideFlags: 0 @@ -633,6 +945,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1111814440} + - {fileID: 1000962762} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} @@ -653,9 +966,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: target: {fileID: 2117891984} - followSpeed: 5 - offset: {x: 0, y: -0.2, z: 1.5} + followSpeed: 3 + offset: {x: 0, y: -0.2, z: 1} followRotation: 1 + maxPitchAngle: 100 --- !u!1 &1841018895 GameObject: m_ObjectHideFlags: 0 @@ -743,3 +1057,4 @@ SceneRoots: - {fileID: 1558242618} - {fileID: 1774110362} - {fileID: 1841018898} + - {fileID: 1184216214} diff --git a/Game/Assets/Scripts/BrushTeeth.cs b/Game/Assets/Scripts/BrushTeeth.cs index 835d999..a022481 100644 --- a/Game/Assets/Scripts/BrushTeeth.cs +++ b/Game/Assets/Scripts/BrushTeeth.cs @@ -1,4 +1,8 @@ -using System.Collections; +/* +Author: Wai Lam +Date: 27/1/25 +Description: Bathroom interaction +*/using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; diff --git a/Game/Assets/Scripts/Followplayercam.cs b/Game/Assets/Scripts/Followplayercam.cs new file mode 100644 index 0000000..517976e --- /dev/null +++ b/Game/Assets/Scripts/Followplayercam.cs @@ -0,0 +1,46 @@ +/* +Author: Wai Lam +Date: 6/2/25 +Description: UI to follow camera with a slight delay +*/ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Followplayercam : MonoBehaviour +{ + + public Transform target; // Usually the Main Camera (XR Rig's Head) + + + public float followSpeed = 5f; // How quickly it follows the target + public Vector3 offset = new Vector3(0, -0.2f, 1.5f); // Position offset + public bool followRotation = true; // Toggle for rotating with the head + + public float maxPitchAngle = 30f; // Limits how much the panel tilts up/down + + private void LateUpdate() + { + if (target == null) return; + + // Smooth Position Follow + Vector3 desiredPosition = target.position + target.TransformDirection(offset); + transform.position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * followSpeed); + + // Smooth Rotation Follow (Yaw + Pitch) + if (followRotation) + { + // Capture target's full rotation + Vector3 targetEulerAngles = target.eulerAngles; + + // Handle Pitch (X-axis) - Clamp to avoid extreme tilting + float pitch = targetEulerAngles.x; + if (pitch > 180) pitch -= 360; // Convert to -180 to 180 range + pitch = Mathf.Clamp(pitch, -maxPitchAngle, maxPitchAngle); + + // Apply Yaw (Y-axis) and Pitch (X-axis), keep Roll (Z-axis) at 0 + Quaternion desiredRotation = Quaternion.Euler(pitch, targetEulerAngles.y, 0); + transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, Time.deltaTime * followSpeed); + } + } +} \ No newline at end of file diff --git a/Game/Assets/Followplayercam.cs.meta b/Game/Assets/Scripts/Followplayercam.cs.meta similarity index 100% rename from Game/Assets/Followplayercam.cs.meta rename to Game/Assets/Scripts/Followplayercam.cs.meta diff --git a/Game/Assets/Scripts/Sceneloader.cs b/Game/Assets/Scripts/Sceneloader.cs new file mode 100644 index 0000000..f25cfc0 --- /dev/null +++ b/Game/Assets/Scripts/Sceneloader.cs @@ -0,0 +1,26 @@ +/* +Author: Wai Lam +Date: 7/2/25 +Description: Loading scene from start to game +*/ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class Sceneloader : MonoBehaviour +{ + public string sceneName; // Name of the scene to load + + public void LoadScene() + { + if (!string.IsNullOrEmpty(sceneName)) + { + SceneManager.LoadScene(sceneName); + } + else + { + Debug.LogWarning("Scene name is not assigned!"); + } + } +} diff --git a/Game/Assets/Scripts/Sceneloader.cs.meta b/Game/Assets/Scripts/Sceneloader.cs.meta new file mode 100644 index 0000000..179cad0 --- /dev/null +++ b/Game/Assets/Scripts/Sceneloader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ba058da590cf7c42be0ee9768d115d2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Game/ProjectSettings/EditorBuildSettings.asset b/Game/ProjectSettings/EditorBuildSettings.asset index 8e85f39..a5f901d 100644 --- a/Game/ProjectSettings/EditorBuildSettings.asset +++ b/Game/ProjectSettings/EditorBuildSettings.asset @@ -17,6 +17,12 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/isaac interaction.unity guid: 0918c8f89e6184c5caed264887eabbb4 + - enabled: 1 + path: Assets/Scenes/Start.unity + guid: 02335c59d249c2b43ab9c3a93b89c4c8 + - enabled: 1 + path: Assets/Scenes/House.unity + guid: a59e0e295e616ae43a48088e6f52328d m_configObjects: Unity.XR.Oculus.Settings: {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2} Unity.XR.WindowsMR.Settings: {fileID: 11400000, guid: dc5a169419fa04987b057f65238cf3ba, type: 2}