浏览代码

Spawn system in place

/main
Ciro Continisio 4 年前
当前提交
4aaa3b36
共有 9 个文件被更改,包括 200 次插入337 次删除
  1. 1
      UOP1_Project/Assets/Prefabs/Pig.prefab
  2. 16
      UOP1_Project/Assets/Prefabs/SpawnSystem.prefab
  3. 357
      UOP1_Project/Assets/Scenes/CharController.unity
  4. 10
      UOP1_Project/Assets/Scripts/CameraManager.cs
  5. 128
      UOP1_Project/Assets/Scripts/SpawnSystem.cs
  6. 5
      UOP1_Project/Packages/packages-lock.json
  7. 2
      UOP1_Project/ProjectSettings/QualitySettings.asset
  8. 7
      UOP1_Project/Assets/Prefabs/SpawnSystem.prefab.meta
  9. 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

16
UOP1_Project/Assets/Prefabs/SpawnSystem.prefab


m_GameObject: {fileID: 2125786285293829329}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f134b859b2acc54d95c5cdac4348075, type: 3}
m_Script: {fileID: 11500000, guid: 65dde41d869e66e4d87103c43970a518, type: 3}
defaultSpawnIndex: 0
playerPrefab: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
_defaultSpawnIndex: 0
_playerPrefab: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
inputReader: {fileID: 0}
gameplayCamera: {fileID: 0}
spawnLocations:
- {fileID: 2125786286893897154}
onPlayerSpawnEvent:
m_PersistentCalls:
m_Calls: []
_inputReader: {fileID: 0}
_gameplayCamera: {fileID: 0}
_spawnLocations: []
--- !u!1 &2125786286893897213
GameObject:
m_ObjectHideFlags: 0

357
UOP1_Project/Assets/Scenes/CharController.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &135922103
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 135922105}
- component: {fileID: 135922104}
- component: {fileID: 135922106}
m_Layer: 0
m_Name: CM vcam1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!114 &135922104
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 135922103}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 45e653bab7fb20e499bda25e1b646fea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ExcludedPropertiesInInspector:
- m_Script
m_LockStageInInspector:
m_StreamingVersion: 20170927
m_Priority: 10
m_StandbyUpdate: 2
m_LookAt: {fileID: 1961901426}
m_Follow: {fileID: 1961901426}
m_Lens:
FieldOfView: 60
OrthographicSize: 5
NearClipPlane: 0.3
FarClipPlane: 1000
Dutch: 0
LensShift: {x: 0, y: 0}
m_Transitions:
m_BlendHint: 0
m_InheritPosition: 0
m_OnCameraLive:
m_PersistentCalls:
m_Calls: []
m_LegacyBlendHint: 0
m_ComponentOwner: {fileID: 2020721999}
--- !u!4 &135922105
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 135922103}
m_LocalRotation: {x: 0.24395259, y: 0, z: 0, w: 0.9697872}
m_LocalPosition: {x: 0.62, y: 5.737, z: -25.886}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2020721999}
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &135922106
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 135922103}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e501d18bb52cf8c40b1853ca4904654f, type: 3}
m_Name:
m_EditorClassIdentifier:
m_CollideAgainst:
serializedVersion: 2
m_Bits: 1
m_IgnoreTag:
m_TransparentLayers:
serializedVersion: 2
m_Bits: 0
m_MinimumDistanceFromTarget: 0.1
m_AvoidObstacles: 1
m_DistanceLimit: 0
m_MinimumOcclusionTime: 0
m_CameraRadius: 0.1
m_Strategy: 1
m_MaximumEffort: 4
m_SmoothingTime: 0
m_Damping: 0
m_DampingWhenOccluded: 0
m_OptimalTargetDistance: 0
--- !u!1 &233317031
GameObject:
m_ObjectHideFlags: 3

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_Name:
m_EditorClassIdentifier:
inputReader: {fileID: 1724036687}
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: 2
m_RootOrder: 3
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: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1069947040
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

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!1001 &1809933188
PrefabInstance:

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

m_CameraActivatedEvent:
m_PersistentCalls:
m_Calls: []
--- !u!4 &1961901426 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 3341179906418240731, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
m_PrefabInstance: {fileID: 3341179907149091243}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2018663598
GameObject:
m_ObjectHideFlags: 3

m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2020721998
GameObject:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2020721999}
- component: {fileID: 2020722002}
- component: {fileID: 2020722001}
- component: {fileID: 2020722000}
m_Layer: 0
m_Name: cm
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2020721999
Transform:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020721998}
m_LocalRotation: {x: -0.24286506, y: 0.42750385, z: -0.12038752, w: 0.86241746}
m_LocalPosition: {x: -0.99633694, y: 0.6658721, z: 9.884593}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 135922105}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2020722000
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020721998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e8b78ac948f05a46a6d8339a503172b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2020722001
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020721998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa7155796051b734daa718462081dc5f, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BindingMode: 4
m_FollowOffset: {x: 0, y: 5.43, z: -10.11}
m_XDamping: 1
m_YDamping: 1
m_ZDamping: 1
m_AngularDampingMode: 0
m_PitchDamping: 0
m_YawDamping: 0
m_RollDamping: 0
m_AngularDamping: 0
--- !u!114 &2020722002
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2020721998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2049112419
GameObject:
m_ObjectHideFlags: 3

m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &2370768318719443585
--- !u!1001 &2104596401
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: _spawnLocations.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: inputReader
value:
objectReference: {fileID: 1724036687}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: gameplayCamera
value:
objectReference: {fileID: 1961065790}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: spawnLocations.Array.data[0]
value:
objectReference: {fileID: 2104596402}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _inputReader
value:
objectReference: {fileID: 1724036687}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _gameplayCamera
value:
objectReference: {fileID: 1961065790}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _spawnLocations.Array.data[0]
value:
objectReference: {fileID: 2104596402}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _cameraManager
value:
objectReference: {fileID: 526256410}
- 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: 15
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!4 &2104596402 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2125786286893897154, guid: e978d53d440e0814086759404585ac32,
type: 3}
m_PrefabInstance: {fileID: 2104596401}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2370768318719443585
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2

- target: {fileID: 211818859182309264, guid: 0fa393e1e37bc9e4e829c25a9452bcd3,
type: 3}
propertyPath: inputReader
value:
objectReference: {fileID: 1724036687}
- 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: 29
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

10
UOP1_Project/Assets/Scripts/CameraManager.cs


public class CameraManager : MonoBehaviour
{
public InputReader inputReader;
public Camera mainCamera;
public void SetupProtagonistVirtualCamera(Transform target)
{
freeLookVCam.Follow = target;
freeLookVCam.LookAt = target;
}
//...
//Removes all listeners to the events coming from the InputReader script
//...
}
private void OnCameraMove(Vector2 cameraMovement)

128
UOP1_Project/Assets/Scripts/SpawnSystem.cs


using UnityEngine;
using UnityEngine.Events;
[Serializable]
public class PlayerSpawnEvent : UnityEvent<Transform> { }
private static int requestedSpawnIndex = -1;
[Header("Settings")]
[SerializeField] private int defaultSpawnIndex = 0;
[Header("Project References")]
#pragma warning disable 649
[SerializeField] private Protagonist playerPrefab;
#pragma warning restore 649
[Header("Settings")]
[SerializeField] private int _defaultSpawnIndex = 0;
[Header("Scene References")]
[SerializeField] private InputReader inputReader;
[SerializeField] private Transform gameplayCamera;
[SerializeField] private Transform[] spawnLocations;
[Header("Project References")]
[SerializeField] private Protagonist _playerPrefab = null;
[Header("Events")]
public PlayerSpawnEvent onPlayerSpawnEvent;
[Header("Scene References")]
[SerializeField] private InputReader _inputReader;
[SerializeField] private CameraManager _cameraManager;
[SerializeField] private Transform[] _spawnLocations;
void Awake()
{
void Awake()
{
Spawn();
Spawn(_defaultSpawnIndex);
}
catch (Exception e)
{

void Reset()
{
AutoFill();
}
void Reset()
{
AutoFill();
}
[ContextMenu("Attempt Auto Fill")]
private void AutoFill()
{
if (inputReader == null)
inputReader = FindObjectOfType<InputReader>();
[ContextMenu("Attempt Auto Fill")]
private void AutoFill()
{
if (_inputReader == null)
_inputReader = FindObjectOfType<InputReader>();
if (gameplayCamera == null)
gameplayCamera = GameObject.FindGameObjectWithTag("MainCamera")?.transform;
if(_cameraManager == null)
_cameraManager = FindObjectOfType<CameraManager>();
if (spawnLocations == null || spawnLocations.Length == 0)
spawnLocations = transform.GetComponentsInChildren<Transform>(true)
.Where(t => t != this.transform)
.ToArray();
}
if (_spawnLocations == null || _spawnLocations.Length == 0)
_spawnLocations = transform.GetComponentsInChildren<Transform>(true)
.Where(t => t != this.transform)
.ToArray();
}
private void Spawn()
{
int spawnIndex = requestedSpawnIndex < 0 ? defaultSpawnIndex : requestedSpawnIndex;
var spawnLocation = GetSpawnLocation(spawnIndex, spawnLocations);
var playerInstance = InstantiatePlayer(playerPrefab, spawnLocation, inputReader, gameplayCamera);
requestedSpawnIndex = -1;
private void Spawn(int spawnIndex)
{
Transform spawnLocation = GetSpawnLocation(spawnIndex, _spawnLocations);
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, spawnLocation, _inputReader, _cameraManager);
}
onPlayerSpawnEvent.Invoke(playerInstance.transform);
}
private Transform GetSpawnLocation(int index, Transform[] spawnLocations)
{
if (spawnLocations == null || spawnLocations.Length == 0)
throw new Exception("No spawn locations set.");
private static 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];
}
index = Mathf.Clamp(index, 0, spawnLocations.Length - 1);
return spawnLocations[index];
}
private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation, InputReader inputReader, CameraManager _cameraManager)
{
if (playerPrefab == null)
throw new Exception("Player Prefab can't be null.");
private static Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation, InputReader inputReader, Transform gameplayCamera)
{
if (playerPrefab == null)
throw new Exception("Player Prefab can't be null.");
bool originalState = playerPrefab.enabled;
// Prevents playerInstance's Protagonist.OnEnable from running now
playerPrefab.enabled = false;
Protagonist playerInstance = Instantiate(playerPrefab, spawnLocation.position, spawnLocation.rotation);
playerPrefab.enabled = originalState;
bool originalState = playerPrefab.enabled;
// Prevents playerInstance's Protagonist.OnEnable from running before we set the inputReader and gameplayCamera references
playerPrefab.enabled = false;
var playerInstance = Instantiate(playerPrefab, spawnLocation.position, spawnLocation.rotation);
playerPrefab.enabled = originalState;
playerInstance.inputReader = inputReader;
playerInstance.gameplayCamera = _cameraManager.mainCamera.transform;
// Since the prefab's script was disabled it need to be enabled here
playerInstance.enabled = true;
playerInstance.inputReader = inputReader;
playerInstance.gameplayCamera = gameplayCamera;
// Since the prefab's script was disabled it need to be enabled here
playerInstance.enabled = true;
return playerInstance;
}
//Feed the player to the CameraManager
_cameraManager.SetupProtagonistVirtualCamera(playerInstance.transform);
public static void SetSpawnIndex(int spawnIndex)
{
// Prevent setting negative numbers from external sources
requestedSpawnIndex = Mathf.Max(spawnIndex, 0);
}
return playerInstance;
}
}

5
UOP1_Project/Packages/packages-lock.json


"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.14",
"version": "1.1.16",
"depth": 1,
"source": "registry",
"dependencies": {

"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0"
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0"
}
},
"com.unity.modules.ai": {

2
UOP1_Project/ProjectSettings/QualitySettings.asset


skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
antiAliasing: 2
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1

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


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

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:
正在加载...
取消
保存