-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathScene.cs
More file actions
79 lines (67 loc) · 2.7 KB
/
Scene.cs
File metadata and controls
79 lines (67 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using UnityEngine;
using UniRx;
namespace uFrame.Kernel
{
/// <summary>
/// The scene class is used to define a scene as a class,
/// this MonoBehaviour should live on a gameobject that is at the root level of the scene it is defining.
/// When this type is loaded by unity, it will publish the SceneAwakeEvent. The SceneManagementService (part of the kernel) will
/// then find the scene loader associated with this scene and invoke its Load Co-Routine method.
/// </summary>
public class Scene : uFrameComponent, IScene
{
[SerializeField] private string _KernelScene;
/// <summary>
/// The kernel scene property is so that this scene can load the correct kernel if it hasn't been loaded yet.
/// </summary>
protected string KernelScene
{
get
{
if (string.IsNullOrEmpty(_KernelScene))
{
return DefaultKernelScene;
}
return _KernelScene;
}
}
/// <summary>
/// The default kernel scene is what is used if the "KernelScene" property is not set. This is really used by
/// the uFrame designer to remove the extra step of specifying the kernel scene each time a scene is created.
/// </summary>
public virtual string DefaultKernelScene { get; set; }
/// <summary>
/// The Name of this scene, this is set by the kernel so that it can reference back to it and destroy it when the
/// Unload Scene Command is fired.
/// </summary>
public string Name { get; set; }
/// <summary>
/// If this scene was loaded via a
/// </summary>
public ISceneSettings _SettingsObject { get; set; }
/// <summary>
/// In this class we override the start method so that we can trigger the kernel to load if its not already.
/// </summary>
/// <returns></returns>
protected override IEnumerator Start()
{
this.KernelLoading();
if (!uFrameKernel.IsKernelLoaded)
{
Name = Application.loadedLevelName;
yield return StartCoroutine(uFrameKernel.InstantiateSceneAsyncAdditively(KernelScene));
}
while (!uFrameKernel.IsKernelLoaded) yield return null;
this.KernelLoaded();
this.Publish(new SceneAwakeEvent() {Scene = this});
}
}
/// <summary>
/// This class is used internally by the Scene class and the kernel to trigger scene loaders load method.
/// </summary>
public class SceneAwakeEvent
{
public IScene Scene { get; set; }
}
}