game: placing npcs in livi playground

This commit is contained in:
ryan 2025-02-07 15:44:43 +08:00
parent 8c637ce8f1
commit e0858a94de
7 changed files with 230 additions and 176 deletions

View file

@ -52,10 +52,18 @@ PrefabInstance:
propertyPath: m_Name
value: Male1
objectReference: {fileID: 0}
- target: {fileID: -4738449573843015574, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
propertyPath: m_TagString
value: NPC
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
propertyPath: m_Name
value: male1WithHair
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
propertyPath: m_TagString
value: NPC
objectReference: {fileID: 0}
- target: {fileID: 5866666021909216657, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
propertyPath: m_Controller
value:
@ -70,6 +78,12 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
insertIndex: -1
addedObject: {fileID: 2866292048537355755}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
insertIndex: -1
addedObject: {fileID: 7526272965874387434}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
insertIndex: -1
addedObject: {fileID: 4155463426386729222}
m_SourcePrefab: {fileID: 100100000, guid: 208f8e7ee2310474aa57f8901d61d5f6, type: 3}
--- !u!1 &8486445782931515160 stripped
GameObject:
@ -113,3 +127,53 @@ MonoBehaviour:
agent: {fileID: 0}
desk: {fileID: 0}
animator: {fileID: 0}
--- !u!136 &7526272965874387434
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8486445782931515160}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.41697595
m_Height: 1.6271778
m_Direction: 1
m_Center: {x: 0, y: 0.78, z: 0}
--- !u!54 &4155463426386729222
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8486445782931515160}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 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: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0

View file

@ -205,67 +205,111 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1039245}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1396610
PrefabInstance:
--- !u!1 &9804464
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9804468}
- component: {fileID: 9804467}
- component: {fileID: 9804466}
- component: {fileID: 9804465}
m_Layer: 0
m_Name: seat
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &9804465
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9804464}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 0
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &9804466
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9804464}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &9804467
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9804464}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &9804468
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9804464}
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2866292048537355755, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: desk
value:
objectReference: {fileID: 418120326}
- target: {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_Name
value: male1WithHair
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.x
value: 0.13746405
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.y
value: -0.00000047683716
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.z
value: -2.7281823
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.31, y: 0.232, z: 3.973}
m_LocalScale: {x: 0.4, y: 0.4, z: 0.4}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &38700534
PrefabInstance:
m_ObjectHideFlags: 0
@ -1978,15 +2022,19 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
maleNpcs:
- {fileID: 0}
- {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
femaleNpcs:
- {fileID: 0}
- {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
policeNpc: {fileID: 0}
spawnPoints: []
spawnPoints:
- {fileID: 1126609777}
playerFree: 0
currentNpcs: []
chairPositions: []
despawnPoints: []
chairPositions:
- {fileID: 9804464}
despawnPoints:
- {fileID: 711059150}
- {fileID: 1400559515}
--- !u!1 &543859847
GameObject:
m_ObjectHideFlags: 0
@ -5027,7 +5075,7 @@ BoxCollider:
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_Bits: 4294967295
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
@ -5069,6 +5117,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
doorLeft: {fileID: 816321262}
doorRight: {fileID: 331300392}
doorCloseDelay: 1.5
--- !u!1 &1318173673
GameObject:
m_ObjectHideFlags: 0
@ -7524,4 +7573,4 @@ SceneRoots:
- {fileID: 38700534}
- {fileID: 402867245}
- {fileID: 775517552}
- {fileID: 1396610}
- {fileID: 9804468}

View file

@ -958,12 +958,12 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1056860014}
- {fileID: 335017576}
- {fileID: 368167159}
- {fileID: 1132197014}
- {fileID: 1558064964}
- {fileID: 589608068}
- {fileID: 1056860014}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &545637506
@ -979,33 +979,16 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
maleNpcs:
- {fileID: 1162186098289904096, guid: b404be61a97237740821ffb3f801eb68, type: 3}
- {fileID: 939314035007084349, guid: b378ca729e9cce4408beb44639b2bc58, type: 3}
- {fileID: 5163734529656434887, guid: 592469d1f1c85824cb0586b51d080b18, type: 3}
- {fileID: 5439687604807156076, guid: f381ae8e8f34b8e4ca4a847775c0e60f, type: 3}
- {fileID: 3572036619537446221, guid: 06fee42127b3b4243a1d03df215365e7, type: 3}
- {fileID: 3212542082100280136, guid: d4e006b1ecd50d44984ac7e8f2fb965f, type: 3}
- {fileID: 6095755043422354155, guid: 4702ac9e34e5f4549be2d0acc2f00dae, type: 3}
- {fileID: 3475247101945908102, guid: 4478b7186cc0aad49b6185426503ea36, type: 3}
- {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
femaleNpcs:
- {fileID: 8874432443279944950, guid: 9d6c422b331360f478f55ea7828561a1, type: 3}
- {fileID: 5700822135220029682, guid: 9a0e848f4199dae46b8c371c6d792998, type: 3}
- {fileID: 807456354009633900, guid: b933b12f828c2fc45b6528e41b2e8824, type: 3}
- {fileID: 3994904034570386205, guid: 921de0f680b059b448b93a8c6d33b63e, type: 3}
- {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
policeNpc: {fileID: 6846919541000073478, guid: 5744d4b3c1617fe4096b9035ee1be4e8, type: 3}
spawnPoints:
- {fileID: 1056860014}
- {fileID: 335017576}
- {fileID: 368167159}
- {fileID: 1132197014}
- {fileID: 1558064964}
- {fileID: 589608068}
playerFree: 0
currentNpcs: []
chairPositions:
- {fileID: 1333249642}
- {fileID: 1333249642}
- {fileID: 1333249642}
despawnPoints: []
--- !u!114 &545637507
MonoBehaviour:
@ -1140,7 +1123,7 @@ Transform:
m_GameObject: {fileID: 1056860013}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -1.53231, y: 1.3681344, z: 2.4535394}
m_LocalPosition: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -1377,6 +1360,7 @@ GameObject:
- component: {fileID: 1333249645}
- component: {fileID: 1333249644}
- component: {fileID: 1333249643}
- component: {fileID: 1333249647}
m_Layer: 0
m_Name: Cube (2)
m_TagString: Untagged
@ -1401,7 +1385,7 @@ BoxCollider:
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
@ -1464,12 +1448,31 @@ Transform:
m_GameObject: {fileID: 1333249642}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 6.04, y: 0.268, z: -5.45}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_LocalPosition: {x: 6.04, y: 0.238, z: -5.45}
m_LocalScale: {x: 0.40720877, y: 0.40720877, z: 0.40720877}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1333249647
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1333249642}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e3fdca004f2d45fe8abbed571a8abd5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OverrideArea: 1
m_Area: 1
m_OverrideGenerateLinks: 0
m_GenerateLinks: 0
m_IgnoreFromBuild: 0
m_ApplyToChildren: 1
m_AffectedAgents: ffffffff
--- !u!1 &1558064963
GameObject:
m_ObjectHideFlags: 0
@ -1587,67 +1590,6 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &600650188589416568
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2866292048537355755, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: desk
value:
objectReference: {fileID: 505257119}
- target: {fileID: 8486445782931515160, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_Name
value: male1WithHair
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.x
value: 6.4546204
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.y
value: 0.04101038
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalPosition.z
value: -3.3671114
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9119289884132965794, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: beae5a92134b6f347a8cd76bfefd04da, type: 3}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
@ -1664,4 +1606,3 @@ SceneRoots:
- {fileID: 515541349}
- {fileID: 505257119}
- {fileID: 1333249646}
- {fileID: 600650188589416568}

View file

@ -18,7 +18,10 @@ public class Door : MonoBehaviour
[SerializeField] private GameObject doorLeft;
[SerializeField] private GameObject doorRight;
/// <summary>
/// a value to control delay the door closing
/// </summary>
public float doorCloseDelay = 0.75f;
private bool doorOpened = false;
/// <summary>
@ -39,6 +42,7 @@ public class Door : MonoBehaviour
/// <param name="other"></param>
void OnTriggerEnter(Collider other)
{
Debug.Log(other.name);
if (!doorOpened && (other.CompareTag("Player") || other.CompareTag("NPC")))
{
OpenDoor();
@ -61,7 +65,7 @@ public class Door : MonoBehaviour
doorRight.transform.eulerAngles = currentRightRotation;
doorOpened = true;
StartCoroutine(CloseDoorAfterDelay(0.75f));
StartCoroutine(CloseDoorAfterDelay(doorCloseDelay));
}
/// <summary>

View file

@ -33,16 +33,13 @@ public class NpcMovementRework : MonoBehaviour
{
animator.SetFloat(Speed, 0);
}
}
public void Start()
{
agent = gameObject.GetComponent<NavMeshAgent>();
animator = gameObject.GetComponent<Animator>();
var sitCoro = SitDown();
StartCoroutine(sitCoro);
StartCoroutine(SitDown());
}
@ -51,41 +48,35 @@ public class NpcMovementRework : MonoBehaviour
agent.SetDestination(desk.position);
}
public IEnumerator SitDown()
{
var i = Random.Range(0, NpcManager.instance.chairPositions.Length);
Debug.Log(i);
var pos = NpcManager.instance.chairPositions[i];
agent.SetDestination(pos.transform.position);
var sittingPosition = pos.transform.position+new Vector3(0,0.5f,0);
var sittingPosition = pos.transform.position;
sittingPosition.y = 0;
agent.SetDestination(sittingPosition);
while (true)
{
var dist= Vector3.Distance(pos.transform.position,gameObject.transform.position);
if (dist <0.5)
var dist= Vector3.Distance(sittingPosition,gameObject.transform.position);
// Debug.Log(dist);
if (dist < 0.05f)
{
agent.SetDestination(gameObject.transform.position);
animator.SetBool(IsSitting, true);
gameObject.transform.rotation = pos.transform.rotation;
gameObject.transform.position=sittingPosition;
animator.SetBool(IsSitting,true);
yield break;
break;
}
yield return new WaitForEndOfFrame();
yield return 0;
}
}
public void Despawn()
{
var random= Random.Range(0, NpcManager.instance.despawnPoints.Length);
var random = Random.Range(0, NpcManager.instance.despawnPoints.Length);
agent.SetDestination(NpcManager.instance.despawnPoints[random].position);
}
}

View file

@ -75,6 +75,11 @@ public class NpcManager : MonoBehaviour
// currentNpcs.SetValue(npc,currentNpcs.Length);
}
private void Start()
{
spawnNpc(false, spawnPoints[0]);
}
public void Awake()
{
if (instance == null)