Created
May 11, 2017 13:23
-
-
Save onotchi/dd95e9ae8b133971e62aeaef6534dc00 to your computer and use it in GitHub Desktop.
Unityでプロ生ちゃん新モデルのスパッツ・靴下・靴の表示を切り替え(Unityに取り込んだMMD版用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace PronamaChan | |
{ | |
public class EquipmentsChanger : MonoBehaviour | |
{ | |
public Material TransparentMaterial; | |
public SkinnedMeshRenderer SkinnedMesh; | |
public bool ShowSpats = false; | |
public bool ShowSocks = true; | |
public bool ShowShoes = true; | |
private Dictionary<MaterialIndexes, Material> _materialsDic; | |
private enum MaterialIndexes | |
{ | |
/// <summary>パンツ</summary> | |
Pants = 6, | |
/// <summary>すね</summary> | |
Shin = 13, | |
/// <summary>つま先</summary> | |
Toe = 14, | |
/// <summary>太もも</summary> | |
Thigh = 15, | |
/// <summary>靴下すね</summary> | |
SocksShin = 16, | |
/// <summary>靴下つま先</summary> | |
SocksToe = 17, | |
/// <summary>靴</summary> | |
Shoes = 18, | |
/// <summary>スパッツ</summary> | |
Spats = 19, | |
} | |
/* TシャツVer. | |
private enum MaterialIndexes | |
{ | |
/// <summary>パンツ</summary> | |
Pants = 2, | |
/// <summary>すね</summary> | |
Shin = 9, | |
/// <summary>つま先</summary> | |
Toe = 10, | |
/// <summary>太もも</summary> | |
Thigh = 11, | |
/// <summary>靴下すね</summary> | |
SocksShin = 12, | |
/// <summary>靴下つま先</summary> | |
SocksToe = 13, | |
/// <summary>靴</summary> | |
Shoes = 14, | |
/// <summary>スパッツ</summary> | |
Spats = 15, | |
} */ | |
// Use this for initialization | |
private void Start() | |
{ | |
this.StoreMaterials(); | |
this.ChangeEquipments(); | |
} | |
// Update is called once per frame | |
private void Update() | |
{ | |
} | |
private void StoreMaterials() | |
{ | |
this._materialsDic = new Dictionary<MaterialIndexes, Material>(); | |
var materials = this.SkinnedMesh.sharedMaterials; | |
foreach (MaterialIndexes index in Enum.GetValues(typeof(MaterialIndexes))) | |
{ | |
this._materialsDic[index] = materials[(int)index]; | |
} | |
//スパッツのRenderQuereを太もものそれより大きくしておく | |
this._materialsDic[MaterialIndexes.Spats].renderQueue = this._materialsDic[MaterialIndexes.Thigh].renderQueue + 1; | |
} | |
private void OnValidate() | |
{ | |
this.ChangeEquipments(); | |
} | |
private void ChangeEquipments() | |
{ | |
if (_materialsDic == null) return; | |
var renderer = this.SkinnedMesh.GetComponent<Renderer>(); | |
var materials = renderer.sharedMaterials; | |
if (this.ShowSpats) | |
{ | |
materials[(int)MaterialIndexes.Pants] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.Thigh] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.Spats] = this._materialsDic[MaterialIndexes.Spats]; | |
} | |
else | |
{ | |
materials[(int)MaterialIndexes.Pants] = this._materialsDic[MaterialIndexes.Pants]; | |
materials[(int)MaterialIndexes.Thigh] = this._materialsDic[MaterialIndexes.Thigh]; | |
materials[(int)MaterialIndexes.Spats] = this.TransparentMaterial; | |
} | |
if (this.ShowSocks) | |
{ | |
materials[(int)MaterialIndexes.Shin] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.Toe] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.SocksShin] = this._materialsDic[MaterialIndexes.SocksShin]; | |
if (this.ShowShoes) | |
{ | |
materials[(int)MaterialIndexes.SocksToe] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.Shoes] = this._materialsDic[MaterialIndexes.Shoes]; | |
} | |
else | |
{ | |
materials[(int)MaterialIndexes.SocksToe] = this._materialsDic[MaterialIndexes.SocksToe]; | |
materials[(int)MaterialIndexes.Shoes] = this.TransparentMaterial; | |
} | |
} | |
else | |
{ | |
materials[(int)MaterialIndexes.Shin] = this._materialsDic[MaterialIndexes.Shin]; | |
materials[(int)MaterialIndexes.SocksShin] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.SocksToe] = this.TransparentMaterial; | |
if (this.ShowShoes) | |
{ | |
materials[(int)MaterialIndexes.Toe] = this.TransparentMaterial; | |
materials[(int)MaterialIndexes.Shoes] = this._materialsDic[MaterialIndexes.Shoes]; | |
} | |
else | |
{ | |
materials[(int)MaterialIndexes.Toe] = this._materialsDic[MaterialIndexes.Toe]; | |
materials[(int)MaterialIndexes.Shoes] = this.TransparentMaterial; | |
} | |
} | |
renderer.sharedMaterials = materials; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment