-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathPHASESoundEventNodeGraph.cs
More file actions
123 lines (110 loc) · 3.78 KB
/
PHASESoundEventNodeGraph.cs
File metadata and controls
123 lines (110 loc) · 3.78 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Collections.Generic;
using UnityEngine;
using XNode;
namespace Apple.PHASE
{
/// <summary>
/// Class representing a graph of sound event nodes.
/// </summary>
/// <remarks> Use the Asset menu to create a new instance of this class. </remarks>
[CreateAssetMenu(menuName = "Apple/PHASE/SoundEvent", fileName = "NewSoundEvent")]
public class PHASESoundEventNodeGraph : NodeGraph
{
static List<PHASESoundEventNodeGraph> m_registeredSoundEvents = new List<PHASESoundEventNodeGraph>();
[System.NonSerialized]
private bool m_isRegistered = false;
// Root node of this sound event
[SerializeField] private PHASESoundEventNode m_rootNode = null;
/// <summary>
/// Register this sound event graph with the PHASE engine.
/// </summary>
public void Register()
{
m_rootNode = GetRootNode();
if (m_rootNode == null)
{
Debug.LogError($"No root node for PHASESoundEventNodeGraph: {name}.");
}
bool result = m_rootNode.Create();
if (result == false)
{
Debug.LogError($"Failed to register PHASE sound event root node {m_rootNode.name}.");
return;
}
// Create sound event asset
result = Helpers.PHASERegisterSoundEventAsset("SoundEvent_" + GetInstanceID().ToString(), m_rootNode.GetNodeId());
if (result == false)
{
Debug.LogError($"Failed to register PHASE sound event asset: {name}.");
}
else
{
m_registeredSoundEvents.Add(this);
m_isRegistered = true;
}
}
private PHASESoundEventNode GetRootNode()
{
for (var i = 0; i < nodes.Count; i++)
{
PHASESoundEventNode node = nodes[i] as PHASESoundEventNode;
NodePort nodePort = nodes[i].GetInputPort("ParentNode");
if (!nodePort.IsConnected)
{
return node;
}
}
return null;
}
protected override void OnDestroy()
{
Unregister();
m_registeredSoundEvents.Remove(this);
base.OnDestroy();
}
/// <summary>
/// Unregister this sound event graph from the PHASE engine.
/// </summary>
public void Unregister()
{
m_isRegistered = false;
Helpers.PHASEUnregisterSoundEventAsset(name);
m_rootNode.DestroyFromPHASE();
}
/// <summary>
/// Unregisters all sound event graphs from the PHASE engine.
/// </summary>
static public void UnregisterAll()
{
foreach (PHASESoundEventNodeGraph soundEvent in m_registeredSoundEvents)
{
soundEvent.Unregister();
}
m_registeredSoundEvents.Clear();
}
/// <summary>
/// Checks if this sound event graph is registered with the PHASE engine.
/// </summary>
/// <returns> Return true if it is registered, false otherwise. </returns>
public bool IsRegistered()
{
return m_isRegistered;
}
/// <summary>
/// Returns a <c>List</c> of all mixers associated with this sound event graph.
/// </summary>
/// <returns>A <c>List</c> of all mixers associated with this sound event graph.</returns>
public List<PHASEMixer> GetMixers()
{
GetRootNode();
if (m_rootNode != null)
{
return m_rootNode.GetMixers();
}
else
{
return null;
}
}
}
}