From fc0bcf020115d856941be168b2323ae78a7fce9c Mon Sep 17 00:00:00 2001 From: Trey Shaw Date: Mon, 29 Jun 2026 22:15:59 -0500 Subject: [PATCH] add unlock system for tools --- Assets/Doug.prefab | 98 +++++++++- Assets/Scenes/World_Greaybox.unity | 180 +++++++++++++++++- Assets/Scripts/Management/GameManager.cs | 1 - Assets/Scripts/Management/PlayerController.cs | 108 +++++++++-- Assets/Scripts/Management/PlayerManager.cs | 43 +++++ Assets/Scripts/Tools/NoTool.cs | 14 ++ Assets/Scripts/Tools/NoTool.cs.meta | 2 + Assets/Scripts/Tools/ThrowableHand.cs | 60 ++++-- Assets/Scripts/Tools/Tool.cs | 12 +- .../Scripts/Utils/SerializableDictionary.cs | 31 +++ .../Utils/SerializableDictionary.cs.meta | 2 + ProjectSettings/PackageManagerSettings.asset | 27 ++- 12 files changed, 513 insertions(+), 65 deletions(-) create mode 100644 Assets/Scripts/Tools/NoTool.cs create mode 100644 Assets/Scripts/Tools/NoTool.cs.meta create mode 100644 Assets/Scripts/Utils/SerializableDictionary.cs create mode 100644 Assets/Scripts/Utils/SerializableDictionary.cs.meta diff --git a/Assets/Doug.prefab b/Assets/Doug.prefab index fb35a0a..63397d3 100644 --- a/Assets/Doug.prefab +++ b/Assets/Doug.prefab @@ -477,6 +477,7 @@ Transform: m_LocalScale: {x: 6.6666665, y: 2.2222223, z: 6.6666665} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 6727541304562925855} - {fileID: 6959836037467520223} - {fileID: 7557613548437949332} - {fileID: 4497923176373106572} @@ -501,7 +502,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &6959836037467520223 Transform: m_ObjectHideFlags: 0 @@ -531,6 +532,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 21ea1f4973209f34aa1bfb2f1dda5454, type: 3} m_Name: m_EditorClassIdentifier: + ToolType: 1 useTimeSec: 0 altUseTimeSec: 0 inUse: 0 @@ -1454,6 +1456,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fe5aedf75d904534296ad0d07fe55622, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::Throwable + ToolType: 5 useTimeSec: 0 altUseTimeSec: 0 inUse: 0 @@ -1825,6 +1828,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: edd0364a446d1fd489dd8bbb53de613a, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::Flashlight + ToolType: 2 useTimeSec: 0 altUseTimeSec: 0 inUse: 0 @@ -1875,6 +1879,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8adaf1de0b489444189e21893ccde9b5, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::Ballgun + ToolType: 4 useTimeSec: 0 altUseTimeSec: 0 inUse: 0 @@ -2426,6 +2431,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 70102eddcaad3044d9ac0ec62519caad, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::GrappleGun + ToolType: 3 useTimeSec: 0.2 altUseTimeSec: 0 inUse: 0 @@ -2572,7 +2578,7 @@ Transform: serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: -0.78, z: 0} - m_LocalScale: {x: 1, y: 3, z: 1} + m_LocalScale: {x: 1, y: 2.41278, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 6581087177990818461} @@ -3083,6 +3089,82 @@ BoxCollider: serializedVersion: 3 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} +--- !u!1 &9052018062808764455 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6727541304562925855} + - component: {fileID: 2779253558307207697} + - component: {fileID: 8034242111769562475} + m_Layer: 0 + m_Name: NoTool + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6727541304562925855 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9052018062808764455} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0.016199952, z: 0.01755007} + m_LocalScale: {x: 0.15, y: 0.14999999, z: 0.15} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6581087177990818461} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2779253558307207697 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9052018062808764455} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 15984e9d9e7f6074f97a69185e39ebb6, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::NoTool + ToolType: 0 + useTimeSec: 0 + altUseTimeSec: 0 + inUse: 0 +--- !u!54 &8034242111769562475 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9052018062808764455} + serializedVersion: 5 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_CenterOfMass: {x: 0, y: 0, z: 0} + m_InertiaTensor: {x: 1, y: 1, z: 1} + m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ImplicitCom: 1 + m_ImplicitTensor: 1 + m_UseGravity: 0 + m_IsKinematic: 1 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 --- !u!1 &9054701043111961555 GameObject: m_ObjectHideFlags: 0 @@ -3134,6 +3216,7 @@ MonoBehaviour: m_EditorClassIdentifier: DougBody: {fileID: 6233083279635182816} tools: + - {fileID: 2779253558307207697} - {fileID: 948123141231275876} - {fileID: 2884873557578242522} - {fileID: 6033266832729015012} @@ -3141,7 +3224,8 @@ MonoBehaviour: - {fileID: 6038027350876930962} walkSpeed: 2 sprintMultiplier: 1.5 - gravity: 1 + gravity: 5 + rotationSpeed: 40 cameraController: {fileID: 5478143440182735446} --- !u!114 &5478143440182735446 MonoBehaviour: @@ -3165,7 +3249,7 @@ MonoBehaviour: minDistance: 1 zoomSpeed: 5 heightOffset: -0.75 - collisionRadius: 0.3 + collisionRadius: 0.01 collisionOffset: 0.2 collisionMask: serializedVersion: 2 @@ -3206,13 +3290,13 @@ CharacterController: m_ProvidesContacts: 0 m_Enabled: 1 serializedVersion: 3 - m_Height: 3 + m_Height: 2.67 m_Radius: 0.92 m_SlopeLimit: 45 m_StepOffset: 0.3 - m_SkinWidth: 0.03 + m_SkinWidth: 0.01 m_MinMoveDistance: 0 - m_Center: {x: 0, y: -0.51, z: 0} + m_Center: {x: 0, y: -0.66, z: 0} --- !u!1 &9105254285813222465 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/World_Greaybox.unity b/Assets/Scenes/World_Greaybox.unity index 31c0a04..2ad7060 100644 --- a/Assets/Scenes/World_Greaybox.unity +++ b/Assets/Scenes/World_Greaybox.unity @@ -154,6 +154,30 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: -9056850266462142758, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -9047727887134345856, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -8907803785428861059, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -8801484775891363735, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -8794726789177251869, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -8681359355455502985, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: -8679921383154817045, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: m_LocalPosition.x value: 0 @@ -194,10 +218,22 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: -8075798944234085933, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -7849233877077813918, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: -7511838633821194502, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[1]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -7269420003911142314, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: -7152024165247120797, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[2]' value: @@ -206,6 +242,10 @@ PrefabInstance: propertyPath: 'm_Materials.Array.data[0]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -5936135199837667612, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: -5532019473813935150, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[1]' value: @@ -214,10 +254,54 @@ PrefabInstance: propertyPath: 'm_Materials.Array.data[1]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -4709409678255011905, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -4659676416678757244, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: -4594601065878512338, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[1]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -4056037076971932226, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -3922443812785298713, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -3639519509707613619, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -1429694127308077889, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -623097957256150569, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -338878865451222768, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: -95896753121866928, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 213103072202071130, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 250826824195658063, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 832315335761619832, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[0]' value: @@ -226,22 +310,70 @@ PrefabInstance: propertyPath: m_Name value: Island_cm_Test objectReference: {fileID: 0} + - target: {fileID: 1030454973722673324, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 1369179596134303224, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 1708991950593452922, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 1936764083821156874, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 2098882618965689144, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 2160165921282053551, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 2444832132617110111, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[3]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 2696388872093842765, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 3070263602160024847, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 3145335169245159225, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 3802984263324534080, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[0]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 3810047666473699632, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 3989179055083284509, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 4029340038601660530, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[2]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 4305739264245721443, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[0]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 5008553074459749374, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} - target: {fileID: 5380494774032967284, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: 'm_Materials.Array.data[0]' value: @@ -250,10 +382,46 @@ PrefabInstance: propertyPath: 'm_Materials.Array.data[1]' value: objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 6750501090022582518, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 7843400803091073728, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 8026868501028919746, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: 78be8f8bd251f244ab82d30f189c8824, type: 2} - target: {fileID: 8040117523804346068, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} propertyPath: m_Layer value: 3 objectReference: {fileID: 0} + - target: {fileID: 8112831532858891024, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 8281812956987458185, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[3]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 8836829699787575794, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 8855642189804323981, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 8914130868685757657, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[1]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} + - target: {fileID: 9004041995877974992, guid: 5d4389ebffbf7bd458488fd3ea3fc492, type: 3} + propertyPath: 'm_Materials.Array.data[2]' + value: + objectReference: {fileID: 2100000, guid: b74fa76d3c3551d478f93b2a251df8f8, type: 2} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -1905,14 +2073,18 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1480974628599415149, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} + propertyPath: gravity + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 1480974628599415149, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} + propertyPath: rotationSpeed + value: 40 + objectReference: {fileID: 0} - target: {fileID: 5056434560497563343, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} propertyPath: m_LocalScale.y value: 2.41278 objectReference: {fileID: 0} - - target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} - propertyPath: heightOffset - value: -0.75 - objectReference: {fileID: 0} - target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3} propertyPath: collisionRadius value: 0.01 diff --git a/Assets/Scripts/Management/GameManager.cs b/Assets/Scripts/Management/GameManager.cs index c3eacf4..8e87dad 100644 --- a/Assets/Scripts/Management/GameManager.cs +++ b/Assets/Scripts/Management/GameManager.cs @@ -22,7 +22,6 @@ public class GameManager : MonoBehaviour // Are we currently in a scene transition? private bool isTransitioningScenes = false; - private void Awake() { // If there is an instance, and it's not me, delete myself. diff --git a/Assets/Scripts/Management/PlayerController.cs b/Assets/Scripts/Management/PlayerController.cs index 250a0ca..f9d051f 100644 --- a/Assets/Scripts/Management/PlayerController.cs +++ b/Assets/Scripts/Management/PlayerController.cs @@ -13,6 +13,7 @@ public class PlayerController : MonoBehaviour public float walkSpeed; public float sprintMultiplier = 1.5f; public float gravity = 10; + public float rotationSpeed = 15; Interactable nearestInteractable; public CameraController cameraController; @@ -23,14 +24,9 @@ public class PlayerController : MonoBehaviour private bool isSprinting = false; private bool paused = false; - // Mathematical plane used to catch the raycast from camera to get direction for - // looking at the mouse - private Plane groundPlane; - // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { - groundPlane = new Plane(Vector3.up, -DougBody.transform.position.y); characterController = GetComponent(); cameraController = GetComponent(); SwitchTools(GameManager.Instance.PlayerManager.CurrentToolIndex); @@ -40,7 +36,6 @@ void Start() void Update() { moveDir = Vector3.zero; - groundPlane.distance = -DougBody.transform.position.y; // TODO: Move input detection somewhere else if (Input.GetKeyDown(KeyCode.Escape)) @@ -223,14 +218,67 @@ void ToolUseDetector() /// void RotatePlayerTowardMouse() { - Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + /*Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + Plane plane = new Plane(cameraController.MainCamera.transform.forward,DougBody.transform.position); - if (groundPlane.Raycast(ray, out var distance)) + if (plane.Raycast(ray, out var distance)) { Vector3 hitPoint = ray.GetPoint(distance); + Vector3 direction = hitPoint - DougBody.transform.position; + direction.y = 0f; - DougBody.transform.LookAt(new Vector3(hitPoint.x, DougBody.transform.position.y, hitPoint.z)); + ///DougBody.transform.LookAt(new Vector3(hitPoint.x, DougBody.transform.position.y, hitPoint.z)); + if (direction.sqrMagnitude > 0.001f) + { + Quaternion targetRotation = + Quaternion.LookRotation(direction); + + DougBody.transform.rotation = Quaternion.Slerp( + DougBody.transform.rotation, + targetRotation, + rotationSpeed * Time.deltaTime + ); + } + }*/ + + Camera cam = cameraController.MainCamera; + + Ray ray = cam.ScreenPointToRay(Input.mousePosition); + + Vector3 targetPoint; + + // 1. Try real world hit first (most stable) + if (Physics.Raycast(ray, out RaycastHit hit, 1000f)) + { + targetPoint = hit.point; } + else + { + // 2. Fallback to plane at player height + Plane plane = new Plane(Vector3.up, DougBody.transform.position); + + if (!plane.Raycast(ray, out float enter)) + return; + + targetPoint = ray.GetPoint(enter); + } + + // 3. Flatten direction so we only rotate on Y axis + Vector3 direction = targetPoint - DougBody.transform.position; + direction.y = 0f; + + if (direction.sqrMagnitude < 0.001f) + return; + + // 4. Convert to rotation + Quaternion targetRotation = Quaternion.LookRotation(direction.normalized); + + // 5. Smooth rotation + DougBody.transform.rotation = Quaternion.Slerp( + DougBody.transform.rotation, + targetRotation, + rotationSpeed * Time.deltaTime + ); } /// @@ -305,8 +353,12 @@ public Vector3 GetVelocity() /// Switches the tools in hand by taking an index /// /// Index of the tool to switch to + /// + /// If true, try the next tool if the tool at toolIndex is not unlocked yet. If false, + /// try the previous tool if the tool at toolIndex is not unlocked. + /// /// - private void SwitchTools(int toolIndex) + private void SwitchTools(int toolIndex, bool defaultToUp=true) { if (toolIndex < 0 || toolIndex >= tools.Length) { @@ -319,9 +371,20 @@ private void SwitchTools(int toolIndex) tool.gameObject.SetActive(false); } - // load new tool - GameManager.Instance.PlayerManager.CurrentToolIndex = toolIndex; - tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true); + if (GameManager.Instance.PlayerManager.IsToolUnlocked(tools[toolIndex].ToolType)) + { + // load new tool + GameManager.Instance.PlayerManager.CurrentToolIndex = toolIndex; + tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true); + } + else + { + // try next index + if (defaultToUp) + SwitchTools(toolIndex + 1, defaultToUp); + else + SwitchTools(toolIndex - 1, defaultToUp); + } } /// @@ -332,11 +395,11 @@ private void SwitchTools(int toolIndex) private void SwitchTools(bool up) { // calculate index of next tool - int newIndex = up ? GameManager.Instance.PlayerManager.CurrentToolIndex - 1 : GameManager.Instance.PlayerManager.CurrentToolIndex + 1; + int newIndex = up ? GameManager.Instance.PlayerManager.CurrentToolIndex + 1 : GameManager.Instance.PlayerManager.CurrentToolIndex - 1; if (newIndex < 0) { - newIndex = tools.Length + newIndex; + newIndex = tools.Length - 1; } else if (newIndex >= tools.Length) { @@ -346,9 +409,18 @@ private void SwitchTools(bool up) // disable current tool tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(false); - // load new tool - GameManager.Instance.PlayerManager.CurrentToolIndex = newIndex; - tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true); + if (GameManager.Instance.PlayerManager.IsToolUnlocked(tools[newIndex].ToolType)) + { + // load new tool + GameManager.Instance.PlayerManager.CurrentToolIndex = newIndex; + tools[GameManager.Instance.PlayerManager.CurrentToolIndex].gameObject.SetActive(true); + } + else + { + // try next tool + if (up) SwitchTools(newIndex + 1); + else SwitchTools(newIndex - 1, false); + } } } diff --git a/Assets/Scripts/Management/PlayerManager.cs b/Assets/Scripts/Management/PlayerManager.cs index 62af1f6..d8cdf96 100644 --- a/Assets/Scripts/Management/PlayerManager.cs +++ b/Assets/Scripts/Management/PlayerManager.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; @@ -5,6 +7,27 @@ public class PlayerManager : MonoBehaviour { public int CurrentToolIndex; + private SerializableDictionary unlockedToolDict = null; + + public bool IsToolUnlocked(ToolEnum tool) + { + if (unlockedToolDict.TryGetValue(tool, out bool unlocked)) return unlocked; + + // If no tool dict saved, init the default one (only None is unlocked) + unlockedToolDict = new SerializableDictionary(); + + foreach (ToolEnum toolType in Enum.GetValues(typeof(ToolEnum))) + { + if (toolType == ToolEnum.None) + unlockedToolDict.Add(toolType, true); + else + unlockedToolDict.Add(toolType, false); + } + + // Try again + if (unlockedToolDict.TryGetValue(tool, out bool unlockedRetry)) return unlockedRetry; + return false; + } #region Player Data Save/Load public void SavePlayerData(ref PlayerSaveData data) @@ -12,6 +35,7 @@ public void SavePlayerData(ref PlayerSaveData data) data.activeToolIndex = GameManager.Instance.PlayerManager.CurrentToolIndex; data.dougPosition = GameManager.Instance.PlayerController.transform.position; data.currentScene = SceneManager.GetActiveScene().name; + data.unlockedToolDict = unlockedToolDict; } public void LoadPlayerData(PlayerSaveData data) @@ -25,6 +49,24 @@ public void LoadPlayerData(PlayerSaveData data) GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex; GameManager.Instance.PlayerController.transform.position = data.dougPosition; } + + if (data.unlockedToolDict != null) + { + unlockedToolDict = data.unlockedToolDict; + } + else + { + // If no tool dict saved, init the default one (only None is unlocked) + unlockedToolDict = new SerializableDictionary(); + + foreach (ToolEnum toolType in Enum.GetValues(typeof(ToolEnum))) + { + if (toolType == ToolEnum.None) + unlockedToolDict.Add(toolType, true); + else + unlockedToolDict.Add(toolType, false); + } + } } #endregion } @@ -35,4 +77,5 @@ public struct PlayerSaveData public int activeToolIndex; public Vector3 dougPosition; public string currentScene; + public SerializableDictionary unlockedToolDict; } diff --git a/Assets/Scripts/Tools/NoTool.cs b/Assets/Scripts/Tools/NoTool.cs new file mode 100644 index 0000000..7c1fc0c --- /dev/null +++ b/Assets/Scripts/Tools/NoTool.cs @@ -0,0 +1,14 @@ +using UnityEngine; + +public class NoTool : Tool +{ + public override void Use() + { + // Do nothin' + } + + public override void UseAlt() + { + // Do nothin' + } +} diff --git a/Assets/Scripts/Tools/NoTool.cs.meta b/Assets/Scripts/Tools/NoTool.cs.meta new file mode 100644 index 0000000..c62e5f1 --- /dev/null +++ b/Assets/Scripts/Tools/NoTool.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 15984e9d9e7f6074f97a69185e39ebb6 \ No newline at end of file diff --git a/Assets/Scripts/Tools/ThrowableHand.cs b/Assets/Scripts/Tools/ThrowableHand.cs index dc94945..77436c2 100644 --- a/Assets/Scripts/Tools/ThrowableHand.cs +++ b/Assets/Scripts/Tools/ThrowableHand.cs @@ -20,7 +20,6 @@ private void Update() { if (GameManager.Instance.PlayerController != null) { - SetGroundPlane(); DrawTargetProjection(); } } @@ -43,28 +42,51 @@ private void DrawTargetProjection() targetProjection = GetComponentInChildren(); } + Transform player = GameManager.Instance.PlayerController.DougBody.transform; + Transform camera = GameManager.Instance.PlayerController.cameraController.MainCamera.transform; + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); - if (handGroundPlane.Raycast(ray, out var distance)) + Vector3 targetPoint; + + // First try real world geometry + if (Physics.Raycast(ray, out RaycastHit hit, 1000f)) { - Vector3 hitPoint = ray.GetPoint(distance); - - float distanceFromPoint = Vector3.Distance(hitPoint, transform.position); - if (distanceFromPoint > range) - { - Vector3 directionTowardMouse = (hitPoint - transform.position).normalized; - targetProjection.transform.position = new Vector3(transform.position.x, hitPoint.y, transform.position.z); - targetProjection.transform.position += directionTowardMouse * range; - - throwForce = range; - } - else - { - targetProjection.gameObject.SetActive(true); - targetProjection.transform.position = hitPoint; - throwForce = distanceFromPoint; - } + targetPoint = hit.point; } + else + { + // Fallback plane if nothing hit + Plane plane = new Plane(Vector3.up, player.position); + + if (!plane.Raycast(ray, out float distance)) + return; + + targetPoint = ray.GetPoint(distance); + } + + // Flatten relative to player + Vector3 offset = targetPoint - player.position; + offset.y = 0f; + + // Clamp range + offset = Vector3.ClampMagnitude(offset, range); + throwForce = offset.magnitude; + + // Final position + Vector3 finalPosition = player.position + offset; + + // Snap back to ground + if (Physics.Raycast( + finalPosition + Vector3.up * 10f, + Vector3.down, + out RaycastHit groundHit, + 50f)) + { + finalPosition = groundHit.point; + } + + targetProjection.transform.position = finalPosition; } public override void Use() diff --git a/Assets/Scripts/Tools/Tool.cs b/Assets/Scripts/Tools/Tool.cs index bf63158..5886f0c 100644 --- a/Assets/Scripts/Tools/Tool.cs +++ b/Assets/Scripts/Tools/Tool.cs @@ -2,8 +2,8 @@ public abstract class Tool : MonoBehaviour { - [Header("Base Tool Parameters")] + public ToolEnum ToolType = ToolEnum.None; public float useTimeSec; public float altUseTimeSec; public bool inUse; @@ -14,3 +14,13 @@ public abstract class Tool : MonoBehaviour // secondary (right click) public abstract void UseAlt(); } + +public enum ToolEnum +{ + None, + Shovel, + Flashlight, + GrappleGun, + Ballgun, + ThrowableHand +} diff --git a/Assets/Scripts/Utils/SerializableDictionary.cs b/Assets/Scripts/Utils/SerializableDictionary.cs new file mode 100644 index 0000000..49ffe55 --- /dev/null +++ b/Assets/Scripts/Utils/SerializableDictionary.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using UnityEngine; + +[System.Serializable] +public class SerializableDictionary : Dictionary, ISerializationCallbackReceiver +{ + // THIS DOES NOT WORK IF KEY OR VALUE ARE NON-SERIALIZABLE TYPES + [SerializeField] private List keys = new List(); + [SerializeField] private List values = new List(); + + public void OnBeforeSerialize() + { + keys.Clear(); + values.Clear(); + foreach (var pair in this) + { + keys.Add(pair.Key); + values.Add(pair.Value); + } + } + + public void OnAfterDeserialize() + { + Clear(); + int count = Mathf.Min(keys.Count, values.Count); + for (int i = 0; i < count; i++) + { + Add(keys[i], values[i]); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/SerializableDictionary.cs.meta b/Assets/Scripts/Utils/SerializableDictionary.cs.meta new file mode 100644 index 0000000..50df751 --- /dev/null +++ b/Assets/Scripts/Utils/SerializableDictionary.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 45405bd3a7fecb94fa903865f4764cda \ No newline at end of file diff --git a/ProjectSettings/PackageManagerSettings.asset b/ProjectSettings/PackageManagerSettings.asset index be4a797..d940b84 100644 --- a/ProjectSettings/PackageManagerSettings.asset +++ b/ProjectSettings/PackageManagerSettings.asset @@ -12,11 +12,13 @@ MonoBehaviour: m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} m_Name: m_EditorClassIdentifier: - m_EnablePreviewPackages: 0 - m_EnablePackageDependencies: 0 + m_EnablePreReleasePackages: 0 m_AdvancedSettingsExpanded: 1 m_ScopedRegistriesSettingsExpanded: 1 + m_SeeAllPackageVersions: 0 + m_DismissPreviewPackagesInUse: 0 oneTimeWarningShown: 0 + oneTimePackageErrorsPopUpShown: 1 m_Registries: - m_Id: main m_Name: @@ -24,20 +26,15 @@ MonoBehaviour: m_Scopes: [] m_IsDefault: 1 m_Capabilities: 7 + m_ConfigSource: 0 + m_Compliance: + m_Status: 0 + m_Violations: [] m_UserSelectedRegistryName: m_UserAddingNewScopedRegistry: 0 m_RegistryInfoDraft: - m_ErrorMessage: - m_Original: - m_Id: - m_Name: - m_Url: - m_Scopes: [] - m_IsDefault: 0 - m_Capabilities: 0 m_Modified: 0 - m_Name: - m_Url: - m_Scopes: - - - m_SelectedScopeIndex: 0 + m_ErrorMessage: + m_UserModificationsInstanceId: -894 + m_OriginalInstanceId: -896 + m_LoadAssets: 0