浏览代码

Adding events and listeners for scene loading

/main
Unknown 4 年前
当前提交
863a7673
共有 16 个文件被更改,包括 167 次插入1 次删除
  1. 2
      UOP1_Project/Assets/Scripts/GameEventListener.cs.meta
  2. 8
      UOP1_Project/Assets/Scriptable Objects/Events.meta
  3. 38
      UOP1_Project/Assets/Scripts/GameEventListener.cs
  4. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_Exit.asset
  5. 8
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_Exit.asset.meta
  6. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadMainMenu.asset
  7. 8
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadMainMenu.asset.meta
  8. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.asset
  9. 8
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.asset.meta
  10. 14
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.asset
  11. 8
      UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.asset.meta
  12. 21
      UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs
  13. 11
      UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs.meta
  14. 0
      /UOP1_Project/Assets/Scripts/GameEventListener.cs.meta

2
UOP1_Project/Assets/Scripts/GameEventListener.cs.meta


fileFormatVersion: 2
guid: 1672132dae377874db68251b10915ac3
guid: 8cb8658de1ad97b4eb747df35933650f
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
UOP1_Project/Assets/Scriptable Objects/Events.meta


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

38
UOP1_Project/Assets/Scripts/GameEventListener.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class GameEventListener : MonoBehaviour
{
public GameEvent Event;
public UnityEvent Response;
private void OnEnable()
{
//Check if the event exists to avoid errors
if (Event == null)
{
return;
}
Event.RegisterListener(this);
}
private void OnDisable()
{
if (Event == null)
{
return;
}
Event.UnregisterListener(this);
}
public void OnEventRaised()
{
if (Response == null)
{
return;
}
Response.Invoke();
}
}

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_Exit.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_Exit
m_EditorClassIdentifier:

8
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_Exit.asset.meta


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

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadMainMenu.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_LoadMainMenu
m_EditorClassIdentifier:

8
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadMainMenu.asset.meta


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

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_LoadNextLevel
m_EditorClassIdentifier:

8
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevel.asset.meta


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

14
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.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: 04ea2f19feb15654cb31bb60f7f50855, type: 3}
m_Name: GameEvent_LoadNextLevelWithProgress
m_EditorClassIdentifier:

8
UOP1_Project/Assets/Scriptable Objects/Events/GameEvent_LoadNextLevelWithProgress.asset.meta


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

21
UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs


using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class GameEvent : ScriptableObject
{
private List<GameEventListener> listeners =
new List<GameEventListener>();
public void Raise()
{
for (int i = listeners.Count - 1; i >= 0; i--)
listeners[i].OnEventRaised();
}
public void RegisterListener(GameEventListener listener)
{ listeners.Add(listener); }
public void UnregisterListener(GameEventListener listener)
{ listeners.Remove(listener); }
}

11
UOP1_Project/Assets/Scripts/Scriptable Objects/Events/GameEvent.cs.meta


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

/UOP1_Project/Assets/LoadingManager.cs.meta → /UOP1_Project/Assets/Scripts/GameEventListener.cs.meta

正在加载...
取消
保存