浏览代码

Level Streaming Manager Update : Now is a manager

/main
Thomas ICHÉ 6 年前
当前提交
84f214a0
共有 12 个文件被更改,包括 767 次插入24 次删除
  1. 3
      Runtime/Actions/StreamingLevelAction.cs
  2. 38
      Runtime/LevelStreaming/LevelStreamingManager.cs
  3. 8
      Resources.meta
  4. 8
      Runtime/Managers.meta
  5. 607
      Resources/Default_LevelStreamingManager.prefab
  6. 7
      Resources/Default_LevelStreamingManager.prefab.meta
  7. 78
      Runtime/Managers/Manager.cs
  8. 11
      Runtime/Managers/Manager.cs.meta
  9. 20
      Runtime/Managers/ManagerDefaultPrefabAttribute.cs
  10. 11
      Runtime/Managers/ManagerDefaultPrefabAttribute.cs.meta

3
Runtime/Actions/StreamingLevelAction.cs


using UnityEngine.Events;
using GameplayIngredients;
using GameplayIngredients.LevelStreaming;
namespace GameplayIngredients.Actions

public override void Execute()
{
LevelStreamingManager.instance.LoadScenes(Action, Scenes, SceneToActivate, ShowUI, OnLoadComplete);
Manager.Get<LevelStreamingManager>().LoadScenes(Action, Scenes, SceneToActivate, ShowUI, OnLoadComplete);
}
}
}

38
Runtime/LevelStreaming/LevelStreamingManager.cs


namespace GameplayIngredients.LevelStreaming
{
public class LevelStreamingManager : MonoBehaviour
[ManagerDefaultPrefab("LevelStreamingManager")]
public class LevelStreamingManager : Manager
public static LevelStreamingManager instance { get { return s_Instance; } }
private static LevelStreamingManager s_Instance;
public enum StreamingAction
{
Load,

public Text LoadingText;
public Text PercentageText;
[Header("Behavior")]
[Min(0.0f)]
public float DelayBeforeLoad = 0.0f;
[Min(0.0f)]
public float DelayAfterLoad = 0.0f;
[Header("Debug")]
public Text DebugText;
public bool EnableDebug = false;

void OnEnable()
{
//if(!Console.HasCommand("STREAMING")) Console.AddCommand(new LevelStreamingCommand());
if (s_Instance != null)
throw new InvalidOperationException("LevelStreamingManager Already Exists");
else
s_Instance = this;
}
void OnDisable()
{
if (s_Instance == this)
s_Instance = null;
}
public void LoadScenes(StreamingAction action, string[] scenes, string sceneToActivate, bool showUI, UnityEvent onLoadComplete)
{

LogDebugInformation("START LOAD/UNLOAD FOR LEVELS...");
SetProgressBar(0.0f, true);
if(DelayBeforeLoad >= 0.0f)
yield return new WaitForSeconds(DelayBeforeLoad);
switch (action)
{
case StreamingAction.Load:

SceneManager.SetActiveScene(newActive);
yield return new WaitForEndOfFrame();
}
if(DelayAfterLoad >= 0.0f)
yield return new WaitForSeconds(DelayAfterLoad);
if (onLoadComplete != null)
onLoadComplete.Invoke();

// Update UI
PercentageText.text = ((int)(m_CurrentPercentage * 100)) + "%";
Vector2 size = ProgressBar.GetComponent<RectTransform>().sizeDelta;
size.x = m_CurrentPercentage * ProgressBarContainer.GetComponent<RectTransform>().sizeDelta.x;
ProgressBar.GetComponent<RectTransform>().sizeDelta = size;
ProgressBar.GetComponent<RectTransform>().localScale = new Vector2(m_CurrentPercentage, 1.0f);
//Debug
if (EnableDebug)

8
Resources.meta


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

8
Runtime/Managers.meta


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

607
Resources/Default_LevelStreamingManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4237660105901699951
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660105901699950}
m_Layer: 5
m_Name: LoadingUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660105901699950
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660105901699951}
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: 4237660106701817725}
- {fileID: 4237660106123981089}
- {fileID: 4237660106447583619}
m_Father: {fileID: 4237660107855997384}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 32, y: 32}
m_SizeDelta: {x: 480, y: 32}
m_Pivot: {x: 0, y: 0}
--- !u!1 &4237660106043442134
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660106043442133}
- component: {fileID: 4237660106043442131}
- component: {fileID: 4237660106043442132}
m_Layer: 5
m_Name: DebugText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660106043442133
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106043442134}
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: 4237660107855997384}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 32, y: -32}
m_SizeDelta: {x: 320, y: -128}
m_Pivot: {x: 0, y: 1}
--- !u!222 &4237660106043442131
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106043442134}
m_CullTransparentMesh: 0
--- !u!114 &4237660106043442132
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106043442134}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text:
--- !u!1 &4237660106123981090
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660106123981089}
- component: {fileID: 4237660106123981119}
- component: {fileID: 4237660106123981088}
m_Layer: 5
m_Name: Percentage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660106123981089
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106123981090}
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: 4237660105901699950}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 80, y: 16}
m_Pivot: {x: 1, y: 1}
--- !u!222 &4237660106123981119
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106123981090}
m_CullTransparentMesh: 0
--- !u!114 &4237660106123981088
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106123981090}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 2
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 100%
--- !u!1 &4237660106447583620
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660106447583619}
- component: {fileID: 4237660106447583617}
- component: {fileID: 4237660106447583618}
m_Layer: 5
m_Name: ProgressBarBG
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660106447583619
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106447583620}
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: 4237660107457405504}
m_Father: {fileID: 4237660105901699950}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 8}
m_Pivot: {x: 0.5, y: 0}
--- !u!222 &4237660106447583617
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106447583620}
m_CullTransparentMesh: 0
--- !u!114 &4237660106447583618
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106447583620}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.33962262, g: 0.33962262, b: 0.33962262, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!1 &4237660106662749796
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660106662749793}
- component: {fileID: 4237660106662749794}
- component: {fileID: 4237660106662749795}
- component: {fileID: 4237660106662749792}
m_Layer: 5
m_Name: Default_LevelStreamingManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660106662749793
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106662749796}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 4237660107855997384}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!223 &4237660106662749794
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106662749796}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 1
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 32767
m_TargetDisplay: 0
--- !u!114 &4237660106662749795
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106662749796}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!114 &4237660106662749792
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106662749796}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d9f78c0b7259f604da294b52e1208e0f, type: 3}
m_Name:
m_EditorClassIdentifier:
LoadingRoot: {fileID: 4237660107855997385}
ProgressBar: {fileID: 4237660107457405505}
ProgressBarContainer: {fileID: 4237660106447583620}
LoadingText: {fileID: 4237660106701817724}
PercentageText: {fileID: 4237660106123981088}
DelayBeforeLoad: 1
DelayAfterLoad: 1
DebugText: {fileID: 4237660106043442132}
EnableDebug: 0
--- !u!1 &4237660106701817726
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660106701817725}
- component: {fileID: 4237660106701817723}
- component: {fileID: 4237660106701817724}
m_Layer: 5
m_Name: Loading
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660106701817725
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106701817726}
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: 4237660105901699950}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 96, y: 16}
m_Pivot: {x: 0, y: 1}
--- !u!222 &4237660106701817723
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106701817726}
m_CullTransparentMesh: 0
--- !u!114 &4237660106701817724
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660106701817726}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Loading...
'
--- !u!1 &4237660107457405505
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660107457405504}
- component: {fileID: 4237660107457405534}
- component: {fileID: 4237660107457405535}
m_Layer: 5
m_Name: ProgressBar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4237660107457405504
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107457405505}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4237660106447583619}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: 0, y: -4}
m_SizeDelta: {x: 40, y: 8}
m_Pivot: {x: 0, y: 0}
--- !u!222 &4237660107457405534
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107457405505}
m_CullTransparentMesh: 0
--- !u!114 &4237660107457405535
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107457405505}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!1 &4237660107855997385
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4237660107855997384}
- component: {fileID: 4237660107855997382}
- component: {fileID: 4237660107855997383}
m_Layer: 5
m_Name: LoadingRoot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &4237660107855997384
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107855997385}
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: 4237660105901699950}
- {fileID: 4237660106043442133}
m_Father: {fileID: 4237660106662749793}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4237660107855997382
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107855997385}
m_CullTransparentMesh: 0
--- !u!114 &4237660107855997383
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4237660107855997385}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0

7
Resources/Default_LevelStreamingManager.prefab.meta


fileFormatVersion: 2
guid: 38e03acd46f707f41bea470a5525d3ee
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

78
Runtime/Managers/Manager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Reflection;
namespace GameplayIngredients
{
public abstract class Manager : MonoBehaviour
{
private static Dictionary<Type, Manager> s_Managers = new Dictionary<Type, Manager>();
public static T Get<T>() where T: Manager
{
if(s_Managers.ContainsKey(typeof(T)))
return (T)s_Managers[typeof(T)];
else
return null;
}
static readonly Type[] kAllManagerTypes = GetAllManagerTypes();
[RuntimeInitializeOnLoadMethod]
static void AutoCreateAll()
{
foreach(var type in kAllManagerTypes)
{
var attrib =type.GetCustomAttribute<ManagerDefaultPrefabAttribute>();
GameObject gameObject;
if(attrib != null)
{
var prefab = Resources.Load<GameObject>(attrib.prefab);
if(prefab == null) // Try loading the "Default_" prefixed version of the prefab
{
prefab = Resources.Load<GameObject>("Default_"+attrib.prefab);
}
if(prefab != null)
{
gameObject = GameObject.Instantiate(prefab);
}
else
{
Debug.LogError($"Could not instantiate default prefab for {type.ToString()} : No prefab '{attrib.prefab}' found in resources folders. Ignoring...");
continue;
}
}
else
{
gameObject = new GameObject();
gameObject.AddComponent(type);
}
gameObject.name = type.Name;
GameObject.DontDestroyOnLoad(gameObject);
var comp = (Manager)gameObject.GetComponent(type);
s_Managers.Add(type,comp);
}
}
static Type[] GetAllManagerTypes()
{
List<Type> types = new List<Type>();
foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach(Type t in assembly.GetTypes())
{
if(typeof(Manager).IsAssignableFrom(t) && !t.IsAbstract)
{
types.Add(t);
}
}
}
return types.ToArray();
}
}
}

11
Runtime/Managers/Manager.cs.meta


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

20
Runtime/Managers/ManagerDefaultPrefabAttribute.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace GameplayIngredients
{
[AttributeUsage(AttributeTargets.Class)]
public class ManagerDefaultPrefabAttribute : Attribute
{
public string prefab { get => m_Prefab; }
string m_Prefab;
public ManagerDefaultPrefabAttribute(string prefabName)
{
m_Prefab = prefabName;
}
}
}

11
Runtime/Managers/ManagerDefaultPrefabAttribute.cs.meta


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