RandomEyes Code Examples
RandomEyes is distributed as compiled dll's as part of the Salsa package so you can write code for RandomEyes in your favorite unity supported language. Include the SALSA namespace at the top of your script before you can interact with SALSA programmatically.
C#:
using CrazyMinnow.SALSA;
JavaScript:
import CrazyMinnow.SALSA;
Create a public Salsa2D or Salsa3D variable in your script:
C#:
public RandomEyes2D randomEyes;
public RandomEyes3D randomEyes;
JavaScript:
public randomEyes : RandomEyes2D;
public randomEyes : RandomEyes3D;
Use GetComponent to get reference to a RandomEyes2D or RandomEyes3D instance just like you would any other component:
C#:
randomEyes = GameObject.Find("GameObjectWithRandomEyesComponent").GetComponent();
randomEyes = GameObject.Find("GameObjectWithRandomEyesComponent").GetComponent();
JavaScript:
randomEyes = GameObject.Find("GameObjectWithRandomEyesComponent").GetComponent();
randomEyes = GameObject.Find("GameObjectWithRandomEyesComponent").GetComponent();
Use FindObjectOfType or FindObjectsOfType to get reference to one or more RandomEyes2D or RandomEyes3D instances just like you would any other component:
C#:
randomEyes = (RandomEyes2D)FindObjectOfType(typeof(RandomEyes2D));
randomEyes = (RandomEyes3D)FindObjectOfType(typeof(RandomEyes3D));
RandomEyes2D[] randomEyes = (RandomEyes2D)FindObjectsOfType(typeof(RandomEyes2D));
RandomEyes3D[] randomEyes = (RandomEyes3D)FindObjectsOfType(typeof(RandomEyes3D));
JavaScript:
randomEyes = FindObjectOfType(CrazyMinnow.SALSA.RandomEyes2D);
randomEyes = FindObjectOfType(CrazyMinnow.SALSA.RandomEyes3D);
randomEyes : RandomEyes2D[] = FindObjectsOfType(RandomEyes2D);
randomEyes : RandomEyes3D[] = FindObjectsOfType(RandomEyes3D);
Once you have reference to your RandomEyes2D or RandomEyes3D instance, you can use that instance to access the properties and public functions detailed above. See the CM_RandomEyes2D_Functions and CM_RandomEyes3D_Functions scripts in [Crazy Minnow Studio/Examples/Scripts] for documented code examples. Both C# and JavaScript examples are included.
- RandomEyes2D C# example
- RandomEyes3D C# example
- RandomEyes2D JavaScript example
- RandomEyes3D JavaScript example
C# - RandomEyes2D syntax example only, see [Crazy Minnow Studio/Examples/Scripts] for functional examples):
using UnityEngine;
using System.Collections;
using CrazyMinnow.SALSA; // Import SALSA classes from the CrazyMinnow namespace
public class YourScript : MonoBehavior
{
public RandomEyes2D randomEyes; // Public reference to RandomEyes2D
void Start()
{
// Get reference to the RandomEyes2D component
randomEyes = GameObject.Find("GameObjectWithRandomEyes").GetComponent();
randomEyes.Look(RandomEyesLook.Position.Forward); // Set the look position
randomEyes.Blink(0.25f); // Blink the eyes for 0.25 seconds
randomEyes.SetLookTarget(SOMEGAMEOBJECT); // Enable eye tracking
randomEyes.SetTargetAffinity(true); // Enable or disable look target affinity
randomEyes.SetAffinityPercentage(0.7f); // Set the affinity percentage
randomEyes.SetRandomEyes(true); // Enable or disable random eyes
randomEyes.SetBlink(true); // Enable or disable random blinking
randomEyes.SetRangeOfMotion(45.5f); // Set the eye movement range of motion
randomEyes.SetBlendSpeed(85.5f); // Set the eye movement speed
randomEyes.SetBlinkDuration(0.05f); // The duration eyes remain closed during a blink
// Set the Eyes to layer 5
randomEyes.SetOrderInLayer(RandomEyes2D.SpriteRend.Eyes, 5);
}
}
C# - RandomEyes3D syntax example only, see [Crazy Minnow Studio/Examples/Scripts] for functional examples):
using UnityEngine;
using System.Collections;
using CrazyMinnow.SALSA; // Import SALSA classes from the CrazyMinnow namespace
public class YourScript : MonoBehavior
{
public RandomEyes3D randomEyes; // Public reference to RandomEyes3D
void Start()
{
// Get reference to the RandomEyes3D component
randomEyes = GameObject.Find("GameObjectWithRandomEyes").GetComponent();
randomEyes.SetBlinkSpeed(20f); // The speed of a blink
randomEyes.SetOpenMax(10f); // The maximum amount the eyes can open (0=max)
randomEyes.SetCloseMax(100f); // The maximum amount the eyes can close (100=max)
randomEyes.SetCustomShapeRandom(true); // Enable random custom shapes
randomEyes.SetCustomShape("smile"); // Set “smile” as the [Current Custom Shape]
randomEyes.SetCustomShape("smile", 2.5f); // Same as above but for 2.5 seconds
randomEyes.SetCustomShapeOverride("smile", true); // Override smile
randomEyes.SetCustomShapeOverride("smile", 2.5f); // Same as above but for 2.5 sec
randomEyes.SetCustomShapeBlendSpeed("smile", 3f); // Smile blendSpeed to 3
randomEyes.SetCustomShapeRangeOfMotion("smile", 80f); // Smile rangeOfMotion to 80
randomEyes.SetGroup("smile", true); // Activate/deactivate multi-BlendShape smile
randomEyes.SetGroup("smile", 1.5f); // Activate multi-BlendShape smile for 1.5 seconds
}
}
JavaScript - RandomEyes2D syntax example only, see [Crazy Minnow Studio/Examples/Scripts] for functional examples):
#pragma strict
import CrazyMinnow.SALSA; // Import SALSA classes from the CrazyMinnow namespace
public class YourScript extends MonoBehavior {
public var randomEyes : RandomEyes2D; // Public reference to Salsa2D
function Start() {
// Get reference to the RandomEyes2D component
randomEyes = GameObject.Find("GameObjectWithRandomEyes").GetComponent(RandomEyes2D);
randomEyes.Look(RandomEyesLook.Position.Forward); // Set the look position
randomEyes.Blink(0.25); // Blink the eyes for 0.25 seconds
randomEyes.SetLookTarget(SOMEGAMEOBJECT); // Enable eye tracking
randomEyes.SetTargetAffinity(true); // Enable or disable look target affinity
randomEyes.SetAffinityPercentage(0.7); // Set the affinity percentage
randomEyes.SetRandomEyes(true); // Enable or disable random eyes
randomEyes.SetBlink(true); // Enable or disable random blinking
randomEyes.SetRangeOfMotion(45.5f); // Set the eye movement range of motion
randomEyes.SetBlendSpeed(85.5f); // Set the eye movement speed
randomEyes.SetBlinkDuration(0.05f); // The duration eyes remain closed during a blink
// Set the Eyes to layer 5
randomEyes.SetOrderInLayer(RandomEyes2D.SpriteRend.Eyes, 5);
}
}
JavaScript - RandomEyes3D syntax example only, see [Crazy Minnow Studio/Examples/Scripts] for functional examples):
#pragma strict
import CrazyMinnow.SALSA; // Import SALSA classes from the CrazyMinnow namespace
public class YourScript extends MonoBehavior {
public var randomEyes : RandomEyes3D; // Public reference to Salsa2D
function Start() {
// Get reference to the RandomEyes3D component
randomEyes = GameObject.Find("GameObjectWithRandomEyes").GetComponent(RandomEyes3D);
randomEyes.SetBlinkSpeed(20); // The speed of a blink
randomEyes.SetOpenMax(10); // The maximum amount the eyes can open (0=max)
randomEyes.SetCloseMax(100); // The maximum amount the eyes can close (100=max)
randomEyes.SetCustomShapeRandom(true); // Enable random custom shapes
randomEyes.SetCustomShape("smile"); // Set “smile” as the [Current Custom Shape]
randomEyes.SetCustomShape("smile", 2.5); // Same as above but for 2.5 seconds
randomEyes.SetCustomShapeOverride("smile", true); // Override smile
randomEyes.SetCustomShapeOverride("smile", 2.5); // Same as above but for 2.5 sec
randomEyes.SetCustomShapeBlendSpeed("smile", 3); // Smile blendSpeed to 3
randomEyes.SetCustomShapeRangeOfMotion("smile", 80); // Smile rangeOfMotion to 80
randomEyes.SetGroup("smile", true); // Activate/deactivate multi-BlendShape smile
randomEyes.SetGroup("smile", 1.5f); // Activate multi-BlendShape smile for 1.5 seconds
}
}