コード例 #1
0
 /// <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");
     }
 }
コード例 #2
0
        /// <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 (randomEyes2D.randomBlink)
                {
                    randomEyes2D.SetBlink(false);
                }
                else
                {
                    randomEyes2D.SetBlink(true);
                }
            }
            if (randomEyes2D.randomBlink)
            {
                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 (!randomEyes2D.randomBlink)
            {
                yPos += (yGap + yHeight);
                if (GUI.Button(new Rect(xPos, yPos, xWidth, yHeight), "Blink"))
                {
                    randomEyes2D.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: " + randomEyes2D.targetAffinityPercentage + "%");
            }
            else
            {
                GUI.Label(new Rect(xPos - 120, yPos, xWidth, yHeight), "Affinity Off");
            }
            if (affinitySet)
            {
                if (affinity)
                {
                    randomEyes2D.SetTargetAffinity(true);
                    randomEyes2D.SetLookTarget(target.gameObject);
                }
                else
                {
                    randomEyes2D.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)
                {
                    randomEyes2D.SetRandomEyes(false);
                    random = false;
                }
                else
                {
                    randomEyes2D.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 randomEyes2D.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, -0.5f);
            }
            else
            {
                target.transform.position = targetPosHome;
            }
            if (trackSet)
            {
                if (track)
                {
                    randomEyes2D.SetLookTarget(target.gameObject);
                }
                else
                {
                    randomEyes2D.SetLookTarget(null);
                }
                trackSet = false;
            }
            #endregion

            if (!affinity && !track)
            {
                randomEyes2D.SetLookTarget(null);
            }
        }