Created
May 11, 2017 12:26
-
-
Save onotchi/9fef746db75aad4a653f432be84a9917 to your computer and use it in GitHub Desktop.
中野シスターズの表情を変化させる
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.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
namespace NakaSis | |
{ | |
public class FaceUpdate : MonoBehaviour | |
{ | |
public SkinnedMeshRenderer EyeBall; | |
public SkinnedMeshRenderer Face; | |
//各スライダーの現在値を保持するリスト | |
private List<float> _sliderValues; | |
//BlendShape名の表示スタイル | |
private GUIStyle _labelTitleStyle; | |
//スライダー値の表示スタイル | |
private GUIStyle _labelValueStyle; | |
private int _blendShapeCount; | |
private void Start() | |
{ | |
if (this.EyeBall == null || this.Face == null) return; | |
//blendShapeのカウント | |
this._blendShapeCount = this.EyeBall.sharedMesh.blendShapeCount + this.Face.sharedMesh.blendShapeCount; | |
this._sliderValues = Enumerable.Repeat<float>(0f, this._blendShapeCount).ToList(); | |
this._labelTitleStyle = new GUIStyle { fixedWidth = 190f, alignment = TextAnchor.MiddleRight, normal = new GUIStyleState { textColor = Color.white } }; | |
this._labelValueStyle = new GUIStyle { fixedWidth = 20f, alignment = TextAnchor.MiddleRight, normal = new GUIStyleState { textColor = Color.white } }; | |
} | |
private void OnGUI() | |
{ | |
if (this.EyeBall == null || this.Face == null) return; | |
GUILayout.Box("", GUILayout.Width(330), GUILayout.Height(15 * (this._blendShapeCount + 1))); | |
Rect screenRect = new Rect(10, 10, 300, 15 * (this._blendShapeCount + 1)); | |
GUILayout.BeginArea(screenRect); | |
var sliderIndex = 0; | |
//EyeBall | |
for (var defIndex = 0; defIndex < this.EyeBall.sharedMesh.blendShapeCount; defIndex++) | |
{ | |
sliderIndex = defIndex; | |
GUILayout.BeginHorizontal(); | |
//BlendShape名 | |
var labelName = this.EyeBall.sharedMesh.GetBlendShapeName(defIndex); | |
labelName = labelName.Substring(labelName.IndexOf('.') + 1); | |
GUILayout.Label(labelName, this._labelTitleStyle); | |
//スライダー | |
this._sliderValues[sliderIndex] = GUILayout.HorizontalSlider(this._sliderValues[sliderIndex], 0f, 100f); | |
//スライダーの値 | |
GUILayout.Label(((int)this._sliderValues[sliderIndex]).ToString("#0"), this._labelValueStyle); | |
GUILayout.EndHorizontal(); | |
//スライダーの値をBlendShapeに反映 | |
this.EyeBall.SetBlendShapeWeight(defIndex, this._sliderValues[sliderIndex]); | |
} | |
//Face | |
var adjustCount = this.EyeBall.sharedMesh.blendShapeCount; | |
for (int defIndex = 0; defIndex < this.Face.sharedMesh.blendShapeCount; defIndex++) | |
{ | |
sliderIndex = adjustCount + defIndex; | |
GUILayout.BeginHorizontal(); | |
//BlendShape名 | |
var labelName = this.Face.sharedMesh.GetBlendShapeName(defIndex); | |
labelName = labelName.Substring(labelName.IndexOf('.') + 1); | |
GUILayout.Label(labelName, this._labelTitleStyle); | |
//スライダー | |
this._sliderValues[sliderIndex] = GUILayout.HorizontalSlider(this._sliderValues[sliderIndex], 0f, 100f); | |
//スライダーの値 | |
GUILayout.Label(((int)this._sliderValues[sliderIndex]).ToString("#0"), this._labelValueStyle); | |
GUILayout.EndHorizontal(); | |
//スライダーの値をBlendShapeに反映 | |
this.Face.SetBlendShapeWeight(defIndex, this._sliderValues[sliderIndex]); | |
} | |
GUILayout.EndArea(); | |
} | |
private void Update() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment