Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class BlendShapeController : MonoBehaviour
- {
- public int blendShape;
- public float weight;
- public int blendShape2;
- public float weight2;
- int blendShapeCount;
- int currBlendShape = 0;
- SkinnedMeshRenderer skinnedMeshRenderer;
- Mesh skinnedMesh;
- float blendVal = 0f;
- bool first_update = true;
- void Awake ()
- {
- skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> ();
- skinnedMesh = GetComponent<SkinnedMeshRenderer> ().sharedMesh;
- }
- void Start ()
- {
- blendShapeCount = skinnedMesh.blendShapeCount;
- //initialize any blendshapes for this model here
- skinnedMeshRenderer.SetBlendShapeWeight (blendShape, weight);
- skinnedMeshRenderer.SetBlendShapeWeight (blendShape2, weight2);
- currBlendShape = 0;
- blendVal = skinnedMeshRenderer.GetBlendShapeWeight(currBlendShape);
- }
- void Update ()
- {
- if(first_update)
- {
- Start ();
- first_update = false;
- }
- //reset all blend shapes if select is pressed
- if (Input.GetKeyDown (KeyCode.Joystick1Button6) || (Input.GetKeyDown(KeyCode.P)))
- {
- currBlendShape = blendShapeCount - 1;
- blendVal = 0f;
- do
- {
- skinnedMeshRenderer.SetBlendShapeWeight (currBlendShape, blendVal);
- currBlendShape--;
- }
- while( currBlendShape > 0 );
- Start ();
- }
- //change the current shape
- if (Input.GetKeyDown(KeyCode.Joystick1Button2) || Input.GetKeyDown(KeyCode.Comma))
- {
- if(currBlendShape <= 0)
- currBlendShape = blendShapeCount - 1;
- else
- currBlendShape--;
- blendVal = skinnedMeshRenderer.GetBlendShapeWeight(currBlendShape);
- }
- else if (Input.GetKeyDown(KeyCode.Joystick1Button1) || Input.GetKeyDown(KeyCode.Period))
- {
- if(currBlendShape + 1 >= blendShapeCount)
- currBlendShape = 0;
- else
- currBlendShape++;
- blendVal = skinnedMeshRenderer.GetBlendShapeWeight(currBlendShape);
- }
- //modify current shape by trigger values
- float value = Input.GetAxis("Triggers") * -1;
- if( Input.GetKey(KeyCode.Semicolon) )
- {
- value = 1f;
- }
- else if( Input.GetKey(KeyCode.Quote) )
- {
- value = -1f;
- }
- if (blendVal > 0f && value < 0f)
- {
- //restore dick head if size increases from 0
- if(currBlendShape == blendShape)
- {
- if( blendVal >= 100f )
- {
- skinnedMeshRenderer.SetBlendShapeWeight (blendShape2, weight2);
- }
- }
- blendVal += value;
- }
- else if (blendVal < 100f && value > 0f)
- {
- blendVal += value;
- }
- skinnedMeshRenderer.SetBlendShapeWeight (currBlendShape, blendVal);
- //hide dick head if size reduced to 0
- if(currBlendShape == blendShape)
- {
- if( blendVal >= 100f && skinnedMeshRenderer.GetBlendShapeWeight(blendShape2) > 0f )
- {
- skinnedMeshRenderer.SetBlendShapeWeight (blendShape2, 0f);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement