6
6
using System . IO ;
7
7
using System . Linq ;
8
8
using System . Reflection ;
9
+ using Tobey . UnityAudio . ExtensionMethods ;
10
+ using Tobey . UnityAudio . Utilities ;
9
11
using UnityEngine ;
10
12
11
13
namespace Tobey . UnityAudio ;
@@ -110,7 +112,6 @@ void logFailure(string missingMemberName, string missingMemberType) =>
110
112
}
111
113
112
114
Logger . LogMessage ( "Attempting to determine the runtime state of Unity Audio..." ) ;
113
- Logger . LogInfo ( "You may see warnings from AccessTools about being unable to find methods or types etc. during this operation." ) ;
114
115
115
116
var path = Path . GetFullPath ( Path . Combine ( Directory . GetParent ( Assembly . GetExecutingAssembly ( ) . Location ) . FullName , audioFilePath . Value ) ) ;
116
117
if ( ! File . Exists ( path ) )
@@ -120,45 +121,48 @@ void logFailure(string missingMemberName, string missingMemberType) =>
120
121
121
122
// in newer versions of Unity, UnityWebRequest.GetAudioClip is deprecated in favour of UnityWebRequestMultimedia.GetAudioClip,
122
123
// so use the newer method where available
123
- var unityWebRequestMultimedia = new [ ] { "UnityWebRequestMultimedia" , "UnityWebRequest" } . Select ( Traverse . CreateWithType ) . FirstOrDefault ( t => t . TypeExists ( ) ) ;
124
+ var unityWebRequestMultimedia = new [ ] { "UnityWebRequestMultimedia" , "UnityWebRequest" }
125
+ . Select ( TraverseHelper . CreateWithOptionalType )
126
+ . FirstOrDefault ( t => t . TypeExists ( ) ) ;
127
+
124
128
if ( unityWebRequestMultimedia is null )
125
129
{
126
130
logFailure ( "UnityEngine.Networking.UnityWebRequest" , "type" ) ;
127
131
yield break ;
128
132
}
129
133
130
134
// we need the type of UnityWebRequest on all versions, as this is the type that will be passed to DownloadHandlerAudioClip.GetContent
131
- var unityWebRequest = Traverse . CreateWithType ( "UnityWebRequest" ) ;
135
+ var unityWebRequest = TraverseHelper . CreateWithOptionalType ( "UnityWebRequest" ) ;
132
136
if ( ! unityWebRequest . TypeExists ( ) )
133
137
{
134
138
logFailure ( "UnityEngine.Networking.UnityWebRequest" , "type" ) ;
135
139
yield break ;
136
140
}
137
141
Type unityWebRequestType = unityWebRequest . GetValue < Type > ( ) ;
138
142
139
- var audioType = Traverse . CreateWithType ( "AudioType" ) ;
143
+ var audioType = TraverseHelper . CreateWithOptionalType ( "AudioType" ) ;
140
144
if ( ! audioType . TypeExists ( ) )
141
145
{
142
146
logFailure ( "UnityEngine.AudioType" , "type" ) ;
143
147
yield break ;
144
148
}
145
149
Type audioTypeType = audioType . GetValue < Type > ( ) ;
146
150
147
- var downloadHandlerAudioClip = Traverse . CreateWithType ( "DownloadHandlerAudioClip" ) ;
151
+ var downloadHandlerAudioClip = TraverseHelper . CreateWithOptionalType ( "DownloadHandlerAudioClip" ) ;
148
152
if ( ! downloadHandlerAudioClip . TypeExists ( ) )
149
153
{
150
154
logFailure ( "UnityEngine.Networking.DownloadHandlerAudioClip" , "type" ) ;
151
155
yield break ;
152
156
}
153
157
154
- var getContent = downloadHandlerAudioClip . Method ( "GetContent" , new [ ] { unityWebRequestType } ) ;
158
+ var getContent = downloadHandlerAudioClip . OptionalMethod ( "GetContent" , new [ ] { unityWebRequestType } ) ;
155
159
if ( ! getContent . MethodExists ( ) )
156
160
{
157
161
logFailure ( $ "{ downloadHandlerAudioClip } :GetContent", "static method" ) ;
158
162
yield break ;
159
163
}
160
164
161
- var getAudioClip = unityWebRequestMultimedia . Method ( "GetAudioClip" , new [ ] { typeof ( string ) , audioTypeType } ) ;
165
+ var getAudioClip = unityWebRequestMultimedia . OptionalMethod ( "GetAudioClip" , new [ ] { typeof ( string ) , audioTypeType } ) ;
162
166
if ( ! getAudioClip . MethodExists ( ) )
163
167
{
164
168
logFailure ( $ "{ unityWebRequestMultimedia } :GetAudioClip", "static method" ) ;
@@ -167,7 +171,7 @@ void logFailure(string missingMemberName, string missingMemberType) =>
167
171
168
172
using var disposableRequest = getAudioClip . GetValue < IDisposable > ( $ "file:///{ path } ", 20 ) ; // AudioType.WAV = 20
169
173
var request = Traverse . Create ( disposableRequest ) ;
170
- var sendWebRequest = new [ ] { "SendWebRequest" , "Send" } . Select ( name => request . Method ( name ) ) . FirstOrDefault ( m => m . MethodExists ( ) ) ;
174
+ var sendWebRequest = new [ ] { "SendWebRequest" , "Send" } . Select ( name => request . OptionalMethod ( name ) ) . FirstOrDefault ( m => m . MethodExists ( ) ) ;
171
175
if ( sendWebRequest is null )
172
176
{
173
177
logFailure ( $ "{ unityWebRequestMultimedia } :SendWebRequest", "instance method" ) ;
0 commit comments