/// <summary>
        /// A coroutine to track a GameObject with a pre-delay and a track duration
        /// </summary>
        /// <param name="preDelay">Pre delay.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="customShapeIndex">Custom shape index.</param>
        IEnumerator Look(float preDelay, float duration, GameObject lookTarget)
        {
            yield return(new WaitForSeconds(preDelay));

            randomEyes.SetLookTarget(lookTarget);

            yield return(new WaitForSeconds(duration));

            randomEyes.SetLookTarget(null);
        }
 /// <summary>
 /// OnTriggerEnter, set the RandomEyes lookTarget to the collider GameObject
 /// </summary>
 /// <param name="col">Col.</param>
 void OnTriggerEnter(Collider col)
 {
     if (randomEyes2D)
     {
         randomEyes2D.SetLookTarget(col.gameObject);
     }
     if (randomEyes3D)
     {
         randomEyes3D.SetLookTarget(col.gameObject);
     }
     if (emitDebug)
     {
         Debug.Log(randomEyes.name + " OnTriggerEnter2D triggered");
     }
 }
Esempio n. 3
0
    void Start()
    {
        clipDir = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/lib/wavs/";
        //clipDir = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/wavs/";
        txtDir  = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/wavname.txt";
        oldTime = File.GetLastWriteTimeUtc(txtDir);
        txtfile = new WWW("file://" + txtDir);
        while (!txtfile.isDone)
        {
        }
        ;
        char ucode = '\u4e2d';

        anim = GetComponent <Animator>();
        eyes = GetComponent <RandomEyes3D>();
        eyes.SetLookTarget(cam);

        makeSalsa(txtfile.text);
    }
        /// <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);
            }
        }