private void ReplaceMaterials(GameObject go, string path) { var meshRenderers = go.GetComponentsInChildren <MeshRenderer>(); foreach (var meshRenderer in meshRenderers) { var materials = meshRenderer.materials; if (materials == null) { continue; } for (var index = 0; index < materials.Length; index++) { var material = materials[index]; var materialName = material.name.Replace(" (Instance)", ""); Sideloader.LogDebug($"Material: {string.Join(":", new[] {path, materialName})}"); var materialMod = AssetTree.Find(path, materialName).FirstOrDefault(); if (materialMod != null) { materials[index] = materialMod.Mod.LoadMaterial(materialMod.FullPath); } } meshRenderer.materials = materials; } }
private void ReplaceMeshes(GameObject go, string path) { // TODO: Eventually, might need to handle SkinnedMeshRenderers, but for now it seems H3 doesn't use those for guns var meshFilters = go.GetComponentsInChildren <MeshFilter>(); foreach (var meshFilter in meshFilters) { var filterName = meshFilter.name; var meshName = meshFilter.mesh.name.Replace(" Instance", ""); Sideloader.Logger.LogDebug($"Mesh: {string.Join(":", new[] {path, filterName, meshName})}"); var replacement = AssetTree.Find(path, filterName, meshName).FirstOrDefault(); if (replacement != null) { meshFilter.mesh = replacement.Mod.LoadMesh(replacement.FullPath); } } }
private void ReplaceTextures(GameObject go, string path) { var meshRenderers = go.GetComponentsInChildren <MeshRenderer>(); foreach (var meshRenderer in meshRenderers) { var materials = meshRenderer.materials; if (materials == null) { continue; } foreach (var material in materials) { var materialName = material.name.Replace(" (Instance)", ""); if (material.mainTexture == null) { continue; } var textureName = material.mainTexture.name; Sideloader.Logger.LogDebug($"Texture: {string.Join(":", new[] {path, materialName, textureName})}"); var nodes = AssetTree.Find(path, materialName, textureName); if (nodes.Length == 0) { continue; } // TODO: Remove duplicates to prevent duplicate loading foreach (var modNode in nodes) { var tex = modNode.Mod.LoadTexture(modNode.FullPath); if (modNode.Path == null) { material.mainTexture = tex; } else { material.SetTexture(modNode.Path, tex); } } } meshRenderer.materials = materials; } }
private void ReplaceItemSpawnerIcon(ItemSpawnerID itemSpawnerId, string path) { if (!itemSpawnerId.Sprite) { return; } Sideloader.LogDebug( $"ItemSpawnerID Icon: {string.Join(":", new[] {path, itemSpawnerId.Sprite.name, itemSpawnerId.Sprite.texture.name})}"); var mod = AssetTree.Find(path, itemSpawnerId.Sprite.name, itemSpawnerId.Sprite.texture.name) .FirstOrDefault(); if (mod == null) { return; } var tex = mod.Mod.LoadTexture(mod.FullPath); var sprite = Sprite.Create(tex, itemSpawnerId.Sprite.rect, itemSpawnerId.Sprite.pivot, itemSpawnerId.Sprite.pixelsPerUnit, 0, SpriteMeshType.Tight, itemSpawnerId.Sprite.border); itemSpawnerId.Sprite = sprite; }