game: basic sweeping interaction w/o ui yet

This commit is contained in:
rezazfn 2025-02-07 21:46:20 +08:00
parent 29fe60bb58
commit 6329805a79
18 changed files with 1688 additions and 22 deletions

BIN
Game/Assets/Audio/BrushTeeth.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 9cf02b0277ad0324389ae25a9fefe8ba
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

BIN
Game/Assets/Audio/Sweeping.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 5c8af228a56ef784aaa0161043ce1b3b
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

BIN
Game/Assets/Audio/ThrowTrash.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: c203d3014d6d6d94ea98b5a50d5a9b67
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,100 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &310050590187365199
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalScale.x
value: 18.603428
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalScale.y
value: 18.603428
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalScale.z
value: 18.603428
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalPosition.x
value: 77.432
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalPosition.y
value: 19.946
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalPosition.z
value: 1066.5955
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
propertyPath: m_Name
value: Dirt_Reza
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
insertIndex: -1
addedObject: {fileID: 2060585004650284097}
m_SourcePrefab: {fileID: 100100000, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
--- !u!1 &616127350627212830 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: ca8d53131ef1d684cb03c756e4d62cfc, type: 3}
m_PrefabInstance: {fileID: 310050590187365199}
m_PrefabAsset: {fileID: 0}
--- !u!65 &2060585004650284097
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 616127350627212830}
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_Size: {x: 0.02554513, y: 0.009530636, z: 0.02554859}
m_Center: {x: 0.0001704092, y: 0.004370806, z: -0.000000001862645}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9f7f3b41cd60a0549809ba5efa4a230d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Game/Assets/Prefabs/dust.fbx (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,109 @@
fileFormatVersion: 2
guid: ca8d53131ef1d684cb03c756e4d62cfc
ModelImporter:
serializedVersion: 22200
internalIDToNameTable: []
externalObjects: {}
materials:
materialImportMode: 2
materialName: 0
materialSearch: 1
materialLocation: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
removeConstantScaleCurves: 0
motionNodeName:
rigImportErrors:
rigImportWarnings:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
importAnimatedCustomProperties: 0
importConstraints: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
extraUserProperties: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
importPhysicalCameras: 1
importVisibility: 1
importBlendShapes: 1
importCameras: 1
importLights: 1
nodeNameCollisionStrategy: 1
fileIdsGeneration: 2
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
keepQuads: 0
weldVertices: 1
bakeAxisConversion: 0
preserveHierarchy: 0
skinWeightsMode: 0
maxBonesPerVertex: 4
minBoneWeight: 0.001
optimizeBones: 1
meshOptimizationFlags: -1
indexFormat: 0
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVMarginMethod: 1
secondaryUVMinLightmapResolution: 40
secondaryUVMinObjectScale: 1
secondaryUVPackMargin: 4
useFileScale: 1
strictVertexDataChecks: 0
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 3
normalCalculationMode: 4
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
blendShapeNormalImportMode: 1
normalSmoothingSource: 0
referencedClips: []
importAnimation: 1
humanDescription:
serializedVersion: 3
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
globalScale: 1
rootMotionBoneName:
hasTranslationDoF: 0
hasExtraRoot: 0
skeletonHasParents: 1
lastHumanDescriptionAvatarSource: {instanceID: 0}
autoGenerateAvatarMappingIfUnspecified: 1
animationType: 2
humanoidOversampling: 1
avatarSetup: 0
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
importBlendShapeDeformPercent: 1
remapMaterialsIfMaterialImportModeIsNone: 0
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BroomSweeping : MonoBehaviour
{
// To track how much trash has been collected so far
public int dirtSweeped = 0;
// Defines how much trash is needed to collect in order to unlock the door
public int dirtRequired = 10;
// Defines Audio References
public AudioSource audioSource;
public AudioClip sweepingSound;
private void OnTriggerEnter(Collider other)
{
if (!other.CompareTag("Dirt")) return;
dirtSweeped++;
Destroy(other.gameObject);
// Play sound only if no other sound is currently playing
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(sweepingSound);
}
}
}

View file

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

View file

@ -1,18 +1,89 @@
/*
Author: Reza
Date: 7/2/25
Description: Living room task of sweeping the dirt on the floor
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Sweeping : MonoBehaviour
{
// Start is called before the first frame update
public Transform broomParent; // Assign the parent object of the broom
public float sweepSpeed = 2f; // Speed of automatic sweeping
public float sweepRange = 0.5f; // How far the broom sweeps left and right
public float cleaningTime = 3f; // Time required to clean dirt
public Slider progressBarPrefab; // Prefab for progress bar UI
private Vector3 startPosition;
private bool isCleaning = false;
private GameObject currentDirt;
private float cleaningProgress = 0f;
private Slider progressBar;
void Start()
{
if (broomParent == null)
{
Debug.LogError("Broom parent not assigned in AutoBroom script!");
return;
}
startPosition = broomParent.position; // Store initial position of the broom
}
// Update is called once per frame
void Update()
private void OnTriggerEnter(Collider other)
{
if (!other.CompareTag("Dirt") || isCleaning) return;
// Start auto-sweeping and cleaning
isCleaning = true;
currentDirt = other.gameObject;
StartCoroutine(SweepAndClean());
}
}
IEnumerator SweepAndClean()
{
float direction = 1f; // Start moving right
// Create and attach progress bar **only when sweeping starts**
progressBar = Instantiate(progressBarPrefab, currentDirt.transform.position + Vector3.up * 1f, Quaternion.identity, currentDirt.transform);
progressBar.gameObject.SetActive(true);
progressBar.value = 0f;
while (cleaningProgress < cleaningTime)
{
// Move broom's entire parent left and right
float moveAmount = direction * sweepSpeed * Time.deltaTime;
broomParent.position += new Vector3(moveAmount, 0, 0);
// Reverse direction when reaching sweep range
if (Mathf.Abs(broomParent.position.x - startPosition.x) > sweepRange)
{
direction *= -1f; // Reverse sweep direction
}
// Increase cleaning progress
cleaningProgress += Time.deltaTime;
progressBar.value = cleaningProgress / cleaningTime;
yield return null;
}
CompleteCleaning();
}
void CompleteCleaning()
{
if (progressBar != null)
{
Destroy(progressBar.gameObject); // Remove progress bar
}
Destroy(currentDirt); // Remove dirt
isCleaning = false; // Allow new cleaning to start
broomParent.position = startPosition; // Reset broom position
cleaningProgress = 0f; // Reset progress
}
}

View file

@ -9,7 +9,7 @@
{
"type": "UnityEngine.ProBuilder.SelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "editor.lastMeshSelectMode",
"value": "{\"m_Value\":8}"
"value": "{\"m_Value\":2}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
@ -149,7 +149,7 @@
{
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "ShapeBuilder.ActiveShapeIndex",
"value": "{\"m_Value\":6}"
"value": "{\"m_Value\":7}"
},
{
"type": "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
@ -169,7 +169,7 @@
{
"type": "UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "ShapeBuilder.LastSize",
"value": "{\"m_Value\":{\"x\":0.197540283203125,\"y\":0.015741348266601564,\"z\":0.1954345703125}}"
"value": "{\"m_Value\":{\"x\":0.248779296875,\"y\":-0.09796714782714844,\"z\":0.2877197265625}}"
},
{
"type": "UnityEngine.Quaternion, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",

View file

@ -10,6 +10,7 @@ TagManager:
- Info
- InfoObject
- Bottle
- Dirt
layers:
- Default
- TransparentFX