浏览代码

Merge pull request #25 from Wodopo/master

Simple Player Spawn System
/main
GitHub 4 年前
当前提交
afc7b64e
共有 7 个文件被更改,包括 288 次插入97 次删除
  1. 1
      UOP1_Project/Assets/Prefabs/Pig.prefab
  2. 189
      UOP1_Project/Assets/Scenes/CharController.unity
  3. 16
      UOP1_Project/Assets/Scripts/CameraManager.cs
  4. 82
      UOP1_Project/Assets/Prefabs/SpawnSystem.prefab
  5. 7
      UOP1_Project/Assets/Prefabs/SpawnSystem.prefab.meta
  6. 79
      UOP1_Project/Assets/Scripts/SpawnSystem.cs
  7. 11
      UOP1_Project/Assets/Scripts/SpawnSystem.cs.meta

1
UOP1_Project/Assets/Prefabs/Pig.prefab


m_Name:
m_EditorClassIdentifier:
speed: 8
turnSmoothTime: 0.2
gravityMultiplier: 5
initialJumpForce: 10
jumpInputDuration: 0.4

189
UOP1_Project/Assets/Scenes/CharController.unity


m_StreamingVersion: 20170927
m_Priority: 10
m_StandbyUpdate: 2
m_LookAt: {fileID: 1961901426}
m_Follow: {fileID: 1961901426}
m_LookAt: {fileID: 0}
m_Follow: {fileID: 0}
m_Lens:
FieldOfView: 60
OrthographicSize: 5

m_Children:
- {fileID: 2020721999}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &135922106
MonoBehaviour:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 233317031}
m_LocalRotation: {x: 0.18994758, y: -0.20527026, z: 0.040647585, w: 0.959235}
m_LocalRotation: {x: 0.18994758, y: -0.2052703, z: 0.040647592, w: 0.959235}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_LocalScale: {x: 5.7737727, y: 1.8967, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: -3.5180001, y: 26.323002, z: -19.474}
--- !u!1 &353533559
GameObject:

m_LocalScale: {x: 4.8320527, y: 1, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &358843509
GameObject:

m_LocalScale: {x: 7.8816566, y: 6.5043144, z: 2.0265193}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 24
m_RootOrder: 25
m_LocalEulerAnglesHint: {x: 0, y: 90.00001, z: 0}
--- !u!1001 &393067907
PrefabInstance:

- target: {fileID: 7160299325435046207, guid: fe3004506b4c6cd478eb2cca639b3713,
type: 3}
propertyPath: m_RootOrder
value: 21
value: 22
objectReference: {fileID: 0}
- target: {fileID: 7160299325435046207, guid: fe3004506b4c6cd478eb2cca639b3713,
type: 3}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &526256409
GameObject:

m_Name:
m_EditorClassIdentifier:
inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
mainCamera: {fileID: 1961065789}
freeLookVCam: {fileID: 1502793901}
--- !u!4 &526256411
Transform:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &695792052
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &802198071
PrefabInstance:

- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}
propertyPath: m_RootOrder
value: 16
value: 17
objectReference: {fileID: 0}
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &826602623
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &955504286
GameObject:

m_LocalScale: {x: 4.66705, y: 1, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &982338980
GameObject:

m_LocalScale: {x: 4.66705, y: 1, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 25
m_RootOrder: 26
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 12.259001}
--- !u!1 &1057381576
GameObject:

m_LocalScale: {x: 6.068361, y: 6.5043144, z: 0.65092325}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 23
m_RootOrder: 24
m_LocalEulerAnglesHint: {x: 0, y: -34.734, z: 0}
--- !u!1 &1069143686
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1069947040
GameObject:

- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}
propertyPath: m_RootOrder
value: 17
value: 18
objectReference: {fileID: 0}
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}

m_LocalScale: {x: 9.785265, y: 1.1941, z: 1.4703052}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1424964852
GameObject:

m_LocalScale: {x: 11.689932, y: 6.5043144, z: 2.0265193}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 22
m_RootOrder: 23
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1502793900
GameObject:

m_StreamingVersion: 20170927
m_Priority: 10
m_StandbyUpdate: 2
m_LookAt: {fileID: 1961901426}
m_Follow: {fileID: 1961901426}
m_LookAt: {fileID: 0}
m_Follow: {fileID: 0}
m_CommonLens: 1
m_Lens:
FieldOfView: 40

- {fileID: 2049112421}
- {fileID: 233317033}
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1523164311
GameObject:

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 27
m_RootOrder: 28
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1559010558
GameObject:

m_LocalScale: {x: 4.66705, y: 1, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 26
m_RootOrder: 27
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 12.259001}
--- !u!1 &1567022179
GameObject:

m_LocalScale: {x: 5.7737727, y: 1.8967, z: 4.9019}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 15
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: -3.5180001, y: 26.324001, z: 28.011002}
--- !u!1001 &1809933188
PrefabInstance:

- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}
propertyPath: m_RootOrder
value: 20
value: 21
objectReference: {fileID: 0}
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}

- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}
propertyPath: m_RootOrder
value: 19
value: 20
objectReference: {fileID: 0}
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
type: 3}

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1961065787}
m_LocalRotation: {x: 0.18778463, y: -0.20536137, z: 0.040184725, w: 0.95966077}
m_LocalRotation: {x: 0.18778464, y: -0.20536137, z: 0.040184725, w: 0.9596608}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1961065791
MonoBehaviour:

m_CameraActivatedEvent:
m_PersistentCalls:
m_Calls: []
--- !u!4 &1961901426 stripped
--- !u!4 &2006012550 stripped
m_CorrespondingSourceObject: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
m_CorrespondingSourceObject: {fileID: 2125786286893897154, guid: e978d53d440e0814086759404585ac32,
m_PrefabInstance: {fileID: 3341179907149091243}
m_PrefabInstance: {fileID: 2093632590}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2018663598
GameObject:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2049112419}
m_LocalRotation: {x: 0.18778461, y: -0.20536137, z: 0.04018472, w: 0.9596608}
m_LocalRotation: {x: 0.18778461, y: -0.20536137, z: 0.040184718, w: 0.9596608}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &2370768318719443585
--- !u!1001 &2093632590
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2

- target: {fileID: 364731123117828817, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829329, guid: e978d53d440e0814086759404585ac32,
value: SmallBuilding
value: SpawnSystem
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _spawnLocations.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _cameraManager
value:
objectReference: {fileID: 526256410}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _spawnLocations.Array.data[0]
value:
objectReference: {fileID: 2006012550}
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -17.85
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -0.14
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: 9.51
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -0
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -0
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -0.019262606
value: 0
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: 0.99981445
value: 1
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: 14
value: 1
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
value: -2.207
value: 0
m_SourcePrefab: {fileID: 100100000, guid: 1ebb75c12ef91014e94524019e01192d, type: 3}
--- !u!1001 &3341179907149091243
m_SourcePrefab: {fileID: 100100000, guid: e978d53d440e0814086759404585ac32, type: 3}
--- !u!1001 &2370768318719443585
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2

- target: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: gameplayCamera
value:
objectReference: {fileID: 1961065790}
- target: {fileID: 3341179906418240709, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 364731123117828817, guid: 1ebb75c12ef91014e94524019e01192d,
value: Pig
value: SmallBuilding
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0.62
value: -17.85
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0.307
value: -0.14
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: -15.776
value: 9.51
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0
value: -0
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0
value: -0
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0
value: -0.019262606
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 1
value: 0.99981445
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 28
value: 15
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
- target: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
- target: {fileID: 384383464925863578, guid: 1ebb75c12ef91014e94524019e01192d,
value: 0
value: -2.207
m_SourcePrefab: {fileID: 100100000, guid: 0fa393e1e37bc9e4e829c25a9452bcd3, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 1ebb75c12ef91014e94524019e01192d, type: 3}
--- !u!1001 &6560919939139749480
PrefabInstance:
m_ObjectHideFlags: 0

- target: {fileID: 7160299325435046207, guid: fe3004506b4c6cd478eb2cca639b3713,
type: 3}
propertyPath: m_RootOrder
value: 18
value: 19
objectReference: {fileID: 0}
- target: {fileID: 7160299325435046207, guid: fe3004506b4c6cd478eb2cca639b3713,
type: 3}

16
UOP1_Project/Assets/Scripts/CameraManager.cs


public class CameraManager : MonoBehaviour
{
public InputReader inputReader;
public Camera mainCamera;
[Tooltip("General multiplier for camera sensitivity/speed")]
[Range(1.0f, 20.0f)]
[SerializeField] private float cameraSensitivity = 7.0f;
public void SetupProtagonistVirtualCamera(Transform target)
{
freeLookVCam.Follow = target;
freeLookVCam.LookAt = target;
}
//...
//Removes all listeners to the events coming from the InputReader script
//...
freeLookVCam.m_XAxis.m_InputAxisValue = cameraMovement.x * Time.smoothDeltaTime * cameraSensitivity;
freeLookVCam.m_YAxis.m_InputAxisValue = cameraMovement.y * Time.smoothDeltaTime * cameraSensitivity;
freeLookVCam.m_XAxis.m_InputAxisValue = cameraMovement.x * Time.smoothDeltaTime;
freeLookVCam.m_YAxis.m_InputAxisValue = cameraMovement.y * Time.smoothDeltaTime;
}
}

82
UOP1_Project/Assets/Prefabs/SpawnSystem.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2125786285293829329
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2125786285293829335}
- component: {fileID: 2125786285293829334}
m_Layer: 0
m_Name: SpawnSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2125786285293829335
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2125786285293829329}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2125786286893897154}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2125786285293829334
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2125786285293829329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 65dde41d869e66e4d87103c43970a518, type: 3}
m_Name:
m_EditorClassIdentifier:
_defaultSpawnIndex: 0
_playerPrefab: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
_inputReader: {fileID: 0}
_gameplayCamera: {fileID: 0}
_spawnLocations: []
--- !u!1 &2125786286893897213
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2125786286893897154}
m_Layer: 0
m_Name: Location 01
m_TagString: Untagged
m_Icon: {fileID: 3936346786652291628, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2125786286893897154
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2125786286893897213}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -14.173, y: 0.69, z: -9.637}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2125786285293829335}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}

7
UOP1_Project/Assets/Prefabs/SpawnSystem.prefab.meta


fileFormatVersion: 2
guid: e978d53d440e0814086759404585ac32
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

79
UOP1_Project/Assets/Scripts/SpawnSystem.cs


using System;
using System.Linq;
using UnityEditor.PackageManager;
using UnityEngine;
using UnityEngine.Events;
public class SpawnSystem : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private int _defaultSpawnIndex = 0;
[Header("Project References")]
[SerializeField] private Protagonist _playerPrefab = null;
[Header("Scene References")]
[SerializeField] private CameraManager _cameraManager;
[SerializeField] private Transform[] _spawnLocations;
void Awake()
{
try
{
Spawn(_defaultSpawnIndex);
}
catch (Exception e)
{
Debug.LogError($"[SpawnSystem] Failed to spawn player. {e.Message}");
}
}
void Reset()
{
AutoFill();
}
[ContextMenu("Attempt Auto Fill")]
private void AutoFill()
{
if(_cameraManager == null)
_cameraManager = FindObjectOfType<CameraManager>();
if (_spawnLocations == null || _spawnLocations.Length == 0)
_spawnLocations = transform.GetComponentsInChildren<Transform>(true)
.Where(t => t != this.transform)
.ToArray();
}
private void Spawn(int spawnIndex)
{
Transform spawnLocation = GetSpawnLocation(spawnIndex, _spawnLocations);
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, spawnLocation, _cameraManager);
SetupCameras(playerInstance);
}
private Transform GetSpawnLocation(int index, Transform[] spawnLocations)
{
if (spawnLocations == null || spawnLocations.Length == 0)
throw new Exception("No spawn locations set.");
index = Mathf.Clamp(index, 0, spawnLocations.Length - 1);
return spawnLocations[index];
}
private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation, CameraManager _cameraManager)
{
if (playerPrefab == null)
throw new Exception("Player Prefab can't be null.");
Protagonist playerInstance = Instantiate(playerPrefab, spawnLocation.position, spawnLocation.rotation);
return playerInstance;
}
private void SetupCameras(Protagonist player)
{
player.gameplayCamera = _cameraManager.mainCamera.transform;
_cameraManager.SetupProtagonistVirtualCamera(player.transform);
}
}

11
UOP1_Project/Assets/Scripts/SpawnSystem.cs.meta


fileFormatVersion: 2
guid: 65dde41d869e66e4d87103c43970a518
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存