Made the elevator button-functional. Needs some fine-tuning and audio work.

This commit is contained in:
mxssw 2025-11-30 22:05:25 +02:00
parent bcf7e3121d
commit dab5bfc677
12 changed files with 483 additions and 74 deletions

View File

@ -29,7 +29,7 @@ Material:
m_Ints: []
m_Floats: []
m_Colors:
- _EmissionColor: {r: 32, g: 32, b: 32, a: 0}
- _EmissionColor: {r: 10.680627, g: 10.680627, b: 10.680627, a: 0}
m_BuildTextureStacks: []
--- !u!114 &3687797256646661601
MonoBehaviour:

View File

@ -0,0 +1,48 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: elevator Variant 11
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 8264915245645977465, guid: e2815ed7e4ba71345aba4539e8e4b07e,
type: 3}
m_ModifiedSerializedProperties: 2
m_ValidKeywords:
- _EMISSION
m_InvalidKeywords: []
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap:
RenderType: Opaque
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats: []
m_Colors:
- _BaseColor: {r: 1, g: 0.6430054, b: 0.0039215684, a: 1}
- _Color: {r: 1, g: 0.6430054, b: 0.0039215684, a: 1}
- _EmissionColor: {r: 7.9709907, g: 0.07423936, b: 0, a: 0}
m_BuildTextureStacks: []
--- !u!114 &3687797256646661601
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 7

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e06a4feba1c7c8d4d9ccd9f08217c305
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -296,14 +296,27 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 3142790275690355627}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 6493031215605065994}
- {fileID: 2029427538857035721}
- {fileID: 6332036866947783938}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 0
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 0
disabled: 0
--- !u!1 &438676407175250832
GameObject:
m_ObjectHideFlags: 0
@ -401,14 +414,25 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 9087196922762249673}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 4082014259661750081}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 1
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 2
disabled: 0
--- !u!1 &537381219194983551
GameObject:
m_ObjectHideFlags: 0
@ -757,14 +781,27 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 6204781832038596249}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 1451428946001551558}
- {fileID: 3244295921045762938}
- {fileID: 350891245177445368}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 0
isInsideButton: 1
isCloseDoorsButton: 1
designatedFloor: 0
disabled: 0
--- !u!1 &996792314886891216
GameObject:
m_ObjectHideFlags: 0
@ -2857,14 +2894,25 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 3279722334677606978}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 8021515965739304570}
defaultMaterial: {fileID: 2100000, guid: 41f12eac51f3a45459e319b9f41ecb1a, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 0
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 0
disabled: 1
--- !u!1 &3325045702031210896
GameObject:
m_ObjectHideFlags: 0
@ -5390,14 +5438,27 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 4950653880436739319}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 446523802055600108}
- {fileID: 2127213541793439145}
- {fileID: 8792729680998815027}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 1
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: -1
disabled: 1
--- !u!1 &6561745356880359737
GameObject:
m_ObjectHideFlags: 0
@ -5692,14 +5753,25 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 3019113234126189591}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 7380030302891720191}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 1
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 3
disabled: 1
--- !u!1 &7341798644222801918
GameObject:
m_ObjectHideFlags: 0
@ -5880,14 +5952,25 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 2675260468325638204}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 683714234332461835}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 1
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 0
disabled: 1
--- !u!1 &7417427669271232914
GameObject:
m_ObjectHideFlags: 0
@ -6028,7 +6111,7 @@ BoxCollider:
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.02, y: 0.02, z: 0.004}
m_Size: {x: 0.02, y: 0.02, z: 0.008}
m_Center: {x: -0.0000038146973, y: -0.00000023841858, z: 0.0028}
--- !u!54 &95927051609668696
Rigidbody:
@ -6070,14 +6153,26 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
buttonDirectionRoot: {fileID: 282480526633532855}
ElevatorOuter: {fileID: 0}
box: {fileID: 0}
minX: 0
maxX: 0
minY: 0
maxY: 0
minZ: -0.005
minZ: -0.009
maxZ: 0
targetRenderers:
- {fileID: 8767912935277034470}
- {fileID: 3147421208204254064}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 300
damping: 8
isFloorButton: 1
isInsideButton: 1
isCloseDoorsButton: 0
designatedFloor: 1
disabled: 0
--- !u!1 &7850065779318502237
GameObject:
m_ObjectHideFlags: 0

View File

@ -22,12 +22,12 @@ Material:
m_PrefabAsset: {fileID: 0}
m_Name: elevator fbx Variant 1
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 2100000, guid: d2cb0067ec2dac14b830006b4537c6d7, type: 2}
m_ModifiedSerializedProperties: 0
m_Parent: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
m_ModifiedSerializedProperties: 2
m_ValidKeywords:
- _EMISSION
m_InvalidKeywords: []
m_LightmapFlags: 4
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
@ -40,5 +40,6 @@ Material:
m_TexEnvs: []
m_Ints: []
m_Floats: []
m_Colors: []
m_Colors:
- _EmissionColor: {r: 26.240507, g: 0.4325358, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@ -506,8 +506,13 @@ MonoBehaviour:
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 8004183478493254772}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 3000
damping: 8
disabled: 0
--- !u!1 &1655508674808552005
GameObject:
m_ObjectHideFlags: 0
@ -652,7 +657,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: df2499e0d0b1e5f4eb0aa3b7de2fb414, type: 2}
- {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -1839,8 +1844,13 @@ MonoBehaviour:
maxY: 0
minZ: -0.005
maxZ: 0
targetRenderers:
- {fileID: 8629732451978090602}
defaultMaterial: {fileID: 2100000, guid: fb15ade5b41060f43816470c3c3dae03, type: 2}
pressedMaterial: {fileID: 2100000, guid: e06a4feba1c7c8d4d9ccd9f08217c305, type: 2}
springForce: 3000
damping: 8
disabled: 0
--- !u!1 &6792274789431496444
GameObject:
m_ObjectHideFlags: 0

View File

@ -1777,7 +1777,12 @@ MonoBehaviour:
<IsNested>k__BackingField: 0
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
_networkBehaviours: []
_networkBehaviours:
- {fileID: 7806173994934619905}
- {fileID: 345553692048754556}
- {fileID: 6603687395008658796}
- {fileID: 764953073149743973}
- {fileID: 2881803077339660242}
<ParentNetworkObject>k__BackingField: {fileID: 0}
<ChildNetworkObjects>k__BackingField: []
_isNetworked: 1
@ -1787,7 +1792,7 @@ MonoBehaviour:
NetworkObserver: {fileID: 0}
<PrefabId>k__BackingField: 0
<SpawnableCollectionId>k__BackingField: 0
_scenePathHash: 353480863
_scenePathHash: 0
<SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 15435807940015550974
_sceneNetworkObjects:
@ -2163,6 +2168,41 @@ PrefabInstance:
propertyPath: m_Name
value: right door
objectReference: {fileID: 0}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: ElevatorOuter
value:
objectReference: {fileID: 345553692048754556}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: designatedFloor
value: 2
objectReference: {fileID: 0}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: ElevatorOuter
value:
objectReference: {fileID: 345553692048754556}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: designatedFloor
value: 2
objectReference: {fileID: 0}
- target: {fileID: 7080676229175652277, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7235137764202097191, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: m_LocalPosition.z
@ -2231,6 +2271,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b0a42248826403b4290be3c9eaf0cd8a, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 3
_addedNetworkObject: {fileID: 8195804890146573050}
_networkObjectCache: {fileID: 8195804890146573050}
floorNumbers:
- floorNumber: 1
floorNumberSprite: {fileID: 8645089989254867705}
@ -2274,6 +2317,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5ef47691d9311604abf356d87aa8e028, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 1
_addedNetworkObject: {fileID: 8195804890146573050}
_networkObjectCache: {fileID: 8195804890146573050}
box: {fileID: 7806173994934619905}
floor: 2
boxPos: {fileID: 4660138546890809471}
@ -2390,6 +2436,36 @@ PrefabInstance:
propertyPath: m_Name
value: right door
objectReference: {fileID: 0}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: ElevatorOuter
value:
objectReference: {fileID: 6603687395008658796}
- target: {fileID: 5880420167976964992, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: designatedFloor
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: ElevatorOuter
value:
objectReference: {fileID: 6603687395008658796}
- target: {fileID: 6716688150999816398, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: designatedFloor
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6941309913956637266, guid: 39c6662c65f8b8740b0dcba6607a839d,
type: 3}
propertyPath: m_BoxSize.y
@ -2509,7 +2585,7 @@ BoxCollider:
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
m_Enabled: 0
serializedVersion: 3
m_Size: {x: 4, y: 3, z: 10}
m_Center: {x: -2.96, y: 1.46, z: 0}
@ -2525,6 +2601,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5ef47691d9311604abf356d87aa8e028, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 2
_addedNetworkObject: {fileID: 8195804890146573050}
_networkObjectCache: {fileID: 8195804890146573050}
box: {fileID: 7806173994934619905}
floor: 1
boxPos: {fileID: 9140433812702186628}
@ -2572,6 +2651,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b0a42248826403b4290be3c9eaf0cd8a, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 4
_addedNetworkObject: {fileID: 8195804890146573050}
_networkObjectCache: {fileID: 8195804890146573050}
floorNumbers:
- floorNumber: 1
floorNumberSprite: {fileID: 8278171174262717255}
@ -2598,11 +2680,31 @@ PrefabInstance:
propertyPath: m_LocalPosition.z
value: -0.327
objectReference: {fileID: 0}
- target: {fileID: 1868872862445697854, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 2472413635749971489, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 2540213522334542846, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: m_Name
value: Elevator box
objectReference: {fileID: 0}
- target: {fileID: 2769017712769253367, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 3104556117277622356, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 3833835715982065669, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: m_Name
@ -2688,6 +2790,21 @@ PrefabInstance:
propertyPath: rolloffCustomCurve.m_Curve.Array.data[0].outWeight
value: 0.85364515
objectReference: {fileID: 0}
- target: {fileID: 5849504599276584512, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 6897965602403835351, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 7333161818204528723, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
- target: {fileID: 8544266915878642225, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: m_Name
@ -2748,6 +2865,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9016434821259732323, guid: 74670edb0ba92b34f92801f43b666e78,
type: 3}
propertyPath: box
value:
objectReference: {fileID: 7806173994934619905}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects:
@ -2831,6 +2953,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 73ccfdd4c926d054ba4f2e96fcb15082, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 0
_addedNetworkObject: {fileID: 8195804890146573050}
_networkObjectCache: {fileID: 8195804890146573050}
callers:
- {fileID: 6603687395008658796}
- {fileID: 345553692048754556}
@ -2868,3 +2993,6 @@ MonoBehaviour:
- {fileID: 8300000, guid: 0c020deef579e2d4aab4b2cc4b12d2e2, type: 3}
- {fileID: 8300000, guid: 57951d8061bb3da4c84d70f7bf8b0339, type: 3}
- {fileID: 8300000, guid: 0b3401cfc5e423d40aec96d322084d20, type: 3}
currentFloor: 2
targetFloor: 2
state: 1

View File

@ -4,12 +4,20 @@ using UnityEngine;
public class ElevatorCaller : MonoBehaviour
{
// Start is called before the first frame update
private void OnTriggerEnter(Collider other)
{
SpringyButtonPhysics button = other.GetComponent<SpringyButtonPhysics>();
//Debug.Log(other);
ElevatorSpringyButton button = other.GetComponent<ElevatorSpringyButton>();
if (button == null) return;
else button.Pressed();
else
{
button.Pressed();
}
}
void Start()
{

View File

@ -7,9 +7,9 @@ using UnityEditor;
using UnityEngine;
public enum ElevatorState
{
Stationary,
OpenDoorsStationary,
CloseDoorsStationary,
OpeningDoors,
AwaitingPassengers,
ClosingDoors,
Moving
}
@ -59,10 +59,10 @@ public class ElevatorBox : NetworkBehaviour
public AudioClip[] closeDoorsClips;
public AudioClip[] moveElevatorClips;
private int currentFloor = 2;
private int targetFloor = 2;
public int currentFloor = 2;
public int targetFloor = 2;
private ElevatorState state = ElevatorState.Stationary;
public ElevatorState state = ElevatorState.CloseDoorsStationary;
void Awake()
{
@ -88,7 +88,7 @@ public class ElevatorBox : NetworkBehaviour
{
//Debug.Log("Calling Elevator");
Debug.Log(state);
if (state == ElevatorState.Stationary || state == ElevatorState.ClosingDoors)
if (state == ElevatorState.OpenDoorsStationary || state == ElevatorState.CloseDoorsStationary || state == ElevatorState.ClosingDoors)
{
Debug.Log(floor);
@ -103,13 +103,13 @@ public class ElevatorBox : NetworkBehaviour
StartCoroutine(OpenDoors());
SetState(ElevatorState.AwaitingPassengers);
SetState(ElevatorState.OpenDoorsStationary);
}
}
public void interestExpired()
{
if (state == ElevatorState.AwaitingPassengers)
if (state == ElevatorState.OpenDoorsStationary)
{
if (IsElevatorEmpty())
{
@ -130,12 +130,13 @@ public class ElevatorBox : NetworkBehaviour
}
private void OnTriggerEnter(Collider other)
{
if (other.GetComponentInParent<SmartHandPresence>() != null) return; // So it ignores player hands.
XROrigin enteredPlayerVR = other.GetComponent<XROrigin>();
KbmController enteredPlayerKbm = other.GetComponent<KbmController>();
XRPlayerMirror networkPlayerDisplay = other.GetComponentInParent<XRPlayerMirror>();
Debug.Log("Player Entered box");
//Debug.Log("Player Entered box");
if (enteredPlayerVR != null)
{
addChild(enteredPlayerVR);
@ -150,11 +151,11 @@ public class ElevatorBox : NetworkBehaviour
}
else {
Debug.Log(other + " Cannot ride in lifts.");
//Debug.Log(other + " Cannot ride in lifts.");
return;
}
Debug.Log("Calling Lift transfer sequence");
/*Debug.Log("Calling Lift transfer sequence");
switch (currentFloor)
{
@ -170,7 +171,7 @@ public class ElevatorBox : NetworkBehaviour
break;
}
StartCoroutine(LiftTransferSequence());
StartCoroutine(LiftTransferSequence()); */
}
@ -199,7 +200,7 @@ public class ElevatorBox : NetworkBehaviour
Debug.Log("Player exited box, state is: " + this.state);
if (this.state == ElevatorState.AwaitingPassengers)
if (this.state == ElevatorState.OpenDoorsStationary)
{
if (IsElevatorEmpty())
{
@ -278,27 +279,30 @@ public class ElevatorBox : NetworkBehaviour
audioSource.Play();
}
private IEnumerator LiftTransferSequence()
public IEnumerator LiftTransferSequence()
{
Debug.Log("Started Lidt transfer sequence");
if (state != ElevatorState.Moving);
Debug.Log("Started Lift transfer sequence");
yield return StartCoroutine(CloseDoors());
yield return StartCoroutine(MoveToFloor(targetFloor));
}
public IEnumerator MoveToFloor(int floorNumber)
{
Debug.Log("Moving to floor " + floorNumber);
if (floorDict.TryGetValue(floorNumber, out Transform target))
{
yield return StartCoroutine(MoveElevator(target.position));
SetCurrentFloor(targetFloor);
}
else
{
Debug.LogWarning($"No floor defined for number {floorNumber}");
}
if (state == ElevatorState.CloseDoorsStationary) {
//Debug.Log("Moving to floor " + floorNumber);
if (floorDict.TryGetValue(floorNumber, out Transform target))
{
yield return StartCoroutine(MoveElevator(target.position));
SetCurrentFloor(targetFloor);
}
else
{
Debug.LogWarning($"No floor defined for number {floorNumber}");
}
state = ElevatorState.CloseDoorsStationary;
yield return StartCoroutine(OpenDoors());
yield return StartCoroutine(OpenDoors());
}
}
private IEnumerator CloseAndStationary()
{
@ -307,12 +311,14 @@ public class ElevatorBox : NetworkBehaviour
yield return StartCoroutine(CloseDoors());
// After doors have closed, set state
SetState(ElevatorState.Stationary);
SetState(ElevatorState.CloseDoorsStationary);
}
private IEnumerator CloseDoors()
public IEnumerator CloseDoors()
{
//if (state == ElevatorState.AwaitingPassengers) {
Debug.Log(state);
if (state != ElevatorState.OpeningDoors && state != ElevatorState.CloseDoorsStationary && state != ElevatorState.ClosingDoors)
{
Debug.Log("Closing doors");
if (Vector3.Distance(leftDoor.transform.position, leftDoorClosedPos.position) < 0.01f)
@ -328,14 +334,15 @@ public class ElevatorBox : NetworkBehaviour
if (currentCaller != null) currentCaller.CloseDoors();
yield return StartCoroutine(MoveDoors(leftDoor, leftDoorClosedPos, rightDoor, rightDoorClosedPos, doorCloseTime));
//}
SetState(ElevatorState.CloseDoorsStationary);
}
}
private IEnumerator OpenDoors()
public IEnumerator OpenDoors()
{
if (state != ElevatorState.AwaitingPassengers) {
//Debug.Log("Opening doors");
if (state != ElevatorState.OpeningDoors && state != ElevatorState.OpenDoorsStationary && state != ElevatorState.Moving) {
Debug.Log("Opening doors");
SetState(ElevatorState.OpeningDoors);
playRandomAudioClipFrom(openDoorsClips);
@ -349,7 +356,7 @@ public class ElevatorBox : NetworkBehaviour
yield return StartCoroutine(MoveDoors(leftDoor, leftDoorOpenPos, rightDoor, rightDoorOpenPos, doorOpenTime));
SetState(ElevatorState.AwaitingPassengers);
SetState(ElevatorState.OpenDoorsStationary);
yield return new WaitForSeconds(doorStayOpenTime); // wait for passengers
}
}
@ -376,30 +383,31 @@ public class ElevatorBox : NetworkBehaviour
private IEnumerator MoveElevator(Vector3 targetPos)
{
if (targetFloor > currentFloor)
foreach (ElevatorOuter caller in callers)
caller.statusPlate.SetMoveState(ElevatorMoveState.Ascending);
if (targetFloor != currentFloor) {
if (targetFloor > currentFloor)
foreach (ElevatorOuter caller in callers)
caller.statusPlate.SetMoveState(ElevatorMoveState.Ascending);
else
foreach (ElevatorOuter caller in callers)
caller.statusPlate.SetMoveState(ElevatorMoveState.Decending);
else
foreach (ElevatorOuter caller in callers)
caller.statusPlate.SetMoveState(ElevatorMoveState.Decending);
Vector3 startPos = transform.position;
float t = 0;
Vector3 startPos = transform.position;
float t = 0;
SetState(ElevatorState.Moving);
playRandomAudioClipFrom(moveElevatorClips);
SetState(ElevatorState.Moving);
playRandomAudioClipFrom(moveElevatorClips);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ElevatorMovement, gameObject); //fmod attached 3d oneshot event
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ElevatorMovement, gameObject); //fmod attached 3d oneshot event
while (t < 1f)
{
t += Time.deltaTime / floorMoveTime;
float easedT = Mathf.SmoothStep(0f, 1f, t); // ease in/out
transform.position = Vector3.Lerp(startPos, targetPos, easedT);
yield return null;
while (t < 1f)
{
t += Time.deltaTime / floorMoveTime;
float easedT = Mathf.SmoothStep(0f, 1f, t); // ease in/out
transform.position = Vector3.Lerp(startPos, targetPos, easedT);
yield return null;
}
}
foreach (ElevatorOuter caller in callers)
caller.statusPlate.SetMoveState(ElevatorMoveState.NotMoving);
}

View File

@ -45,12 +45,9 @@ public class ElevatorOuter : NetworkBehaviour
}
}
private void OnTriggerEnter(Collider other)
public void CallElevator()
{
Debug.Log("Something entered call area");
if (other.GetComponentInParent<XRPlayerMirror>() == null) return;
StartCoroutine(box.callElevator(floor));
Debug.Log("Player entered call area");
}
private void OnTriggerExit(Collider other)

View File

@ -1,9 +1,13 @@
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class SpringyButtonPhysics : MonoBehaviour {
public class ElevatorSpringyButton : MonoBehaviour {
public Transform buttonDirectionRoot;
public ElevatorOuter ElevatorOuter;
public ElevatorBox box;
[Header("Movement limits")]
public float minX = 0f;
public float maxX = 0f;
public float minY = 0f;
@ -11,14 +15,31 @@ public class SpringyButtonPhysics : MonoBehaviour {
public float minZ = 0.005f;
public float maxZ = 0f;
[Header("Visuals")]
public Renderer[] targetRenderers;
public Material defaultMaterial;
public Material pressedMaterial;
[Header("Spring Settings")]
public float springForce = 300f; // how strong it returns
public float damping = 8f; // prevents vibration
[Header("Button Type Settings")]
public bool isFloorButton;
public bool isInsideButton;
public bool isCloseDoorsButton;
public int designatedFloor;
private Rigidbody rb;
private Vector3 restLocalPos;
public bool disabled;
private bool isAwaitingResponse = false;
void Start()
{
rb = GetComponent<Rigidbody>();
@ -58,9 +79,94 @@ public class SpringyButtonPhysics : MonoBehaviour {
// --- 5. Convert back to world and move via Rigidbody ---
Vector3 worldPos = buttonDirectionRoot.TransformPoint(newLocalPos);
rb.MovePosition(worldPos);
//Keeping the buttons firing until their needs have been met
if (!isAwaitingResponse || disabled) return;
if (!isInsideButton && box != null)
{
if (box.currentFloor == designatedFloor) StartCoroutine(DeactivateAfterDelay(0.5f));
else Pressed();
return;
}
if (isInsideButton && box != null)
{
if (isFloorButton)
{
if (designatedFloor == box.currentFloor) StartCoroutine(DeactivateAfterDelay(0.5f));
else Pressed();
return;
}
if (isCloseDoorsButton)
{
if (box.state == ElevatorState.ClosingDoors|| box.state == ElevatorState.Moving) StartCoroutine(DeactivateAfterDelay(0.5f));
else Pressed();
return;
}
else
{
if (box.state == ElevatorState.OpeningDoors || box.state == ElevatorState.Moving) StartCoroutine(DeactivateAfterDelay(0.5f));
else Pressed();
return;
}
}
}
public void Pressed()
{
Debug.Log("Button is pressed");
isAwaitingResponse = true;
foreach (Renderer renderer in targetRenderers)
{
renderer.material = pressedMaterial;
}
//Debug.Log("Button is pressed");
if (ElevatorOuter != null && !isInsideButton) ElevatorOuter.CallElevator();
if (disabled) StartCoroutine(DeactivateAfterDelay(0.5f));
if (box != null && isInsideButton)
{
if (isFloorButton)
{
box.targetFloor = designatedFloor;
if (box.targetFloor != box.currentFloor) {
Debug.Log("Lift transfer sequence");
StartCoroutine(box.LiftTransferSequence());
}
else StartCoroutine(box.OpenDoors());
return;
}
if (isCloseDoorsButton)
{
//Debug.Log("Closing Doors");
StartCoroutine(box.CloseDoors());
return;
}
else
{
StartCoroutine(box.OpenDoors());
//Debug.Log("Opening Doors");
return;
}
}
}
public void Deactivate()
{
Debug.Log("Deactivating");
//if (isAwaitingResponse) return;
isAwaitingResponse = false;
foreach (Renderer renderer in targetRenderers)
{
renderer.material = defaultMaterial;
}
}
private System.Collections.IEnumerator DeactivateAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
//isAwaitingResponse = false;
Deactivate();
}
}

Binary file not shown.