void Update() { // Add the components when checked and not already loaded if (loadSalsaAndRandomEyes && !salsa3D && !re3D) { // Salsa3D gameObject.AddComponent <Salsa3D>(); // Add a Salsa3D component salsa3D = GetComponent <Salsa3D>(); // Get reference to the Salsa3D component salsa3D.skinnedMeshRenderer = GetComponent <SkinnedMeshRenderer>(); // Link the SkinnedMeshRenderer salsa3D.saySmallIndex = 0; // Set saySmall BlendShape index salsa3D.sayMediumIndex = 1; // Set sayMedium BlendShape index salsa3D.sayLargeIndex = 2; // Set sayLarge BlendShape index salsa3D.SetAudioClip(audioClip); // Set AudioClip // Or set the AudioClip from a clip in any Resources folder //salsa3D.SetAudioClip((Resources.Load("EthanEcho0", typeof(AudioClip)) as AudioClip)); salsa3D.saySmallTrigger = 0.002f; // Set the saySmall amplitude trigger salsa3D.sayMediumTrigger = 0.004f; // Set the sayMedium amplitude trigger salsa3D.sayLargeTrigger = 0.006f; // Set the sayLarge amplitude trigger salsa3D.audioUpdateDelay = 0.08f; // Set the amplitutde sample update delay salsa3D.blendSpeed = 10f; // Set the blend speed salsa3D.rangeOfMotion = 100f; // Set the range of motion salsa3D.broadcast = true; // Enable talk event broadcasts salsa3D.broadcastReceivers = new GameObject[1]; // Creat a new array of broadcast receivers salsa3D.broadcastReceivers[0] = broadcastReciever; // Link to a GameObject setup to listen for SALSA talk events salsa3D.expandBroadcast = true; // Expand the broadcast recievers array in the inspector salsa3D.Play(); // Begin lip sync // RandomEyes3D gameObject.AddComponent <RandomEyes3D>(); // Add a RandomEyes3D component re3D = GetComponent <RandomEyes3D>(); // Get reference to the RandomEyes3D component re3D.skinnedMeshRenderer = GetComponent <SkinnedMeshRenderer>(); // Link the SkinnedMeshRenderer re3D.lookUpIndex = 3; // Set the lookUp BlendShape index re3D.lookDownIndex = 4; // Set the lookDown BlendShape index re3D.lookLeftIndex = 5; // Set the lookLeft BlendShape index re3D.lookRightIndex = 6; // Set the lookRight BlendShape index re3D.blinkIndex = 7; // Set the blink BlendShape index re3D.rangeOfMotion = 100f; // Set the eyes range of motion re3D.blendSpeed = 10f; // Set the eyes blend speed re3D.blinkDuration = 0.05f; // Set the blink duration re3D.blinkSpeed = 20f; // Set the blink speed re3D.SetOpenMax(0f); // Set the max eye open position, 0=max re3D.SetCloseMax(100f); // Set the max eye close position, 100=max re3D.SetRandomEyes(true); // Enable random eye movement re3D.SetBlink(true); // Enable random blink re3D.AutoLinkCustomShapes(true, salsa3D); // Automatically link all available BlendShapes while excluding eye and mouth shapes re3D.expandCustomShapes = true; // Expand the custom shapes array in the inspector re3D.broadcastCS = true; // Enable cust shape event broadcasts re3D.broadcastCSReceivers = new GameObject[1]; // Creat a new array of broadcast receivers re3D.broadcastCSReceivers[0] = GameObject.Find("Broadcasts"); // Link to a GameObject setup to listen for RandomEyes custom shape events re3D.expandBroadcastCS = true; // Expand the broadcast recievers array in the inspector } }
/// <summary> /// Draw the GUI buttons /// </summary> void OnGUI() { xPos = Screen.width - 20 - xWidth; // X position for right side GUI controls yPos = 0; // Reset the button Y position #region Turn random blink on or off yPos += yGap; if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Toggle Blink")) { if (randomEyes3D.blink) { randomEyes3D.SetBlink(false); } else { randomEyes3D.SetBlink(true); } } if (randomEyes3D.blink) { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Random Blink On"); } else { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Random Blink Off"); } #endregion #region When random blink is off, demonstrate programmatic blinking if (!randomEyes3D.blink) { yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Blink")) { randomEyes3D.Blink(0.075f); } } #endregion #region Toggle affinity to the target yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Toggle Affinity")) { if (affinity) { affinity = false; } else { affinity = true; } affinitySet = true; } if (affinity) { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Affinity On: " + randomEyes3D.targetAffinityPercentage + "%"); } else { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Affinity Off"); } if (affinitySet) { if (affinity) { randomEyes3D.SetTargetAffinity(true); randomEyes3D.SetLookTarget(target.gameObject); } else { randomEyes3D.SetTargetAffinity(false); } affinitySet = false; } #endregion #region Turn [Look Target] tracking on or off yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Toggle Tracking")) { if (track) { track = false; } else { track = true; } trackSet = true; } if (track) { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Tracking On"); } else { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Tracking Off"); } #endregion #region Turn random eye movement on or off yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Toggle RandomEyes")) { if (random) { randomEyes3D.SetRandomEyes(false); random = false; } else { randomEyes3D.SetRandomEyes(true); random = true; } } #endregion #region Display the on/off status of random eye movement if (random) { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Random Eyes On"); } else { GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Random Eyes Off"); } #endregion #region Display the on/off status, set target position to cursor position, and set the randomEyes3D.lookTarget if (track) { targetPos = Input.mousePosition; targetPos.z = -mainCam.transform.position.z - -target.transform.position.z; target.transform.position = new Vector3( mainCam.ScreenToWorldPoint(targetPos).x, mainCam.ScreenToWorldPoint(targetPos).y, -2f); } else { target.transform.position = targetPosHome; } if (trackSet) { if (track) { randomEyes3D.SetLookTarget(target.gameObject); } else { randomEyes3D.SetLookTarget(null); } trackSet = false; } #endregion #region When random eye movement is off, demonstrate programmatic eye control if (!random) { #region Set programmatic directional look controls yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Up Right")) { randomEyes3D.Look(RandomEyesLook.Position.UpRight); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Up")) { randomEyes3D.Look(RandomEyesLook.Position.Up); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Up Left")) { randomEyes3D.Look(RandomEyesLook.Position.UpLeft); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Right")) { randomEyes3D.Look(RandomEyesLook.Position.Right); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Forward")) { randomEyes3D.Look(RandomEyesLook.Position.Forward); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Left")) { randomEyes3D.Look(RandomEyesLook.Position.Left); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Down Right")) { randomEyes3D.Look(RandomEyesLook.Position.DownRight); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Down")) { randomEyes3D.Look(RandomEyesLook.Position.Down); } yPos += (yGap + yHeight); if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Look Down Left")) { randomEyes3D.Look(RandomEyesLook.Position.DownLeft); } #endregion } #endregion if (!affinity && !track) { randomEyes3D.SetLookTarget(null); } }
void Update() { // Add the components when checked and not already loaded if (loadSalsaAndRandomEyes && !salsa3D && !re3D) { // Salsa3D gameObject.AddComponent<Salsa3D>(); // Add a Salsa3D component salsa3D = GetComponent<Salsa3D>(); // Get reference to the Salsa3D component salsa3D.skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>(); // Link the SkinnedMeshRenderer salsa3D.saySmallIndex = 0; // Set saySmall BlendShape index salsa3D.sayMediumIndex = 1; // Set sayMedium BlendShape index salsa3D.sayLargeIndex = 2; // Set sayLarge BlendShape index salsa3D.SetAudioClip(audioClip); // Set AudioClip // Or set the AudioClip from a clip in any Resources folder //salsa3D.SetAudioClip((Resources.Load("EthanEcho0", typeof(AudioClip)) as AudioClip)); salsa3D.saySmallTrigger = 0.002f; // Set the saySmall amplitude trigger salsa3D.sayMediumTrigger = 0.004f; // Set the sayMedium amplitude trigger salsa3D.sayLargeTrigger = 0.006f; // Set the sayLarge amplitude trigger salsa3D.audioUpdateDelay = 0.08f; // Set the amplitutde sample update delay salsa3D.blendSpeed = 10f; // Set the blend speed salsa3D.rangeOfMotion = 100f; // Set the range of motion salsa3D.broadcast = true; // Enable talk event broadcasts salsa3D.broadcastReceivers = new GameObject[1]; // Creat a new array of broadcast receivers salsa3D.broadcastReceivers[0] = broadcastReciever; // Link to a GameObject setup to listen for SALSA talk events salsa3D.expandBroadcast = true; // Expand the broadcast recievers array in the inspector salsa3D.Play(); // Begin lip sync // RandomEyes3D gameObject.AddComponent<RandomEyes3D>(); // Add a RandomEyes3D component re3D = GetComponent<RandomEyes3D>(); // Get reference to the RandomEyes3D component re3D.skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>(); // Link the SkinnedMeshRenderer re3D.lookUpIndex = 3; // Set the lookUp BlendShape index re3D.lookDownIndex = 4; // Set the lookDown BlendShape index re3D.lookLeftIndex = 5; // Set the lookLeft BlendShape index re3D.lookRightIndex = 6; // Set the lookRight BlendShape index re3D.blinkIndex = 7; // Set the blink BlendShape index re3D.rangeOfMotion = 100f; // Set the eyes range of motion re3D.blendSpeed = 10f; // Set the eyes blend speed re3D.blinkDuration = 0.05f; // Set the blink duration re3D.blinkSpeed = 20f; // Set the blink speed re3D.SetOpenMax(0f); // Set the max eye open position, 0=max re3D.SetCloseMax(100f); // Set the max eye close position, 100=max re3D.SetRandomEyes(true); // Enable random eye movement re3D.SetBlink(true); // Enable random blink re3D.broadcast = true; // Enable eye movement event broadcasts re3D.broadcastReceivers = new GameObject[1]; // Creat a new array of broadcast receivers re3D.broadcastReceivers[0] = GameObject.Find("Broadcasts"); // Link to a GameObject setup to listen for RandomEyes look events re3D.expandBroadcast = true; // Expand the broadcast recievers array in the inspector re3D.AutoLinkCustomShapes(true, salsa3D); // Automatically link all available BlendShapes while excluding eye and mouth shapes re3D.expandCustomShapes = true; // Expand the custom shapes array in the inspector re3D.broadcastCS = true; // Enable cust shape event broadcasts re3D.broadcastCSReceivers = new GameObject[1]; // Creat a new array of broadcast receivers re3D.broadcastCSReceivers[0] = GameObject.Find("Broadcasts"); // Link to a GameObject setup to listen for RandomEyes custom shape events re3D.expandBroadcastCS = true; // Expand the broadcast recievers array in the inspector } }