//Load and setup model prefab private IEnumerator LoadPrefab(string modelfile) { bool done = false; DestroyImmediate(mesh); GameObject prefab = Resources.Load <GameObject>($"{modelsPath}{RacePath}{modelfile}_prefab"); mesh = Instantiate(prefab, gameObject.transform); yield return(null); M2Model m2 = GetComponentInChildren <M2Model>(); byte[] data = m2.data.bytes; byte[] skin = m2.skin.bytes; byte[] skel = m2.skel.bytes; loadBinaries = new Thread(() => { Model = m2.LoadModel(data, skin, skel); done = true; }); loadBinaries.Start(); yield return(null); activeGeosets = new List <int> { 0, 2301 }; while (loadBinaries.IsAlive) { yield return(null); } if (done) { LoadColors(); yield return(null); textures = new Texture2D[Model.Textures.Length]; if (Gender) { helper = new GilneanMale(Model, worgen); } else { helper = new GilneanFemale(Model, worgen); } yield return(null); time = new float[Model.TextureAnimations.Length]; frame = new int[Model.TextureAnimations.Length]; for (int i = 0; i < time.Length; i++) { time[i] = 0f; frame[i] = 0; yield return(null); } renderer = GetComponentInChildren <SkinnedMeshRenderer>(); animator = GetComponentInChildren <Animator>(); Change = true; Loaded = !loadBinaries.IsAlive; } gameObject.SetActive(false); }
//Load the model from assets public IEnumerator LoadModel(string collectionfile, CASCHandler casc) { UnloadModel(); bool done = false; converter = new System.Drawing.ImageConverter(); this.casc = casc; GameObject prefab = Resources.Load <GameObject>($"{Path}{collectionfile}"); mesh = Instantiate(prefab, gameObject.transform); yield return(null); M2Model m2 = GetComponentInChildren <M2Model>(); byte[] data = m2.data.bytes; byte[] skin = m2.skin.bytes; byte[] skel = m2.skel.bytes; loadBinaries = new Thread(() => { Model = m2.LoadModel(data, skin, skel); done = true; }); loadBinaries.Start(); yield return(null); ActiveGeosets = new List <int>(); while (loadBinaries.IsAlive) { yield return(null); } if (done) { LoadColors(); yield return(null); textures = new Texture2D[Model.Textures.Length]; MatchBones(character); time = new float[Model.TextureAnimations.Length]; frame = new int[Model.TextureAnimations.Length]; for (int i = 0; i < time.Length; i++) { time[i] = 0f; frame[i] = 0; yield return(null); } Loaded = !loadBinaries.IsAlive; Change = true; } }
//Load and setup model prefab public IEnumerator LoadPrefab(string modelfile, CASCHandler casc) { DestroyImmediate(mesh); if (modelsPath == null) { modelsPath = @"creature\"; } bool done = false; converter = new System.Drawing.ImageConverter(); this.casc = casc; GameObject prefab = Resources.Load <GameObject>($"{modelsPath}{modelfile}_prefab"); mesh = Instantiate(prefab, gameObject.transform); yield return(null); M2Model m2 = GetComponentInChildren <M2Model>(); byte[] data = m2.data.bytes; byte[] skin = m2.skin.bytes; byte[] skel = m2.skel.bytes; loadBinaries = new Thread(() => { Model = m2.LoadModel(data, skin, skel); done = true; }); loadBinaries.Start(); yield return(null); while (loadBinaries.IsAlive) { yield return(null); } if (done) { LoadColors(); textures = new Texture2D[Model.Textures.Length]; Transform[] bones = GetComponentInChildren <SkinnedMeshRenderer>().bones; yield return(null); if (Model.Particles.Length > 0) { GameObject[] particles = new GameObject[Model.Particles.Length]; for (int i = 0; i < particles.Length; i++) { particles[i] = WoWHelper.ParticleEffect(Model.Particles[i]); particles[i].transform.parent = bones[Model.Particles[i].Bone]; particles[i].transform.localPosition = Vector3.zero; particles[i].name = $"Particle{i}"; yield return(null); } } time = new float[Model.TextureAnimations.Length]; frame = new int[Model.TextureAnimations.Length]; for (int i = 0; i < time.Length; i++) { time[i] = 0f; frame[i] = 0; yield return(null); } renderer = GetComponentInChildren <SkinnedMeshRenderer>(); Change = true; Loaded = !loadBinaries.IsAlive; } }