KK_MobAdder.MobManager.CreteSilhouetteFromBundle(UnityEngine.AssetBundle, string, UnityEngine.Material, UnityEngine.GameObject, UnityEngine.RuntimeAnimatorController)

Here are the examples of the csharp api KK_MobAdder.MobManager.CreteSilhouetteFromBundle(UnityEngine.AssetBundle, string, UnityEngine.Material, UnityEngine.GameObject, UnityEngine.RuntimeAnimatorController) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : MobManager.cs
License : GNU General Public License v3.0
Project Creator : ManlyMarco

public static IEnumerator CreateTemplates()
        {
            // ---------- First load the built-in silhouette and other necessary replacedets ---------- //

            var top = new GameObject("silhouette_template");
            Object.DontDestroyOnLoad(top);

            var modelObj = CommonLib.Loadreplacedet<GameObject>("chara/oo_base.unity3d", "p_cm_body_00_low", true, "abdata");
            var modelRend = PrepareSilhouetteRenderer(modelObj);
            GameObject animObj;
            if (modelRend != null)
            {
                animObj = CommonLib.Loadreplacedet<GameObject>("chara/oo_base.unity3d", "p_cf_body_bone_low", true, "abdata");
            }
            else
            {
                // The fallback is needed for KK Party, posibly pre-darkness KK
                Object.Destroy(modelObj);
                modelObj = CommonLib.Loadreplacedet<GameObject>("chara/oo_base.unity3d", "p_cm_body_00", true, "abdata");
                modelRend = PrepareSilhouetteRenderer(modelObj);
                if (modelRend == null)
                {
                    Object.Destroy(modelObj);
                    throw new InvalidOperationException("Could not find silhouette model data");
                }

                animObj = CommonLib.Loadreplacedet<GameObject>("chara/oo_base.unity3d", "p_cf_body_bone", true, "abdata");
            }
            var animCmp = animObj.GetComponent<Animator>();
            foreach (var c in animObj.GetComponentsInChildren(typeof(Component), true))
            {
                if (c is Animator || c is Transform)
                    continue;

                // Get rid of useless performance-eating scripts
                // Can't DestroyImmediate these two because other components rely on them so they have to be removed later
                if (c is BaseData || c is NeckLookCalcVer2)
                    Object.Destroy(c);
                else
                    Object.DestroyImmediate(c);
            }

            var animObjCopy = Object.Instantiate(animObj);

            modelObj.transform.SetParent(top.transform);
            animObj.transform.SetParent(top.transform);

            RemoveCloneTagsFromName(modelObj);
            RemoveCloneTagsFromName(animObj);

            // Replace mesh bones with animator bones
            var animBones = animCmp.GetComponentsInChildren<Transform>(true);
            var modelBones = modelRend.bones.ToArray();
            for (var i = 0; i < modelBones.Length; i++)
                modelBones[i] = animBones.First(x => x.name == modelBones[i].name);
            modelRend.rootBone = animBones.First(x => x.name == "cf_j_root");
            modelRend.bones = modelBones;
            // Destroy no longer used bones
            Object.Destroy(modelObj.transform.Find("cf_j_root")?.gameObject);
            // Not used
            Object.Destroy(modelObj.transform.Find("cf_o_root/n_cm_body")?.gameObject);
            Object.Destroy(modelObj.transform.Find("cf_o_root/n_tang")?.gameObject);

            var animBundle = replacedetBundle.LoadFromFile(@"abdata\action\animator\00.unity3d");
            var animBase = animBundle.Loadreplacedet("base");

            var ctrl = (RuntimeAnimatorController)Object.Instantiate(animBase);
            animCmp.runtimeAnimatorController = ctrl;

            animBundle.Unload(false);

            SetupNavmeshObstacle(top);

            top.SetActive(false);
            _swimsuitSilhouetteTemplates = new List<GameObject> { top }; //todo more kinds? with hair?

            // Allow for Object.Destroy calls to finish since we're making copies of some of the object below
            yield return null;

            // ---------- Next load custom silhouette models from our replacedet bundle ---------- //

            var silhouetteMaterial = modelRend.material;

            var res = ResourceUtils.GetEmbeddedResource("silhouettes", typeof(MobAdderPlugin).replacedembly);
            var sab = replacedetBundle.LoadFromMemory(res);
            //var sab = replacedetBundle.LoadFromFile(@"E:\Unity projects\kk test\replacedets\replacedetBundles\test");

            var names = sab.GetAllreplacedetNames();

            var uniformNames = names.Where(x => x.Contains("uniform_")).ToList();
            _uniformSilhouetteTemplates = new List<GameObject>();
            foreach (var uniformName in uniformNames)
            {
                var newTop = CreteSilhouetteFromBundle(sab, uniformName, silhouetteMaterial, animObjCopy, ctrl);
                _uniformSilhouetteTemplates.Add(newTop);
            }

            var gymNames = names.Where(x => x.Contains("gym_")).ToList();
            _gymSilhouetteTemplates = new List<GameObject>();
            foreach (var gymName in gymNames)
            {
                var newTop = CreteSilhouetteFromBundle(sab, gymName, silhouetteMaterial, animObjCopy, ctrl);
                _gymSilhouetteTemplates.Add(newTop);
            }

            MobAdderPlugin.Logger.LogInfo($"Loaded {_uniformSilhouetteTemplates.Count} uniform silhouettes and {_gymSilhouetteTemplates.Count} gym silhouettes");

            var unused = names.Except(uniformNames).Except(gymNames).ToArray();
            if (unused.Any()) MobAdderPlugin.Logger.LogWarning("Unused replacedets in the silhouette replacedet bundle: " + string.Join("; ", unused));

            sab.Unload(false);

            // Allow for templates to finish creating before allowing spawning them
            yield return null;
        }