private ModelSkinController AddDefaultSkin(GameObject def) { base.Logger.LogInfo("Adding default skin to " + def); ModelSkinController component = def.GetComponentInChildren <ModelLocator>().modelTransform.gameObject.AddComponent <ModelSkinController>(); CharacterModel model = def.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <CharacterModel>(); LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo); skinDefInfo.BaseSkins = new SkinDef[0]; skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(Color.black, Color.white, Color.black, Color.white); skinDefInfo.NameToken = "Default"; skinDefInfo.UnlockableName = ""; skinDefInfo.RootObject = def.GetComponentInChildren <ModelLocator>().modelTransform.gameObject; skinDefInfo.RendererInfos = model.baseRendererInfos; skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0]; skinDefInfo.GameObjectActivations = new SkinDef.GameObjectActivation[1] { new SkinDef.GameObjectActivation() { gameObject = def, shouldActivate = true } }; skinDefInfo.Name = "DEFAULT_" + def.name + "_SKIN"; if (model) { skinDefInfo.RendererInfos = model.baseRendererInfos; for (int i = 0; i < skinDefInfo.RendererInfos.Length; i++) { skinDefInfo.RendererInfos[i].defaultMaterial.enableInstancing = true; skinDefInfo.RendererInfos[i].renderer.material.enableInstancing = true; skinDefInfo.RendererInfos[i].renderer.sharedMaterial.enableInstancing = true; } SkinDef skinDef3 = LoadoutAPI.CreateNewSkinDef(skinDefInfo); component.skins = new SkinDef[1] { skinDef3 }; LoadoutAPI.AddSkinToCharacter(def, skinDef3); SkinDef[] skins = component.skins; SkinDef[][] newSkins = typeof(BodyCatalog).GetFieldValue <SkinDef[][]>("skins"); newSkins[BodyCatalog.FindBodyIndex(def)] = skins; typeof(BodyCatalog).SetFieldValue <SkinDef[][]>("skins", newSkins); } else { base.Logger.LogError("Unable to create new skin for " + def); } return(component); }
public void Awake() { Stonk.nameToken = "Artifact of Stonk"; Stonk.descriptionToken = "Every hit gives you items, getting hurt takes them away"; Stonk.smallIconDeselectedSprite = LoadoutAPI.CreateSkinIcon(Color.white, Color.white, Color.white, Color.white); Stonk.smallIconSelectedSprite = LoadoutAPI.CreateSkinIcon(Color.grey, Color.white, Color.white, Color.white); ArtifactCatalog.getAdditionalEntries += (list) => { list.Add(Stonk); }; On.RoR2.CharacterBody.OnTakeDamageServer += CharacterBody_OnTakeDamageServer; }
public static void RegisterSkins() { GameObject bodyPrefab = GrovetenderPlugin.myCharacter; GameObject model = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject; CharacterModel characterModel = model.GetComponent <CharacterModel>(); if (model.GetComponent <ModelSkinController>()) { GrovetenderPlugin.Destroy(model.GetComponent <ModelSkinController>()); } ModelSkinController skinController = model.AddComponent <ModelSkinController>(); ChildLocator childLocator = model.GetComponent <ChildLocator>(); SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer"); LanguageAPI.Add("GROVETENDERBODY_DEFAULT_SKIN_NAME", "Default"); LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo); skinDefInfo.BaseSkins = Array.Empty <SkinDef>(); skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0]; skinDefInfo.MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0]; skinDefInfo.GameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>(); skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(new Color(0.09f, 0.03f, 0.03f), new Color(0.039f, 0.039f, 0.078f), new Color(0.61f, 0.59f, 0.5f), new Color(0.9f, 0.9f, 0.9f)); skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0]; /*{ * new SkinDef.MeshReplacement * { * renderer = mainRenderer, * mesh = mainRenderer.sharedMesh * } * };*/ skinDefInfo.Name = "GROVETENDERBODY_DEFAULT_SKIN_NAME"; skinDefInfo.NameToken = "GROVETENDERBODY_DEFAULT_SKIN_NAME"; skinDefInfo.RendererInfos = characterModel.baseRendererInfos; skinDefInfo.RootObject = model; skinDefInfo.UnlockableName = ""; SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo); skinController.skins = new SkinDef[1] { defaultSkin }; }
public static void InitializeArtifact() { GoombaArtifactDef.nameToken = "Artifact of Goombastomping"; GoombaArtifactDef.descriptionToken = "Deal substantial damage upon landing on an enemy's head."; GoombaArtifactDef.smallIconDeselectedSprite = LoadoutAPI.CreateSkinIcon(Color.black, Color.white, Color.white, Color.white); GoombaArtifactDef.smallIconSelectedSprite = LoadoutAPI.CreateSkinIcon(Color.gray, Color.white, Color.white, Color.white); ArtifactAPI.Add(GoombaArtifactDef); goombaGameObject.name = "GoombaStomp"; if (deathMessages.Value) { LanguageAPI.Add("PLAYER_DEATH_QUOTE_GOOMBADEATH", goombaDeathToken); LanguageAPI.Add("PLAYER_DEATH_QUOTE_GOOMBADEATH_2P", goombaDeathMultiplayerToken); } }
private void CreateHenryPrefab() { if (!HenryBody) { PrefabBuilder builder = new PrefabBuilder(); builder.prefabName = "HenryBody"; builder.masteryAchievementUnlockable = ""; builder.model = Assets.mainAssetBundle.LoadAsset <GameObject>("mdlHenry"); builder.defaultSkinIcon = LoadoutAPI.CreateSkinIcon(API.HexToColor("00A86B"), API.HexToColor("E56717"), API.HexToColor("D9DDDC"), API.HexToColor("43464B")); builder.masterySkinIcon = LoadoutAPI.CreateSkinIcon(API.HexToColor("00A86B"), API.HexToColor("E56717"), API.HexToColor("D9DDDC"), API.HexToColor("43464B")); builder.masterySkinDelegate = material; HenryBody = builder.CreatePrefab(); Material material() { return(Assets.mainAssetBundle.LoadAsset <Material>("matHenryAlt")); } } }
public static void RegisterSkins() { GameObject bodyPrefab = Templar.myCharacter; GameObject model = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject; CharacterModel characterModel = model.GetComponent <CharacterModel>(); ModelSkinController skinController = model.AddComponent <ModelSkinController>(); ChildLocator childLocator = model.GetComponent <ChildLocator>(); SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer"); #region Default Skin LanguageAPI.Add("Templar_DEFAULT_SKIN", "Default"); LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo); skinDefInfo.BaseSkins = Array.Empty <SkinDef>(); skinDefInfo.MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0]; skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0]; skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(new Color(0.64f, 0.31f, 0.22f), new Color(0.54f, 0.21f, 0.12f), new Color(0.64f, 0.31f, 0.22f), new Color(0.54f, 0.21f, 0.12f)); skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0]; skinDefInfo.Name = "Templar_DEFAULT_SKIN"; skinDefInfo.NameToken = "Templar_DEFAULT_SKIN"; skinDefInfo.RendererInfos = characterModel.baseRendererInfos; skinDefInfo.RootObject = model; CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos; CharacterModel.RendererInfo[] array = new CharacterModel.RendererInfo[rendererInfos.Length]; rendererInfos.CopyTo(array, 0); Material material = array[0].defaultMaterial; if (material) { material = UnityEngine.Object.Instantiate <Material>(LegacyResourcesAPI.Load <GameObject>("Prefabs/CharacterBodies/ClayBruiserBody").GetComponentInChildren <CharacterModel>().baseRendererInfos[0].defaultMaterial); array[0].defaultMaterial = material; } skinDefInfo.RendererInfos = array; SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo); #endregion var skinDefs = new List <SkinDef>() { defaultSkin }; skinController.skins = skinDefs.ToArray(); }
public static void RegisterArtifacts() { GoombaArtifactDef.nameToken = "Artifact of Headstomping"; GoombaArtifactDef.descriptionToken = "Deal substantial damage upon landing on an enemy's head."; GoombaArtifactDef.smallIconDeselectedSprite = LoadoutAPI.CreateSkinIcon(Color.white, Color.white, Color.white, Color.white); GoombaArtifactDef.smallIconSelectedSprite = LoadoutAPI.CreateSkinIcon(Color.gray, Color.white, Color.white, Color.white); goombaGameObject.name = "GoombaStomp"; LanguageAPI.Add("PLAYER_DEATH_QUOTE_GOOMBADEATH", goombaDeathToken); LanguageAPI.Add("PLAYER_DEATH_QUOTE_GOOMBADEATH_2P", goombaDeathMultiplayerToken); ArtifactCatalog.getAdditionalEntries += (list) => { list.Add(GoombaArtifactDef); }; On.RoR2.CharacterMotor.OnHitGround += CharacterMotor_OnHitGround; On.RoR2.GlobalEventManager.OnPlayerCharacterDeath += GlobalEventManager_OnPlayerCharacterDeath; //full override until i can get IL }
public void Awake() { Conversion = ScriptableObject.CreateInstance <ArtifactDef>(); Conversion.nameToken = "Artifact of Conversion"; Conversion.descriptionToken = "Amount of your items is capped with your experience level, BUT you can DROP your items. Gain experience and share with friends! Click on an item to drop."; Sprite template = LoadoutAPI.CreateSkinIcon(Color.white, Color.white, Color.white, Color.white); string artifactIconPath = $"file:\\\\{Info.Location}\\..\\conv.png"; string artifactIconDisabledPath = $"file:\\\\{Info.Location}\\..\\convdis.png"; WWW w = new WWW(artifactIconPath); while (!w.isDone) { ; } WWW ww = new WWW(artifactIconDisabledPath); while (!ww.isDone) { ; } Texture2D artifactIconTexture = w.texture; Texture2D artifactIconDisabledTexture = ww.texture; Sprite artifactIcon = Sprite.Create(artifactIconTexture, template.rect, template.pivot); Sprite artifactDisabledIcon = Sprite.Create(artifactIconDisabledTexture, template.rect, template.pivot); Conversion.smallIconDeselectedSprite = artifactDisabledIcon; Conversion.smallIconSelectedSprite = artifactIcon; ArtifactCatalog.getAdditionalEntries += (list) => { list.Add(Conversion); }; RunArtifactManager.onArtifactEnabledGlobal += RunArtifactManager_onArtifactEnabledGlobal; RunArtifactManager.onArtifactDisabledGlobal += RunArtifactManager_onArtifactDisabledGlobal; }
public void AddSkin(GameObject gameObject, string SkinFolder, ConfigFile config) { LoadoutAPI.SkinDefInfo skinDefInfo = new LoadoutAPI.SkinDefInfo(); skinDefInfo.BaseSkins = new SkinDef[0]; skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(config.Bind <Color>("", "IconColorTop", Color.magenta).Value, config.Bind <Color>("", "IconColorRight", Color.black).Value, config.Bind <Color>("", "IconColorBottom", Color.magenta).Value, config.Bind <Color>("", "IconColorLeft", Color.black).Value); skinDefInfo.NameToken = config.Bind <string>("", "SkinName", "DefaultName").Value; skinDefInfo.UnlockableName = config.Bind <string>("", "UnlockableName", "").Value; skinDefInfo.RootObject = gameObject.GetComponentInChildren <ModelLocator>().modelTransform.gameObject; skinDefInfo.RendererInfos = new CharacterModel.RendererInfo[0]; skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0]; skinDefInfo.GameObjectActivations = new SkinDef.GameObjectActivation[0]; skinDefInfo.Name = "CUSTOM_" + gameObject.name + "_SKIN"; base.Logger.LogInfo("Adding new skin to " + gameObject.name + " with name " + skinDefInfo.NameToken); int MeshReplacementIndex = config.Bind <int>("", "MeshReplacementIndex", -1).Value; string MeshReplacementKey = config.Bind <string>("", "SkinMeshToUse", "Default").Value; string minionSkinForBody = config.Bind <string>("", "MinionReplacementForBody", "NONE", new ConfigDescription("If this is a minion skin, determines the characterbody for it")).Value; string minionSkinForSkin = config.Bind <string>("", "MinionReplacementForSkin", "NONE", new ConfigDescription("If this is a minion skin, determines the characterbody for it")).Value; bool isMinionSkin = false; if (minionSkinForBody != null) { isMinionSkin = minionSkinForBody != "NONE"; } if (MeshReplacementKey != "Default" && MeshReplacementKey != "Custom" && MeshReplacementKey != null) { SkinDef def1 = gameObject.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <ModelSkinController>().skins.First(x => x.nameToken == MeshReplacementKey); MeshReplacementIndex = Array.IndexOf(gameObject.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <ModelSkinController>().skins, def1); } SkinDef def = gameObject.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <ModelSkinController>().skins[MeshReplacementIndex]; if (def) { skinDefInfo.MeshReplacements = def.meshReplacements; skinDefInfo.RendererInfos = def.rendererInfos; } CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos; CharacterModel.RendererInfo[] array = new CharacterModel.RendererInfo[rendererInfos.Length]; rendererInfos.CopyTo(array, 0); foreach (string MaterialFolder in Directory.EnumerateDirectories(SkinFolder)) { //Get name of render from folder name string[] MaterialIndexVs = MaterialFolder.Split(new string[] { @"\" }, StringSplitOptions.None); string RendererName = MaterialIndexVs[MaterialIndexVs.Length - 1]; //Find the renderer based on the name int index = Array.IndexOf(array, array.FirstOrDefault(x => x.renderer.name == RendererName)); //Get the material of the renderer Material defaultMaterial = array[index].defaultMaterial; if (defaultMaterial) { //Create a clone of the material defaultMaterial = UnityEngine.Object.Instantiate <Material>(defaultMaterial); //Iterate through all files related to this material from the skin folder foreach (string FilePath in Directory.EnumerateFiles(MaterialFolder)) { //Loading and applying textures from .png if (FilePath.EndsWith(".PNG") || FilePath.EndsWith(".png")) { //Use File name to get texture name string[] FilePathVs = FilePath.Split(new string[] { @"\" }, StringSplitOptions.None); string FileName = FilePathVs[FilePathVs.Length - 1].Replace(".PNG", ""); //Create new Texture2d and load image in Texture2D savedTex = new Texture2D(1, 1, TextureFormat.RGBAFloat, false, true); ImageConversion.LoadImage(savedTex, System.IO.File.ReadAllBytes(FilePath)); //Apply the loaded image savedTex.Apply(); //Attempt to place this image onto the material in the correct property if (defaultMaterial.HasProperty(FileName)) { defaultMaterial.enableInstancing = true; defaultMaterial.SetTexture(FileName, GetReadableTextureCopy(savedTex)); } } else if (FilePath.EndsWith(".cfg")) { //Load the config at this path BepInEx.Configuration.ConfigFile perMatConfig = new ConfigFile(FilePath, true); //iterate through material properties and apply via config foreach (string value in floatProperties) { if (defaultMaterial.HasProperty(value)) { defaultMaterial.SetFloat(value, perMatConfig.Bind <float>("", value, defaultMaterial.GetFloat(value), new ConfigDescription("Sets the value for " + value)).Value); } } foreach (string value in colorProperties) { if (defaultMaterial.HasProperty(value)) { defaultMaterial.SetColor(value, perMatConfig.Bind <Color>("", value, defaultMaterial.GetColor(value), new ConfigDescription("Sets the value for " + value)).Value); } } foreach (string value in defaultMaterial.shaderKeywords) { bool isEnabled = perMatConfig.Bind <bool>("", value, defaultMaterial.IsKeywordEnabled(value), new ConfigDescription("Sets the value for " + value)).Value; if (isEnabled) { defaultMaterial.EnableKeyword(value); } else { defaultMaterial.DisableKeyword(value); } } } else { base.Logger.LogError("Unsupported file found in material folder: " + FilePath); } } array[index].defaultMaterial = defaultMaterial; } } skinDefInfo.RendererInfos = array; LoadoutAPI.AddSkinToCharacter(gameObject, skinDefInfo); SkinDef[] skins = gameObject.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <ModelSkinController>().skins; skins[skins.Length - 1].minionSkinReplacements = new SkinDef.MinionSkinReplacement[0]; skins[skins.Length - 1].projectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0]; if (isMinionSkin) { base.Logger.LogInfo("Is a minion skin"); foreach (GameObject body in BodyCatalog.allBodyPrefabs) { if (body.name == minionSkinForBody) { base.Logger.LogInfo("Applying minionskinreplacement"); SkinDef defForMaster = body.GetComponentInChildren <ModelSkinController>().skins.First(x => x.nameToken == minionSkinForSkin); base.Logger.LogInfo("Size was " + defForMaster.minionSkinReplacements.Length); Array.Resize(ref defForMaster.minionSkinReplacements, defForMaster.minionSkinReplacements.Length + 1); defForMaster.minionSkinReplacements[defForMaster.minionSkinReplacements.Length - 1] = new SkinDef.MinionSkinReplacement() { minionBodyPrefab = gameObject, minionSkin = skins[skins.Length - 1] }; base.Logger.LogInfo("Size is now " + defForMaster.minionSkinReplacements.Length); } } } SkinDef[][] newSkins = typeof(BodyCatalog).GetFieldValue <SkinDef[][]>("skins"); newSkins[BodyCatalog.FindBodyIndex(gameObject)] = skins; typeof(BodyCatalog).SetFieldValue <SkinDef[][]>("skins", newSkins); }
public void AddSkin(SurvivorDef def, string SkinFolder, ConfigFile config) { GameObject gameObject = def.bodyPrefab; LoadoutAPI.SkinDefInfo skinDefInfo = new LoadoutAPI.SkinDefInfo(); skinDefInfo.BaseSkins = new SkinDef[0]; skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(config.Bind <Color>("", "IconColorTop", Color.magenta).Value, config.Bind <Color>("", "IconColorRight", Color.black).Value, config.Bind <Color>("", "IconColorBottom", Color.magenta).Value, config.Bind <Color>("", "IconColorLeft", Color.black).Value); skinDefInfo.NameToken = config.Bind <string>("", "SkinName", "DefaultName").Value; skinDefInfo.UnlockableName = config.Bind <string>("", "UnlockableName", "").Value; skinDefInfo.RootObject = def.bodyPrefab.GetComponent <ModelLocator>().modelTransform.gameObject; skinDefInfo.RendererInfos = new CharacterModel.RendererInfo[0]; skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0]; skinDefInfo.GameObjectActivations = new SkinDef.GameObjectActivation[0]; skinDefInfo.Name = "SKIN_" + gameObject.name + "_DEFAULT"; int MeshReplacementIndex = config.Bind <int>("", "MeshReplacementIndex", 0).Value; if (MeshReplacementIndex != -1) { skinDefInfo.MeshReplacements = gameObject.GetComponent <ModelLocator>().modelTransform.GetComponent <ModelSkinController>().skins[MeshReplacementIndex].meshReplacements; skinDefInfo.RendererInfos = gameObject.GetComponent <ModelLocator>().modelTransform.GetComponent <ModelSkinController>().skins[MeshReplacementIndex].rendererInfos; } CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos; CharacterModel.RendererInfo[] array = new CharacterModel.RendererInfo[rendererInfos.Length]; rendererInfos.CopyTo(array, 0); foreach (string MaterialFolder in Directory.EnumerateDirectories(SkinFolder)) { string[] MaterialIndexVs = MaterialFolder.Split(new string[] { @"\" }, StringSplitOptions.None); string RendererName = MaterialIndexVs[MaterialIndexVs.Length - 1]; int index = Array.IndexOf(array, array.FirstOrDefault(x => x.renderer.name == RendererName)); Material defaultMaterial = array[index].defaultMaterial; if (defaultMaterial) { defaultMaterial = UnityEngine.Object.Instantiate <Material>(defaultMaterial); foreach (string FilePath in Directory.EnumerateFiles(MaterialFolder)) { if (FilePath.EndsWith(".PNG") || FilePath.EndsWith(".png")) { string[] FilePathVs = FilePath.Split(new string[] { @"\" }, StringSplitOptions.None); string FileName = FilePathVs[FilePathVs.Length - 1].Replace(".PNG", ""); Texture2D savedTex = new Texture2D(1, 1, TextureFormat.RGBAFloat, false, true); ImageConversion.LoadImage(savedTex, System.IO.File.ReadAllBytes(FilePath)); savedTex.Apply(); if (defaultMaterial.HasProperty(FileName)) { defaultMaterial.enableInstancing = true; defaultMaterial.SetTexture(FileName, GetReadableTextureCopy(savedTex)); } } else if (FilePath.EndsWith(".cfg")) { string[] ConfigPathVs = FilePath.Split(new string[] { @"\" }, StringSplitOptions.None); string ConfigName = @"BepInEx\skins\" + ConfigPathVs[ConfigPathVs.Length - 4] + @"\" + ConfigPathVs[ConfigPathVs.Length - 3] + @"\" + ConfigPathVs[ConfigPathVs.Length - 2] + @"\" + ConfigPathVs[ConfigPathVs.Length - 1]; BepInEx.Configuration.ConfigFile perMatConfig = new ConfigFile(ConfigName, true); { foreach (string value in floatProperties) { if (defaultMaterial.HasProperty(value)) { defaultMaterial.SetFloat(value, perMatConfig.Bind <float>("", value, defaultMaterial.GetFloat(value), new ConfigDescription("Sets the value for " + value)).Value); } } foreach (string value in colorProperties) { if (defaultMaterial.HasProperty(value)) { defaultMaterial.SetColor(value, perMatConfig.Bind <Color>("", value, defaultMaterial.GetColor(value), new ConfigDescription("Sets the value for " + value)).Value); } } foreach (string value in defaultMaterial.shaderKeywords) { bool isEnabled = perMatConfig.Bind <bool>("", value, defaultMaterial.IsKeywordEnabled(value), new ConfigDescription("Sets the value for " + value)).Value; if (isEnabled) { defaultMaterial.EnableKeyword(value); } else { defaultMaterial.DisableKeyword(value); } } } } else if (FilePath.EndsWith(".obj")) { Mesh holderMesh = new Mesh(); ObjImporter newMesh = new ObjImporter(); holderMesh = newMesh.ImportFile(FilePath); if (array[index].renderer.gameObject.GetComponent <MeshFilter>()) { Array.Resize(ref skinDefInfo.MeshReplacements, skinDefInfo.MeshReplacements.Length + 1); skinDefInfo.MeshReplacements[skinDefInfo.MeshReplacements.Length - 1].mesh = holderMesh; skinDefInfo.MeshReplacements[skinDefInfo.MeshReplacements.Length - 1].renderer = array[index].renderer; (skinDefInfo.MeshReplacements[skinDefInfo.MeshReplacements.Length - 1].renderer as SkinnedMeshRenderer).sharedMesh = holderMesh; } } else { base.Logger.LogError("Unsupported file found in material folder: " + FilePath); } } array[index].defaultMaterial = defaultMaterial; } } base.Logger.LogInfo("Added new skin to " + def.bodyPrefab.name + " with name " + skinDefInfo.NameToken); skinDefInfo.RendererInfos = array; LoadoutAPI.AddSkinToCharacter(def.bodyPrefab, skinDefInfo); SkinDef[] skins = def.bodyPrefab.GetComponent <ModelLocator>().modelTransform.GetComponent <ModelSkinController>().skins; SkinDef[][] newSkins = typeof(BodyCatalog).GetFieldValue <SkinDef[][]>("skins"); newSkins[SurvivorCatalog.GetBodyIndexFromSurvivorIndex(def.survivorIndex)] = skins; typeof(BodyCatalog).SetFieldValue <SkinDef[][]>("skins", newSkins); }
private void AddSkins(GameObject bodyObject) //credits to rob { GameObject bodyPrefab = bodyObject; GameObject model = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject; CharacterModel characterModel = model.GetComponent <CharacterModel>(); ModelSkinController skinController = null; if (model.GetComponent <ModelSkinController>()) { skinController = model.GetComponent <ModelSkinController>(); } else { skinController = model.AddComponent <ModelSkinController>(); } SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer"); if (mainRenderer == null) { CharacterModel.RendererInfo[] bRI = Reflection.GetFieldValue <CharacterModel.RendererInfo[]>(characterModel, "baseRendererInfos"); if (bRI != null) { foreach (CharacterModel.RendererInfo rendererInfo in bRI) { if (rendererInfo.renderer is SkinnedMeshRenderer) { mainRenderer = (SkinnedMeshRenderer)rendererInfo.renderer; break; } } if (mainRenderer != null) { characterModel.SetFieldValue <SkinnedMeshRenderer>("mainSkinnedMeshRenderer", mainRenderer); } } } LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo); skinDefInfo.BaseSkins = Array.Empty <SkinDef>(); skinDefInfo.GameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>(); skinDefInfo.Icon = LoadoutAPI.CreateSkinIcon(Color.white, Color.white, Color.white, Color.white); skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[] { new SkinDef.MeshReplacement { renderer = mainRenderer, mesh = mainRenderer.sharedMesh } }; skinDefInfo.Name = "PYRO_DEFAULT_SKIN_NAME"; skinDefInfo.NameToken = "PYRO_DEFAULT_SKIN_NAME"; skinDefInfo.RendererInfos = characterModel.baseRendererInfos; skinDefInfo.RootObject = model; skinDefInfo.UnlockableName = ""; skinDefInfo.MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0]; skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0]; SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo); skinController.skins = new SkinDef[1] { defaultSkin, }; }