4using NaughtyAttributes;
6using System.Collections;
7using System.Collections.Generic;
9using System.Threading.Tasks;
23 public GameObject
Load(
byte[] data,
string filename, GameObject wrapper =
null,
bool singleModel =
false,
bool global =
false)
30 var gltf =
new GltfImport();
31 var loadingSuccess = AsyncHelpersBuild.RunSync(() => gltf.LoadGltfBinary(data));
60 void ComponentAdder(GameObject go)
62 if (go.GetComponent<MeshFilter>() && !go.GetComponent<Collider>())
64 var coll = go.AddComponent<MeshCollider>();
67 if (go.GetComponent<MeshRenderer>())
69 var mr = go.GetComponent<MeshRenderer>();
70 foreach (var material
in mr.materials)
72 if (material.mainTexture ==
null)
74 material.mainTexture = Resources.Load<Texture>(
"2k_white");
82 for (
int i = 0; i < go.transform.childCount; i++)
84 ComponentAdder(go.transform.GetChild(i).gameObject);
91 Load(System.IO.File.ReadAllBytes(
@"D:\GIT\UNITY\vrtanoda\VRtanoda tools\Tooltable\tooltable.glb"),
"tooltable.glb");
96public static class AsyncHelpersBuild
98 private class ExclusiveSynchronizationContext : SynchronizationContext
102 private readonly AutoResetEvent workItemsWaiting =
new AutoResetEvent(initialState:
false);
104 private readonly Queue<Tuple<SendOrPostCallback, object>> items =
new Queue<Tuple<SendOrPostCallback, object>>();
106 public Exception InnerException
112 public override void Send(SendOrPostCallback d,
object state)
114 throw new NotSupportedException(
"We cannot send to our same thread");
117 public override void Post(SendOrPostCallback d,
object state)
121 items.Enqueue(Tuple.Create(d, state));
124 workItemsWaiting.Set();
127 public void EndMessageLoop()
135 public void BeginMessageLoop()
139 Tuple<SendOrPostCallback, object> tuple =
null;
144 tuple = items.Dequeue();
150 tuple.Item1(tuple.Item2);
151 if (InnerException !=
null)
153 throw new AggregateException(
"AsyncHelpers.Run method threw an exception.", InnerException);
158 workItemsWaiting.WaitOne();
163 public override SynchronizationContext CreateCopy()
169 public static void RunSync(Func<Task> task)
171 SynchronizationContext current = SynchronizationContext.Current;
172 ExclusiveSynchronizationContext synch =
new ExclusiveSynchronizationContext();
173 SynchronizationContext.SetSynchronizationContext(synch);
174 synch.Post(async delegate
183 synch.InnerException = e;
188 synch.EndMessageLoop();
191 synch.BeginMessageLoop();
192 SynchronizationContext.SetSynchronizationContext(current);
195 public static T RunSync<T>(Func<Task<T>> task)
197 SynchronizationContext current = SynchronizationContext.Current;
198 ExclusiveSynchronizationContext synch =
new ExclusiveSynchronizationContext();
199 SynchronizationContext.SetSynchronizationContext(synch);
201 synch.Post(async delegate
210 synch.InnerException = e;
215 synch.EndMessageLoop();
218 synch.BeginMessageLoop();
219 SynchronizationContext.SetSynchronizationContext(current);
UnityEngine.UI.Button Button
void AddGameObject(GameObject gobject, LoadPanel panel=LoadPanel.None, string filePath="", bool global=false)
static pb_PrefabBrowser instance
static GLTFastLoader instance
GameObject LastLoadedGameObject
GameObject Load(byte[] data, string filename, GameObject wrapper=null, bool singleModel=false, bool global=false)