浏览代码

Allow multiple entry/exit points in Locations (#284)

* added support for multiple entry/exit points using PathSO

* + added entrance & exit in TestingGround scene going to the Beach scene

* + LocationExit: renamed a private method

* Added spawn location tag

* Added tag to entrances in different locations

* Find entrances with tag before spawning

* Added array initialization

* Made entrance a prefab

Co-authored-by: Amel Negra <amel.negra@unity3d.com>
/devlogs-3-input
GitHub 4 年前
当前提交
fb323a77
共有 23 个文件被更改,包括 815 次插入52 次删除
  1. 1
      UOP1_Project/Assets/Prefabs/GameplayEssentials/SpawnSystem.prefab
  2. 227
      UOP1_Project/Assets/Scenes/Locations/Beach.unity
  3. 153
      UOP1_Project/Assets/Scenes/Locations/Forest.unity
  4. 246
      UOP1_Project/Assets/Scenes/TestingGround.unity
  5. 8
      UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs
  6. 23
      UOP1_Project/Assets/Scripts/SpawnSystem.cs
  7. 1
      UOP1_Project/ProjectSettings/TagManager.asset
  8. 46
      UOP1_Project/Assets/Prefabs/GameplayEssentials/Entrance.prefab
  9. 7
      UOP1_Project/Assets/Prefabs/GameplayEssentials/Entrance.prefab.meta
  10. 17
      UOP1_Project/Assets/ScriptableObjects/RuntimeAnchors/PathTaken.asset
  11. 8
      UOP1_Project/Assets/ScriptableObjects/RuntimeAnchors/PathTaken.asset.meta
  12. 8
      UOP1_Project/Assets/ScriptableObjects/SceneData/Paths.meta
  13. 24
      UOP1_Project/Assets/Scripts/RuntimeAnchors/PathAnchor.cs
  14. 11
      UOP1_Project/Assets/Scripts/RuntimeAnchors/PathAnchor.cs.meta
  15. 11
      UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs
  16. 11
      UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs.meta
  17. 10
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/PathSO.cs
  18. 11
      UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/PathSO.cs.meta
  19. 14
      UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndForest.asset
  20. 8
      UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndForest.asset.meta
  21. 14
      UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndTestingGround.asset
  22. 8
      UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndTestingGround.asset.meta

1
UOP1_Project/Assets/Prefabs/GameplayEssentials/SpawnSystem.prefab


type: 2}
_playerInstantiatedChannel: {fileID: 11400000, guid: 2723b3f59f7ede3498fe7e385d2bb6ee,
type: 2}
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_spawnLocations:
- {fileID: 2125786286893897154}
_OnSceneReady: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}

227
UOP1_Project/Assets/Scenes/Locations/Beach.unity
文件差异内容过多而无法显示
查看文件

153
UOP1_Project/Assets/Scenes/Locations/Forest.unity


objectReference: {fileID: 0}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _spawnLocations.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
- target: {fileID: 2125786285293829334, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: _spawnLocations.Array.data[1]
value:
objectReference: {fileID: 0}
- target: {fileID: 2125786285293829335, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: m_LocalPosition.x

type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2125786286893897213, guid: e978d53d440e0814086759404585ac32,
type: 3}
propertyPath: m_TagString
value: SpawnLocation
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e978d53d440e0814086759404585ac32, type: 3}

_locationsToLoad:
- {fileID: 11400000, guid: 2f386bbc670c05145834a0f9c7d55798, type: 2}
_showLoadScreen: 0
_pathTaken: {fileID: 11400000, guid: a9ec09853cba047a8a58f5881053cfc6, type: 2}
_exitPath: {fileID: 11400000, guid: 050fcf2d8a1044670b51fc2358167588, type: 2}
_locationExitLoadChannel: {fileID: 11400000, guid: 00e3063edc5902e40832ea618644c597,
type: 2}
--- !u!65 &1406036542

type: 3}
m_PrefabInstance: {fileID: 1526974243}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1596812572
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5540501665159811849, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_Name
value: EntranceFromBeach
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalPosition.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalPosition.z
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalRotation.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_RootOrder
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 5540501665159811850, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3b5498e27a52ce243b2ce35ba305d864, type: 3}
--- !u!1 &1596812573 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5540501665159811849, guid: 3b5498e27a52ce243b2ce35ba305d864,
type: 3}
m_PrefabInstance: {fileID: 1596812572}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1596812574
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1596812573}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7b70693d4d664e7bb07286b6d0d981d, type: 3}
m_Name:
m_EditorClassIdentifier:
_entrancePath: {fileID: 11400000, guid: 050fcf2d8a1044670b51fc2358167588, type: 2}
--- !u!1001 &1685989698
PrefabInstance:
m_ObjectHideFlags: 0

- target: {fileID: 1657732992883833910, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.03563515
value: 0.03581318
value: -0.009175836
value: -0.008454343
value: 0.24919106
value: 0.22959732
objectReference: {fileID: 0}
- target: {fileID: 1657732992883833910, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.97258985
value: 0.035795752
value: 0.03581318
value: -0.0085278535
value: -0.008454343
value: 0.23159355
value: 0.22959732
objectReference: {fileID: 0}
- target: {fileID: 2808035858438402709, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.97258985
value: 0.2295973
value: 0.22959732
value: 0.03581321
value: 0.03581318
objectReference: {fileID: 0}
- target: {fileID: 2955398947125553842, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

- target: {fileID: 2955398947125553842, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.z
value: -0.00845435
value: -0.008454343
objectReference: {fileID: 0}
- target: {fileID: 2955398947125553842, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

- target: {fileID: 8745341641394998850, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalPosition.x
value: -0.73545265
value: -0.88254315
value: -9.9729185
value: -11.967503
value: 0.1
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 8745341642014614481, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

- target: {fileID: 8745341642014614482, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.x
value: 0.24919108
value: 0.22959733
value: 0.03563516
value: 0.03581318
value: -0.009175838
value: -0.008454344
value: 0.967755
value: 0.97258985
value: -0.73545265
value: -0.88254315
value: 6
value: 7
value: -9.9729185
value: -11.967503
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 45632f0a227c860489bcba0eb1f4ec3e, type: 3}

246
UOP1_Project/Assets/Scenes/TestingGround.unity
文件差异内容过多而无法显示
查看文件

8
UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs


[Header("Loading settings")]
[SerializeField] private GameSceneSO[] _locationsToLoad = default;
[SerializeField] private bool _showLoadScreen = default;
[SerializeField] private PathAnchor _pathTaken = default;
[SerializeField] private PathSO _exitPath = default;
[Header("Broadcasting on")]
[SerializeField] private LoadEventChannelSO _locationExitLoadChannel = default;

if (other.CompareTag("Player"))
{
UpdatePathTaken();
}
private void UpdatePathTaken() {
if (_pathTaken != null)
_pathTaken.Path = _exitPath;
}
}

23
UOP1_Project/Assets/Scripts/SpawnSystem.cs


[SerializeField] private Protagonist _playerPrefab = default;
[SerializeField] private TransformAnchor _playerTransformAnchor = default;
[SerializeField] private TransformEventChannelSO _playerInstantiatedChannel = default;
[SerializeField] private PathAnchor _pathTaken = default;
[SerializeField] private Transform[] _spawnLocations;
private Transform[] _spawnLocations;
[Header("Scene Ready Event")]
[SerializeField] private VoidEventChannelSO _OnSceneReady = default; //Raised when the scene is loaded and set active

private void SpawnPlayer()
{
Spawn(_defaultSpawnIndex);
GameObject[] spawnLocationsGO = GameObject.FindGameObjectsWithTag("SpawnLocation");
_spawnLocations = new Transform[spawnLocationsGO.Length];
for (int i = 0; i < spawnLocationsGO.Length; ++i)
{
_spawnLocations[i] = spawnLocationsGO[i].transform;
}
Spawn(FindSpawnIndex(_pathTaken?.Path ?? null));
}
void Reset()

index = Mathf.Clamp(index, 0, spawnLocations.Length - 1);
return spawnLocations[index];
}
private int FindSpawnIndex(PathSO pathTaken)
{
if (pathTaken == null)
return _defaultSpawnIndex;
int index = Array.FindIndex(_spawnLocations, element =>
element?.GetComponent<LocationEntrance>()?.EntrancePath == pathTaken
);
return (index < 0) ? _defaultSpawnIndex : index;
}
private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation)

1
UOP1_Project/ProjectSettings/TagManager.asset


- Pickable
- CookingPot
- NPC
- SpawnLocation
layers:
- Default
- TransparentFX

46
UOP1_Project/Assets/Prefabs/GameplayEssentials/Entrance.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5540501665159811849
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5540501665159811850}
- component: {fileID: 5540501665159811851}
m_Layer: 0
m_Name: Entrance
m_TagString: SpawnLocation
m_Icon: {fileID: 3936346786652291628, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5540501665159811850
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5540501665159811849}
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: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5540501665159811851
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5540501665159811849}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7b70693d4d664e7bb07286b6d0d981d, type: 3}
m_Name:
m_EditorClassIdentifier:
_entrancePath: {fileID: 0}

7
UOP1_Project/Assets/Prefabs/GameplayEssentials/Entrance.prefab.meta


fileFormatVersion: 2
guid: 3b5498e27a52ce243b2ce35ba305d864
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

17
UOP1_Project/Assets/ScriptableObjects/RuntimeAnchors/PathTaken.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
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: a3f6d258ef1d442128bb2af4b61592d8, type: 3}
m_Name: PathTaken
m_EditorClassIdentifier:
description: Contains the Path taken by the player, which is set by the LocationExit.
It can be used by the SpawnSystem to determine the LocationEntrance.
isSet: 0

8
UOP1_Project/Assets/ScriptableObjects/RuntimeAnchors/PathTaken.asset.meta


fileFormatVersion: 2
guid: a9ec09853cba047a8a58f5881053cfc6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/ScriptableObjects/SceneData/Paths.meta


fileFormatVersion: 2
guid: e4428dec107cd4b3999c0c113b2813a4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

24
UOP1_Project/Assets/Scripts/RuntimeAnchors/PathAnchor.cs


using UnityEngine;
[CreateAssetMenu(fileName = "New PathAnchor", menuName = "Runtime Anchors/Path")]
public class PathAnchor : RuntimeAnchorBase
{
[HideInInspector] public bool isSet = false; // Any script can check if the transform is null before using it, by just checking this bool
private PathSO _Path;
public PathSO Path
{
get { return _Path; }
set
{
_Path = value;
isSet = _Path != null;
}
}
public void OnDisable()
{
_Path = null;
isSet = false;
}
}

11
UOP1_Project/Assets/Scripts/RuntimeAnchors/PathAnchor.cs.meta


fileFormatVersion: 2
guid: a3f6d258ef1d442128bb2af4b61592d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LocationEntrance : MonoBehaviour
{
[Header("Asset References")]
[SerializeField] private PathSO _entrancePath;
public PathSO EntrancePath => _entrancePath;
}

11
UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs.meta


fileFormatVersion: 2
guid: f7b70693d4d664e7bb07286b6d0d981d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/PathSO.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This class contains Settings specific to Paths, which are used to determine the connecting entrances and exits between Locations
/// </summary>
[CreateAssetMenu(fileName = "BetweenLocation1AndLocation2", menuName = "Scene Data/Path")]
public class PathSO : ScriptableObject { }

11
UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/PathSO.cs.meta


fileFormatVersion: 2
guid: fedb6eda6181441209c70ac00d6e7cc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndForest.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
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: fedb6eda6181441209c70ac00d6e7cc8, type: 3}
m_Name: BetweenBeachAndForest
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndForest.asset.meta


fileFormatVersion: 2
guid: 050fcf2d8a1044670b51fc2358167588
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

14
UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndTestingGround.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
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: fedb6eda6181441209c70ac00d6e7cc8, type: 3}
m_Name: BetweenBeachAndTestingGround
m_EditorClassIdentifier:

8
UOP1_Project/Assets/ScriptableObjects/SceneData/Paths/BetweenBeachAndTestingGround.asset.meta


fileFormatVersion: 2
guid: 02c13d612a86149a8b354b877b9f261f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存