Esempio n. 1
0
 void Start()
 {
     higthScore = PlayerPrefs.GetInt("HighScore");
     CurrentScore = PlayerPrefs.GetInt("currentScore");
     text = new GameObject("SomeGUIText");
     Instantiate(text);
     myText = text.AddComponent<GUIText>();
     myText.transform.position = new Vector3(0.2f,0.2f,0f);
     myText.GetComponent<GUIText> ().text = "Score: " + CurrentScore + " Meilleur score : " + higthScore;
     myText.GetComponent<GUIText> ().fontSize = 100;
     skin = Resources.Load("GUISkin") as GUISkin;
 }
Esempio n. 2
0
    public void ShowItemsForSell()
    {
        float offsetNextItem = 0f;
        for(int i = 0; i<inventory.itemList.Count; i++){

            showItem = Instantiate(textItem) as GUIText;
            showItem.GetComponent<ShowItemTextSell>().itemName = inventory.itemList[i].name;
            showItem.text = inventory.itemList[i].name +"     "+inventory.itemList[i].GetComponent<Item>().priceSell+" Gils";
            showItem.transform.parent = shop;
            showItem.transform.position += new Vector3(-0.4f, 0.4f-offsetNextItem,0f);
            showItem.transform.rotation = textItem.transform.rotation;
            showItem.transform.localScale = textItem.transform.localScale;
            offsetNextItem += 0.1f;
        }
    }
Esempio n. 3
0
 public void ShowTimeOutWarning()
 {
     //Shows the Warning Message for InActivity
     InactivityWarningMessage.GetComponent <GUIText>().enabled = true;
 }
Esempio n. 4
0
    //----------------------------------- end of public functions --------------------------------------//

    void Start()
    {
        try
        {
            // get sensor data
            KinectManager kinectManager = KinectManager.Instance;
            if (kinectManager && kinectManager.IsInitialized())
            {
                sensorData = kinectManager.GetSensorData();
            }

            if (sensorData == null || sensorData.sensorInterface == null)
            {
                throw new Exception("Background removal cannot be started, because KinectManager is missing or not initialized.");
            }

            // ensure the needed dlls are in place and speech recognition is available for this interface
            bool bNeedRestart = false;
            bool bSuccess     = sensorData.sensorInterface.IsBackgroundRemovalAvailable(ref bNeedRestart);

            if (bSuccess)
            {
                if (bNeedRestart)
                {
                    KinectInterop.RestartLevel(gameObject, "BR");
                    return;
                }
            }
            else
            {
                string sInterfaceName = sensorData.sensorInterface.GetType().Name;
                throw new Exception(sInterfaceName + ": Background removal is not supported!");
            }

            // Initialize the background removal
            bSuccess = sensorData.sensorInterface.InitBackgroundRemoval(sensorData, colorCameraResolution);

            if (!bSuccess)
            {
                throw new Exception("Background removal could not be initialized.");
            }

            // create the foreground image and alpha-image
            int imageLength = sensorData.sensorInterface.GetForegroundFrameLength(sensorData, colorCameraResolution);
            foregroundImage = new byte[imageLength];

            // get the needed rectangle
            Rect neededFgRect = sensorData.sensorInterface.GetForegroundFrameRect(sensorData, colorCameraResolution);

            // create the foreground texture
            foregroundTex = new Texture2D((int)neededFgRect.width, (int)neededFgRect.height, TextureFormat.RGBA32, false);

            // calculate the foreground rectangle
            if (foregroundCamera != null)
            {
                Rect  cameraRect = foregroundCamera.pixelRect;
                float rectHeight = cameraRect.height;
                float rectWidth  = cameraRect.width;

                if (rectWidth > rectHeight)
                {
                    rectWidth = Mathf.Round(rectHeight * neededFgRect.width / neededFgRect.height);
                }
                else
                {
                    rectHeight = Mathf.Round(rectWidth * neededFgRect.height / neededFgRect.width);
                }

                foregroundRect = new Rect((cameraRect.width - rectWidth) / 2, cameraRect.height - (cameraRect.height - rectHeight) / 2, rectWidth, -rectHeight);
            }

            instance   = this;
            isBrInited = true;

            //DontDestroyOnLoad(gameObject);
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and BR-Library installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }
Esempio n. 5
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

            int iJointIndex = (int)TrackedJoint;

            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);

                    if (posJoint != Vector3.zero)
                    {
                        // 3d position to depth
                        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                        // depth pos to color pos
                        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

//						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
//						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                        if (debugText)
                        {
                            debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId;                             // new Vector2(scaleX, scaleY).ToString();
                        }

                        if (OverlayObject)
                        {
                            Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));
                            OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, 1.0f);
                            float y = OverlayObject.transform.position.y;
                            float x = OverlayObject.transform.position.x;

                            /*
                             * if (OverlayObject.transform.position.y < 2.0f)
                             * {
                             *  y = 2.0f;
                             * }
                             *
                             * if(x < -5.0f)
                             * {
                             *  x = -5.0f;
                             * }
                             * else if(x > 5.0f)
                             * {
                             *  x = 5.0f;
                             * }
                             */
                            Vector3 pos = new Vector3((x - prevTrans.x) * x_translation_intensity, (y - prevTrans.y) * y_translation_intensity, 0f);
                            ////////////////cam.transform.position = Vector3.Lerp(prevTrans, pos, 1.0f);
                            //OverlayObject.transform.position = new Vector3(x - prevTrans.x, y - prevTrans.y, OverlayObject.transform.position.z);
                            cam.transform.Translate(pos);
                            prevTrans = OverlayObject.transform.position;

                            cam.transform.rotation = Quaternion.Euler(new Vector3(OverlayObject.transform.position.y * y_rotation_intensity, -OverlayObject.transform.position.x * x_rotation_intensity, 0));

                            //OverlayObject.transform.rotation = Quaternion.Euler(new Vector3(OverlayObject.transform.position.y * y_rotation_intensity, -OverlayObject.transform.position.x * x_rotation_intensity, 0));
                            //Vector3 rot = new Vector3((OverlayObject.transform.position.y - prevRot.y) * y_rotation_intensity, (-OverlayObject.transform.position.x + -prevRot.x) * x_rotation_intensity, 0);
                            //OverlayObject.transform.Rotate(new Vector3(OverlayObject.transform.rotation.y - prevRot.y, OverlayObject.transform.rotation.x - prevRot.x, 0));
                        }
                    }
                }
            }
        }
    }
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

            int iJointIndex = (int)TrackedJoint;

            //Kinectで誰かひとりよみこめたらtrue
            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();

                // ID1の人の右手が追跡されていたらtrue
                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);

                    // posJointの位置が(0,0,0)だったらtrue
                    if (posJoint != Vector3.zero)
                    {
                        // 3d position to depth
                        // 深さへの3D位置
                        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                        // depth pos to color pos
                        // 色位置への深さ位置
                        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                        // 色位置への深さ位置のx/Kinectのワイド
                        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

//						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
//						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                        if (debugText)
                        {
                            debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId;                             // new Vector2(scaleX, scaleY).ToString();
                        }

                        if (OverlayObject)
                        {
                            Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));

                            // オブジェクトの場所=ベクトル二点間の補間(ゲームオブジェクトにアタッチされているTransform,ひとつ前の行で求めた位置,5f*最後のフレームを完了するのに要した時間)
                            OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime);
                        }
                    }
                }
            }
        }
    }
    //----------------------------------- end of public functions --------------------------------------//


    void Start()
    {
        try
        {
            // get sensor data
            KinectManager kinectManager = KinectManager.Instance;
            if (kinectManager && kinectManager.IsInitialized())
            {
                sensorData = kinectManager.GetSensorData();
            }

            if (sensorData == null || sensorData.sensorInterface == null)
            {
                throw new Exception("Face tracking cannot be started, because KinectManager is missing or not initialized.");
            }

            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please, wait...";
            }

            // ensure the needed dlls are in place and face tracking is available for this interface
            bool bNeedRestart = false;
            if (sensorData.sensorInterface.IsFaceTrackingAvailable(ref bNeedRestart))
            {
                if (bNeedRestart)
                {
                    KinectInterop.RestartLevel(gameObject, "FM");
                    return;
                }
            }
            else
            {
                string sInterfaceName = sensorData.sensorInterface.GetType().Name;
                throw new Exception(sInterfaceName + ": Face tracking is not supported!");
            }

            // Initialize the face tracker
            if (!sensorData.sensorInterface.InitFaceTracking(getFaceModelData, displayFaceRect))
            {
                throw new Exception("Face tracking could not be initialized.");
            }

            instance = this;
            isFacetrackingInitialized = true;

            //DontDestroyOnLoad(gameObject);

            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Ready.";
            }
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and FT-Library installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }
    void Start()
#endif
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        });

        webViewObject.SetMargins(5, 5, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);

        switch (Application.platform)
        {
#if !UNITY_WEBPLAYER
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.IPhonePlayer:
        case RuntimePlatform.Android:
            if (Url.StartsWith("http"))
            {
                webViewObject.LoadURL(Url.Replace(" ", "%20"));
            }
            else
            {
                var src    = System.IO.Path.Combine(Application.streamingAssetsPath, Url);
                var dst    = System.IO.Path.Combine(Application.persistentDataPath, Url);
                var result = "";
                if (src.Contains("://"))
                {
                    var www = new WWW(src);
                    yield return(www);

                    result = www.text;
                }
                else
                {
                    result = System.IO.File.ReadAllText(src);
                }
                System.IO.File.WriteAllText(dst, result);
                webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
            }
            if (Application.platform != RuntimePlatform.Android)
            {
                webViewObject.EvaluateJS(
                    "window.addEventListener('load', function() {" +
                    "	window.Unity = {"+
                    "		call:function(msg) {"+
                    "			var iframe = document.createElement('IFRAME');"+
                    "			iframe.setAttribute('src', 'unity:' + msg);"+
                    "			document.documentElement.appendChild(iframe);"+
                    "			iframe.parentNode.removeChild(iframe);"+
                    "			iframe = null;"+
                    "		}"+
                    "	}"+
                    "}, false);");
            }
            break;
#else
        case RuntimePlatform.OSXWebPlayer:
        case RuntimePlatform.WindowsWebPlayer:
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
            webViewObject.EvaluateJS(
                "parent.$(function() {" +
                "	window.Unity = {"+
                "		call:function(msg) {"+
                "			parent.unityWebView.sendMessage('WebViewObject', msg)"+
                "		}"+
                "	};"+
                "});");
            break;
#endif
        }
    }
Esempio n. 9
0
    void Update()
    {
        if (this.tag == "focusBlock")
        {
//			Debug.Log ("focusBlock");
            print("Score " + score);
            rend.material = focus;
        }
        else
        {
            rend.material = normal;
        }

        KinectManager km        = KinectManager.Instance;
        uint          Player1ID = km.GetPlayer1ID();

        if (active)
        {
            if (transform.position.x > rightLimit)
            {
                direction = -1;
            }
            else if (transform.position.x < leftLimit)
            {
                direction = 1;
            }
            var movement = Vector3.right * direction * speed * Time.deltaTime;
            transform.Translate(movement);

            if (Input.GetKeyDown("space") || (Player1ID != 0 && km.IsGestureComplete(Player1ID, KinectGestures.Gestures.Jump, false)))
            {
                if (Physics.CheckBox(this.transform.position - new Vector3(0, 1f, 0),
                                     new Vector3((gameObject.transform.localScale.x) / 2f, .1f, .5f), Quaternion.identity))
                {
                    Collider[] these = Physics.OverlapBox(this.transform.position - new Vector3(0, 1f, 0),
                                                          new Vector3((gameObject.transform.localScale.x) / 2f, .1f, .5f), Quaternion.identity);

                    float rightEdgeOver = (gameObject.transform.position.x + (gameObject.transform.localScale.x) / 2f) -
                                          (these [0].transform.position.x + (these [0].transform.localScale.x) / 2f);
                    float leftEdgeOver = (gameObject.transform.position.x - (gameObject.transform.localScale.x) / 2f) -
                                         (these [0].transform.position.x - (these [0].transform.localScale.x) / 2f);
                    //Debug.Log (rightEdgeOver);
                    //float diff = these [0].transform.position.x - gameObject.transform.position.x;

                    if (rightEdgeOver > 0)
                    {
                        gameObject.transform.localScale -= new Vector3(Mathf.Abs(rightEdgeOver), 0, 0);
                        gameObject.transform.position   -= new Vector3(Mathf.Abs(rightEdgeOver) / 2f, 0, 0);
                    }
                    else
                    {
                        gameObject.transform.localScale -= new Vector3(Mathf.Abs(leftEdgeOver), 0, 0);
                        gameObject.transform.position   += new Vector3(Mathf.Abs(leftEdgeOver) / 2f, 0, 0);
                    }
                    scoreText.GetComponent <GUIText> ().text = "";
                    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.AddComponent <AutoMove> ();
                    cube.transform.localScale = gameObject.transform.localScale;
                    cube.transform.position   = this.transform.position + new Vector3(0, 1, 0);
                    // set properties of AutoMove script in new b
                    cube.GetComponent <AutoMove> ().normal = normal;
                    cube.GetComponent <AutoMove> ().focus  = focus;
                    cube.GetComponent <AutoMove> ().setScore(score + 1);
                    cube.GetComponent <AutoMove> ().scoreText = scoreText;
                    this.tag = "Untagged";
                }

                active = false;
            }
        }
    }
Esempio n. 10
0
    //----------------------------------- end of public functions --------------------------------------//


    void Start()
    {
        try
        {
            // get sensor data
            KinectManager kinectManager = KinectManager.Instance;
            if (kinectManager && kinectManager.IsInitialized())
            {
                sensorData = kinectManager.GetSensorData();
            }

            if (sensorData == null || sensorData.sensorInterface == null)
            {
                throw new Exception("Speech recognition cannot be started, because KinectManager is missing or not initialized.");
            }

            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please, wait...";
            }

            // ensure the needed dlls are in place and speech recognition is available for this interface
            bool bNeedRestart = false;
            if (sensorData.sensorInterface.IsSpeechRecognitionAvailable(ref bNeedRestart))
            {
                if (bNeedRestart)
                {
                    KinectInterop.RestartLevel(gameObject, "SM");
                    return;
                }
            }
            else
            {
                string sInterfaceName = sensorData.sensorInterface.GetType().Name;
                throw new Exception(sInterfaceName + ": Speech recognition is not supported!");
            }

            // Initialize the speech recognizer
            string sCriteria = String.Format("Language={0:X};Kinect=True", languageCode);
            int    rc        = sensorData.sensorInterface.InitSpeechRecognition(sCriteria, true, false);
            if (rc < 0)
            {
                string sErrorMessage = (new SpeechErrorHandler()).GetSapiErrorMessage(rc);
                throw new Exception(String.Format("Error initializing Kinect/SAPI: " + sErrorMessage));
            }

            if (requiredConfidence > 0)
            {
                sensorData.sensorInterface.SetSpeechConfidence(requiredConfidence);
            }

            if (grammarFileName != string.Empty)
            {
                // copy the grammar file from Resources, if available
                if (!File.Exists(grammarFileName))
                {
                    TextAsset textRes = Resources.Load(grammarFileName, typeof(TextAsset)) as TextAsset;

                    if (textRes != null)
                    {
                        string sResText = textRes.text;
                        File.WriteAllText(grammarFileName, sResText);
                    }
                }

                // load the grammar file
                rc = sensorData.sensorInterface.LoadSpeechGrammar(grammarFileName, (short)languageCode, dynamicGrammar);
                if (rc < 0)
                {
                    string sErrorMessage = (new SpeechErrorHandler()).GetSapiErrorMessage(rc);
                    throw new Exception("Error loading grammar file " + grammarFileName + ": " + sErrorMessage);
                }

//				// test dynamic grammar phrases
//				rc = sensorData.sensorInterface.AddGrammarPhrase("addressBook", string.Empty, "Nancy Anderson", true, false);
//				rc = sensorData.sensorInterface.AddGrammarPhrase("addressBook", string.Empty, "Cindy White", false, false);
//				rc = sensorData.sensorInterface.AddGrammarPhrase("addressBook", string.Empty, "Oliver Lee", false, false);
//				rc = sensorData.sensorInterface.AddGrammarPhrase("addressBook", string.Empty, "Alan Brewer", false, false);
//				rc = sensorData.sensorInterface.AddGrammarPhrase("addressBook", string.Empty, "April Reagan", false, true);
            }

            instance        = this;
            sapiInitialized = true;

            //DontDestroyOnLoad(gameObject);

            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Ready.";
            }
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and SAPI installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }
Esempio n. 11
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        manager.smoothing = KinectManager.Smoothing.None;



        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

            int iJointIndex             = (int)TrackedJoint;
            int iJointIndexSholderRight = (int)TrackedJointShoulderRight;
            int iJointIndexSholderLeft  = (int)TrackedJointShoulderLeft;

            if (manager.IsUserDetected())
            {
                /*if (throwListener)
                 * {
                 *  if (throwListener.IsSwipeLeft())
                 *  {
                 *      OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, new Vector3(5, 1), smoothFactor * Time.deltaTime);
                 *      this.ballThrew = true;
                 *  }
                 * }*/

                uint userId = manager.GetPlayer1ID();


                this.userHandPos          = manager.GetRawSkeletonJointPos(userId, iJointIndex);
                this.userShoulderRightPos = manager.GetRawSkeletonJointPos(userId, iJointIndexSholderRight);
                this.userShoulderLeftPos  = manager.GetRawSkeletonJointPos(userId, iJointIndexSholderLeft);

                this.timestamp = Time.realtimeSinceStartup;



                if (!isThrow)
                {
                    this.textbox.info = "Wykonaj gest rzutu prawa reka.";
                    isThrow           = FindThrow();
                }

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);

                    if (posJoint != Vector3.zero)
                    {
                        // 3d position to depth
                        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                        // depth pos to color pos

                        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;


//						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
//						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                        if (debugText)
                        {
                            debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId;                             // new Vector2(scaleX, scaleY).ToString();
                        }

                        if (throwListener.IsRiseLeftHand())
                        {
                            this.ballThrew = false;
                            this.state     = 0;
                            this.isThrow   = false;

                            this.oldSpeed = 0;


                            this.textbox.info = "Wykonaj gest rzutu prawa reka.";
                        }



                        if (!ballThrew && throwListener)
                        {
                            //kiedy nie wykonano rzutu i widzi obiekt
                            if (OverlayObject)
                            {
                                //ustalanie pozycji kuli na ekranie na podstawie pozycji dloni
                                Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, (posJoint.z * (-1) + 3)));
                                //przesuniecie kuli pomiedzy pozycjami z t-1 a t
                                OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime);
                            }
                            //kiedy wykonano gest rzutu
                            if (isThrow)
                            {
                                //wlaczenie grawitacji - oderwanie pilki od reki
                                OverlayObject.GetComponent <Rigidbody>().useGravity = true;
                                this.acceleration = 2;
                                //nadanie pilce przedkosci w pojedynczej klatce
                                OverlayObject.GetComponent <Rigidbody>().AddForce(this.speedx * this.acceleration, this.speedy * this.acceleration, Mathf.Abs(this.speedz) * this.acceleration, ForceMode.VelocityChange);
                                //wartosci pogladowe
                                this.oldBallPos   = OverlayObject.GetComponent <Rigidbody>().position;
                                this.oldTimestamp = this.timestamp;
                                this.ballThrew    = true;
                            }
                        }
                        //jezeli wykonano gest rzutu
                        // Debug.Log(isDistanceFound);
                        if (ballThrew && this.state != 4)
                        {
                            //wartosci pogladowe
                            float ballDis   = Vector3.Distance(this.oldBallPos, OverlayObject.GetComponent <Rigidbody>().position);
                            float ts        = this.timestamp - this.oldTimestamp;
                            float actualDis = Vector2.Distance(this.startBallPos, new Vector2(OverlayObject.GetComponent <Rigidbody>().position.x, OverlayObject.GetComponent <Rigidbody>().position.z));
                            this.oldTimestamp = this.timestamp;
                            float Dx = OverlayObject.GetComponent <Rigidbody>().position.x - oldBallPos.x;
                            float Dy = OverlayObject.GetComponent <Rigidbody>().position.y - oldBallPos.y;
                            float Dz = OverlayObject.GetComponent <Rigidbody>().position.z - oldBallPos.z;
                            this.oldBallPos = OverlayObject.GetComponent <Rigidbody>().position;
                            float ballSpeed = ballDis / ts;
                            Debug.Log("Czas = " + timestamp + "\n" +
                                      "x = " + OverlayObject.GetComponent <Rigidbody>().position.x + "\n" +
                                      "y = " + OverlayObject.GetComponent <Rigidbody>().position.y + "\n" +
                                      "z = " + OverlayObject.GetComponent <Rigidbody>().position.z + "\n" +
                                      "startz = " + startBallPos.x + "\n" +
                                      "starty = " + startBallPos.y + "\n" +

                                      "Dx = " + Dx + "\n" +
                                      "Dy = " + Dy + "\n" +
                                      "Dz = " + Dz + "\n" +
                                      "speed = " + ballSpeed + "\n" +
                                      "ballDis = " + ballDis + "\n" +
                                      "actualDis = " + actualDis + "\n" +
                                      "ts = " + ts);

                            this.textbox.info = "predkosc wyrzutu: " + (this.acceleration * oldSpeed).ToString("#0.0#;(#0.0#);-\0-") + "m/s \n" +
                                                "odleglosc rzutu: " + actualDis.ToString("#0.0#;(#0.0#);-\0-") + "m \n" +
                                                "kat wyrzutu: " + this.angle.ToString("#0.0#;(#0.0#);-\0-") + "\n";
                            if (OverlayObject.transform.position.y < 0.2)
                            {
                                //wylaczenie grawitacji i wyhamowanie pilki
                                OverlayObject.GetComponent <Rigidbody>().useGravity = false;
                                OverlayObject.transform.position = new Vector3(OverlayObject.GetComponent <Rigidbody>().position.x, (float)0.2, OverlayObject.GetComponent <Rigidbody>().position.z);
                                Rigidbody.velocity = Vector3.zero;
                                this.state         = 4;
                                textbox.info      += "Aby wykonac rzut ponownie, unies lewa reke";
                            }
                        }
                    }
                }
            }
            else if (this.state < 3)
            {
                this.textbox.info = "";
            }
        }
    }
Esempio n. 12
0
	/// <summary>
	/// Creates the dialog objects.
	/// </summary>
	public void createDialogObjects() {

		dialogSpeakerText = Instantiate(dialogSpeakerText) as GUIText;
		dialogSpeakerText.transform.position = speakerTextPos;
		
		dialogText = Instantiate(dialogText) as GUIText;
		dialogText.transform.position = dialogTextPos;
		dialogTextWrapper = dialogText.GetComponent<WordWrapText>();

		textBox = Instantiate(textBox) as Transform;
		textBox.transform.parent = GameObject.Find("Main Camera").transform;
		textBox.transform.localPosition = textBoxPos;


		dialogNextText = Instantiate(dialogNextText) as GUIText;
		dialogNextText.transform.position = dialogNextTextPos;

	}
Esempio n. 13
0
 void SetCountText()
 {
     myText.GetComponent <GUIText>().text = "Score: " + score;
 }
Esempio n. 14
0
 public static void UpdateScore()
 {
     score++;
     scoreText.GetComponent <Text>().text = $"{score}";
     scoreText.text = $"  Score: {score}";
 }
Esempio n. 15
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

            int iJointIndex      = (int)TrackedJoint;
            int ihombroDerecho   = (int)hombroDerecho;
            int ihombroIzquierdo = (int)hombroIzquierdo;
            int ihombroCentro    = (int)hombroCentro;
            int icaderaIzquierdo = (int)caderaIzquierdo;
            int icaderaDerecho   = (int)caderaDerecho;

            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();

                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);

                    Vector3 posHombroDerecho   = manager.GetRawSkeletonJointPos(userId, ihombroDerecho);
                    Vector3 posHombroIzquierdo = manager.GetRawSkeletonJointPos(userId, ihombroIzquierdo);
                    Vector3 posHombroCentro    = manager.GetRawSkeletonJointPos(userId, ihombroCentro);
                    Vector3 posCaderaIzquierdo = manager.GetRawSkeletonJointPos(userId, icaderaIzquierdo);
                    Vector3 posCaderaDerecho   = manager.GetRawSkeletonJointPos(userId, icaderaDerecho);

                    Vector3 ejex = posHombroDerecho - posHombroIzquierdo;
                    Vector3 ejey = posHombroDerecho - posCaderaDerecho;

                    //Debug.Log("distancia en x" + ejex);
                    //Debug.Log("distancia en y" + ejey);

                    if (posJoint != Vector3.zero)
                    {
                        // 3d position to depth
                        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                        // depth pos to color pos
                        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

//						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
//						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                        if (debugText)
                        {
                            debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId;                             // new Vector2(scaleX, scaleY).ToString();
                        }

                        if (OverlayObject)
                        {
                            Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));
                            vPosOverlay.y = vPosOverlay.y + 1f;
                            OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime);



                            OverlayObject.transform.localScale = new Vector3(Mathf.Abs(ejex.x) * 18, Mathf.Abs(ejey.y) * 18, 2);
                            //Debug.Log("scala" + OverlayObject.transform.localScale);
                        }
                    }
                }
            }
        }
    }
    // scales the avatar as needed
    public void ScaleAvatar(float fSmooth)
    {
//		KinectManager manager = KinectManager.Instance;
//		if(!manager)
//			return;
//
//		if(fSmooth != 0f && manager.IsUserTurnedAround(currentUserId))
//			return;

        // scale body
        SetupBoneScale(bodyScaleTransform, modelBodyScale, modelBodyHeight,
                       bodyHeight, 0f, fSmooth, ref fScaleBody);

        // scale arms
        float fLeftUpperArmLength = !mirroredAvatar ? leftUpperArmLength : rightUpperArmLength;

        SetupBoneScale(leftShoulderScaleTransform, modelLeftShoulderScale, modelLeftUpperArmLength,
                       fLeftUpperArmLength, fScaleBody, fSmooth, ref fScaleLeftUpperArm);

        float fLeftLowerArmLength = !mirroredAvatar ? leftLowerArmLength : rightLowerArmLength;

        SetupBoneScale(leftElbowScaleTransform, modelLeftElbowScale, modelLeftLowerArmLength,
                       fLeftLowerArmLength, fScaleLeftUpperArm, fSmooth, ref fScaleLeftLowerArm);

        float fRightUpperArmLength = !mirroredAvatar ? rightUpperArmLength : leftUpperArmLength;

        SetupBoneScale(rightShoulderScaleTransform, modelRightShoulderScale, modelRightUpperArmLength,
                       fRightUpperArmLength, fScaleBody, fSmooth, ref fScaleRightUpperArm);

        float fRightLowerArmLength = !mirroredAvatar ? rightLowerArmLength : leftLowerArmLength;

        SetupBoneScale(rightElbowScaleTransform, modelRightElbowScale, modelLeftLowerArmLength,
                       fRightLowerArmLength, fScaleRightUpperArm, fSmooth, ref fScaleRightLowerArm);

        // scale legs
        float fLeftUpperLegLength = !mirroredAvatar ? leftUpperLegLength : rightUpperLegLength;

        SetupBoneScale(leftHipScaleTransform, modelLeftHipScale, modelLeftUpperLegLength,
                       fLeftUpperLegLength, fScaleBody, fSmooth, ref fScaleLeftUpperLeg);

        float fLeftLowerLegLength = !mirroredAvatar ? leftLowerLegLength : rightLowerLegLength;

        SetupBoneScale(leftKneeScaleTransform, modelLeftKneeScale, modelLeftLowerLegLength,
                       fLeftLowerLegLength, fScaleLeftUpperLeg, fSmooth, ref fScaleLeftLowerLeg);

        float fRightUpperLegLength = !mirroredAvatar ? rightUpperLegLength : leftUpperLegLength;

        SetupBoneScale(rightHipScaleTransform, modelRightHipScale, modelRightUpperLegLength,
                       fRightUpperLegLength, fScaleBody, fSmooth, ref fScaleRightUpperLeg);

        float fRightLowerLegLength = !mirroredAvatar ? rightLowerLegLength : leftLowerLegLength;

        SetupBoneScale(rightKneeScaleTransform, modelRightKneeScale, modelRightLowerLegLength,
                       fRightLowerLegLength, fScaleRightUpperLeg, fSmooth, ref fScaleRightLowerLeg);

        if (debugText != null)
        {
            string sDebug = string.Format("B: {0:F3}\nULA: {1:F3}, LLA: {2:F3}; RUA: {3:F3}, RLA: {4:F3}\nLUL: {5:F3}, LLL: {6:F3}; RUL: {7:F3}, RLL: {8:F3}",
                                          fScaleBody, fScaleLeftUpperArm, fScaleLeftLowerArm,
                                          fScaleRightUpperArm, fScaleRightLowerArm,
                                          fScaleLeftUpperLeg, fScaleLeftLowerLeg,
                                          fScaleRightUpperLeg, fScaleRightLowerLeg);
            debugText.GetComponent <GUIText>().text = sDebug;
        }
    }
Esempio n. 17
0
    void Update()
    {
        // dont run Update() if there is no gesture listener
        if (!gestureListener)
        {
            return;
        }

        if (!gestureListener.currentUser())
        {
            timerOn = true;
        }
        else
        {
            timerOn       = false;
            timeForAUser += Time.deltaTime;
        }

        if (timerOn)
        {
            timeNoUser += Time.deltaTime;
        }

        if (timeNoUser > 5)
        {
            whichMoviePlaying = 11;
            Debug.Log("This user spent " + timeForAUser.ToString("n2") + " seconds in the space");
            timeForAUser = 0;
            timeNoUser   = 0;
        }
        //videoInfo.GetComponent<GUIText>().text = leanRightCount.ToString();
        if (whichMoviePlaying == 1)
        {
            if (movieC1.isPlaying)
            {
                CaptureGuestures();
                sp.Write("A");
            }
            else
            {
                ClipEndAction(1, movieA1, movieB1, 1);
            }
        }
        else if (whichMoviePlaying == 2)
        {
            if (!movieA1.isPlaying && !movieB1.isPlaying)
            {
                playMovie(movieC2);
                whichMoviePlaying = 3;
            }
        }
        else if (whichMoviePlaying == 3)
        {
            if (movieC2.isPlaying)
            {
                sp.Write("F");
                CaptureGuestures();
            }
            else
            {
                //CompletelyEndAction();
                ClipEndAction(3, movieA2, movieB2, 2);
            }
        }
        else if (whichMoviePlaying == 4)
        {
            if (!movieA2.isPlaying && !movieB2.isPlaying)
            {
                playMovie(movieC3);
                whichMoviePlaying = 5;
            }
        }
        else if (whichMoviePlaying == 5)
        {
            if (movieC3.isPlaying)
            {
                sp.Write("F");
                CaptureGuestures();
            }
            else
            {
                ClipEndActionWithMovieD(5, movieA3, movieB3, movieD1, 3);
            }
        }
        else if (whichMoviePlaying == 6)
        {
            if (!movieA3.isPlaying && !movieB3.isPlaying && !movieD1.isPlaying)
            {
                playMovie(movieC4);
                whichMoviePlaying = 7;
            }
        }
        else if (whichMoviePlaying == 7)
        {
            if (movieC4.isPlaying)
            {
                sp.Write("F");
                CaptureGuestures();
            }
            else
            {
                ClipEndActionWithMovieD(7, movieA4, movieB4, movieD2, 4);
            }
        }
        else if (whichMoviePlaying == 8)
        {
            if (!movieA4.isPlaying && !movieB4.isPlaying && !movieD2.isPlaying)
            {
                playMovie(movieC5);
                whichMoviePlaying = 9;
            }
        }
        else if (whichMoviePlaying == 9)
        {
            if (movieC5.isPlaying)
            {
                sp.Write("F");
                CaptureGuestures();
            }
            else
            {
                ClipEndActionWithMovieD(9, movieA5, movieB5, movieD3, 5);
            }
        }
        else if (whichMoviePlaying == 10)
        {
            if (!movieA5.isPlaying && !movieB5.isPlaying && !movieD3.isPlaying)
            {
                playMovie(movieC6);
                whichMoviePlaying = 11;
            }
        }
        else if (whichMoviePlaying == 11)
        {
            if (!movieC6.isPlaying)
            {
                playMovie(endBlack);
                whichMoviePlaying = 12;
            }
            else
            {
                sp.Write("A");
            }
        }
        else if (whichMoviePlaying == 12)
        {
            if (!endBlack.isPlaying)
            {
                CompletelyEndAction();
            }
            else
            {
                gestureListener.ResetGesture();
            }
        }

        /*
         * else if (whichMoviePlaying == 12)
         * {
         *   if (!movieA6.isPlaying && !movieB6.isPlaying)
         *   {
         *       playMovie(movieC7);
         *       whichMoviePlaying = 13;
         *   }
         * }
         *
         * else if(whichMoviePlaying == 13)
         * {
         *   if (!movieC7.isPlaying)
         *   {
         *       CompletelyEndAction();
         *   }
         * }
         */

        // Keyboard events

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Jumping to start");
            branchIndex = 0;
            videoInfo.GetComponent <GUIText>().text = " ";
            ResetCounts();
            playMovie(endBlack);
            whichMoviePlaying = 12;
            branchList        = "";
            backgroundAudio.Stop();
            backgroundAudio.Play();
        }

        else if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        /* else if (Input.GetKeyDown(KeyCode.Return))
         * {
         *  GetComponent<RawImage>().texture = movie1 as MovieTexture;
         *  movie1.Play();
         * }
         */
    }
Esempio n. 18
0
    IEnumerator Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            ld: (msg) =>
        {
            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
        },
            enableWKWebView: true);
        webViewObject.SetMargins(5, 100, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);

#if !UNITY_WEBPLAYER
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            var exts = new string[] {
                ".jpg",
                ".html"  // should be last
            };
            foreach (var ext in exts)
            {
                var    url    = Url.Replace(".html", ext);
                var    src    = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var    dst    = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://"))    // for Android
                {
                    var www = new WWW(src);
                    yield return(www);

                    result = www.bytes;
                }
                else
                {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html")
                {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }
#if !UNITY_ANDROID
        webViewObject.EvaluateJS(
            "window.addEventListener('load', function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           var iframe = document.createElement('IFRAME');" +
            "           iframe.setAttribute('src', 'unity:' + msg);" +
            "           document.documentElement.appendChild(iframe);" +
            "           iframe.parentNode.removeChild(iframe);" +
            "           iframe = null;" +
            "       }" +
            "   }" +
            "}, false);");
#endif
#else
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
        webViewObject.EvaluateJS(
            "parent.$(function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "       }" +
            "   };" +
            "});");
#endif
        yield break;
    }
Esempio n. 19
0
 private void update()
 {
     text = temp1 + "      " + temp2 + "       " + temp3 + "      " + temp4;
     gt.GetComponent <GUIText>().text = text;
 }
Esempio n. 20
0
 // Use this for initialization
 void Start()
 {
     onScreenMessage.GetComponent <OnCameraMessage>().appearing = false;
 }
Esempio n. 21
0
 // Use this for initialization
 void Start()
 {
     g.GetComponent <GUIText>().text = "HOLD TO\nGO " + s;
 }
Esempio n. 22
0
    void OnGUI()
    {
        if (!interactionInited)
        {
            return;
        }

        // display debug information
        if (debugText)
        {
            string sGuiText = string.Empty;

            //if(isLeftHandPrimary)
            {
                sGuiText += "LCursor" + (isLeftHandPrimary ? "*: " : " : ") + leftHandScreenPos.ToString();

                if (lastLeftHandEvent == HandEventType.Grip)
                {
                    sGuiText += "  LeftGrip";
                }
                else if (lastLeftHandEvent == HandEventType.Release)
                {
                    sGuiText += "  LeftRelease";
                }

                if (isLeftHandClick)
                {
                    sGuiText += "  LeftClick";
                }
//				else if(leftHandClickProgress > 0.5f)
//				{
//					sGuiText += String.Format("  {0:F0}%", leftHandClickProgress * 100);
//				}

                if (isLeftHandPress)
                {
                    sGuiText += "  LeftPress";
                }
            }

            //if(isRightHandPrimary)
            {
                sGuiText += "\nRCursor" + (isRightHandPrimary ? "*: " : " : ") + rightHandScreenPos.ToString();

                if (lastRightHandEvent == HandEventType.Grip)
                {
                    sGuiText += "  RightGrip";
                }
                else if (lastRightHandEvent == HandEventType.Release)
                {
                    sGuiText += "  RightRelease";
                }

                if (isRightHandClick)
                {
                    sGuiText += "  RightClick";
                }
//				else if(rightHandClickProgress > 0.5f)
//				{
//					sGuiText += String.Format("  {0:F0}%", rightHandClickProgress * 100);
//				}

                if (isRightHandPress)
                {
                    sGuiText += "  RightPress";
                }
            }

            debugText.GetComponent <GUIText>().text = sGuiText;
        }

        // display the cursor status and position
        if (useHandCursor)
        {
            Texture texture = null;

            if (isLeftHandPrimary)
            {
                if (lastLeftHandEvent == HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastLeftHandEvent == HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }
            else if (isRightHandPrimary)
            {
                if (lastRightHandEvent == HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastRightHandEvent == HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }

            if (texture == null)
            {
                texture = normalHandTexture;
            }

            if (useHandCursor)
            {
                if ((texture != null) && (isLeftHandPrimary || isRightHandPrimary))
                {
                    Rect rectTexture;
//					rectTexture = new Rect(cursorScreenPos.x * Screen.width - texture.width / 2, (1f - cursorScreenPos.y) * Screen.height - texture.height / 2,
//					                       texture.width, texture.height);
//
//					if(controlMouseCursor)
//					{
//						MouseControl.MouseMove(cursorScreenPos, debugText);
//					}

                    if (controlMouseCursor)
                    {
                        MouseControl.MouseMove(cursorScreenPos, debugText);
                        rectTexture = new Rect(Input.mousePosition.x - texture.width / 2, Screen.height - Input.mousePosition.y - texture.height / 2,
                                               texture.width, texture.height);
                    }
                    else
                    {
                        rectTexture = new Rect(cursorScreenPos.x * Screen.width - texture.width / 2, (1f - cursorScreenPos.y) * Screen.height - texture.height / 2,
                                               texture.width, texture.height);
                        //	Rect rectTexture = new Rect(cursorScreenPos.x * Screen.width, (1f - cursorScreenPos.y) * Screen.height, texture.width, texture.height);
                    }

                    GUI.DrawTexture(rectTexture, texture);
                }
            }
        }
    }
Esempio n. 23
0
    void OnGUI()
    {
        if (!interactionInited)
        {
            return;
        }

        // display debug information
        if (debugText)
        {
            string sGuiText = string.Empty;

            if (isRightHandPrimary)
            {
                sGuiText += "Cursor: " + cursorScreenPos.ToString();

                if (lastRightHandEvent == HandEventType.Grip)
                {
                    sGuiText += "  RightGrip";
                }
                else if (lastRightHandEvent == HandEventType.Release)
                {
                    sGuiText += "  RightRelease";
                }

                if (isRightHandClick)
                {
                    sGuiText += "  RightClick";
                }
//				else if(rightHandClickProgress > 0.5f)
//				{
//					sGuiText += String.Format("  {0:F0}%", rightHandClickProgress * 100);
//				}

                if (isRightHandPress)
                {
                    sGuiText += "  RightPress";
                }
            }

            if (isLeftHandPrimary)
            {
                sGuiText = "Cursor: " + cursorScreenPos.ToString();

                if (lastLeftHandEvent == HandEventType.Grip)
                {
                    sGuiText += "  LeftGrip";
                }
                else if (lastLeftHandEvent == HandEventType.Release)
                {
                    sGuiText += "  LeftRelease";
                }

                if (isLeftHandClick)
                {
                    sGuiText += "  LeftClick";
                }
//				else if(leftHandClickProgress > 0.5f)
//				{
//					sGuiText += String.Format("  {0:F0}%", leftHandClickProgress * 100);
//				}

                if (isLeftHandPress)
                {
                    sGuiText += "  LeftPress";
                }
            }

            debugText.GetComponent <GUIText>().text = sGuiText;
        }

        // display the cursor status and position
        if (useHandCursor)
        {
            Texture texture = null;

            if (isLeftHandPrimary)
            {
                if (lastLeftHandEvent == HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastLeftHandEvent == HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }
            else if (isRightHandPrimary)
            {
                if (lastRightHandEvent == HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastRightHandEvent == HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }

            if (texture == null)
            {
                texture = normalHandTexture;
            }

            if (useHandCursor)
            {
//				if(handCursor.guiTexture && texture)
//				{
//					handCursor.guiTexture.texture = texture;
//				}

                if ((texture != null) && (isLeftHandPrimary || isRightHandPrimary))
                {
                    //handCursor.transform.position = cursorScreenPos; // Vector3.Lerp(handCursor.transform.position, cursorScreenPos, 3 * Time.deltaTime);
                    Rect rectTexture = new Rect(cursorScreenPos.x * Screen.width - texture.width / 2, (1f - cursorScreenPos.y) * Screen.height - texture.height / 2,
                                                texture.width, texture.height);
                    GUI.DrawTexture(rectTexture, texture);

                    if (controlMouseCursor)
                    {
                        MouseControl.MouseMove(cursorScreenPos, debugText);
                    }
                }
            }
        }
    }
Esempio n. 24
0
    IEnumerator Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            //status.GetComponent<Animation>().Play();
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            started: (msg) =>
        {
            Debug.Log(string.Format("CallOnStarted[{0}]", msg));
        },
            ld: (msg) =>
        {
            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if UNITY_EDITOR_OSX || !UNITY_ANDROID
            // NOTE: depending on the situation, you might prefer
            // the 'iframe' approach.
            // cf. https://github.com/gree/unity-webview/issues/189
#if true
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        window.location = 'unity:' + msg;
                      }
                    }
                  }
                ");
#else
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        var iframe = document.createElement('IFRAME');
                        iframe.setAttribute('src', 'unity:' + msg);
                        document.documentElement.appendChild(iframe);
                        iframe.parentNode.removeChild(iframe);
                        iframe = null;
                      }
                    }
                  }
                ");
#endif
#endif
            webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
        },
            //ua: "custom user agent string",
            enableWKWebView: true);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
        webViewObject.bitmapRefreshCycle = 1;
#endif
        webViewObject.SetMargins(5, 200, 5, 15);
        webViewObject.SetVisibility(true);

#if !UNITY_WEBPLAYER
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            var exts = new string[] {
                ".jpg",
                ".js",
                ".html"  // should be last
            };
            foreach (var ext in exts)
            {
                var    url    = Url.Replace(".html", ext);
                var    src    = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var    dst    = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://"))
                {  // for Android
                    var www = new WWW(src);
                    yield return(www);

                    result = www.bytes;
                }
                else
                {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html")
                {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }
#else
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
        webViewObject.EvaluateJS(
            "parent.$(function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "       }" +
            "   };" +
            "});");
#endif
        yield break;
    }
Esempio n. 25
0
    IEnumerator Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
            status.text = msg;
            status.GetComponent <Animation>().Play();
        },
            ld: (msg) =>
        {
            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if !UNITY_ANDROID
            webViewObject.EvaluateJS(@"
                  window.Unity = {
                    call: function(msg) {
                      window.location = 'unity:' + msg;
                    }
                  }
                ");
#endif
            webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
        },
            //ua: "custom user agent string",
            enableWKWebView: true);
        webViewObject.SetMargins(5, 100, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);

#if !UNITY_WEBPLAYER
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            var exts = new string[] {
                ".jpg",
                ".html"  // should be last
            };
            foreach (var ext in exts)
            {
                var    url    = Url.Replace(".html", ext);
                var    src    = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var    dst    = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://"))    // for Android
                {
                    var www = new WWW(src);
                    yield return(www);

                    result = www.bytes;
                }
                else
                {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html")
                {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }
#else
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
        webViewObject.EvaluateJS(
            "parent.$(function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "       }" +
            "   };" +
            "});");
#endif
        yield break;
    }
Esempio n. 26
0
    void Update()
    {
        KinectManager manager = KinectManager.Instance;

        if (manager && manager.IsInitialized())
        {
            //backgroundImage.renderer.material.mainTexture = manager.GetUsersClrTex();
            if (backgroundImage && (backgroundImage.texture == null))
            {
                backgroundImage.texture = manager.GetUsersClrTex();
            }

//			Vector3 vRight = BottomRight - BottomLeft;
//			Vector3 vUp = TopLeft - BottomLeft;

            int iJointIndex = (int)TrackedJoint;

            if (manager.IsUserDetected())
            {
                uint userId = manager.GetPlayer1ID();


                if (manager.IsJointTracked(userId, iJointIndex))
                {
                    Vector3 posJoint = manager.GetRawSkeletonJointPos(userId, iJointIndex);

                    if (posJoint != Vector3.zero)
                    {
                        // 3d position to depth
                        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                        // depth pos to color pos
                        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

//						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
//						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                        if (debugText)
                        {
                            debugText.GetComponent <GUIText>().text = "Tracked user ID: " + userId;                             // new Vector2(scaleX, scaleY).ToString();
                        }

                        if (OverlayObject)
                        {
                            Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));
                            OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime);
                        }
                    }
                }

                ////player 2

                //if (manager.IsJointTracked(depthViewer.userId2, iJointIndex))
                //{
                //    Vector3 posJoint = manager.GetRawSkeletonJointPos(depthViewer.userId2, iJointIndex);

                //    if (posJoint != Vector3.zero)
                //    {
                //        // 3d position to depth
                //        Vector2 posDepth = manager.GetDepthMapPosForJointPos(posJoint);

                //        // depth pos to color pos
                //        Vector2 posColor = manager.GetColorMapPosForDepthPos(posDepth);

                //        float scaleX = (float)posColor.x / KinectWrapper.Constants.ColorImageWidth;
                //        float scaleY = 1.0f - (float)posColor.y / KinectWrapper.Constants.ColorImageHeight;

                //        //						Vector3 localPos = new Vector3(scaleX * 10f - 5f, 0f, scaleY * 10f - 5f); // 5f is 1/2 of 10f - size of the plane
                //        //						Vector3 vPosOverlay = backgroundImage.transform.TransformPoint(localPos);
                //        //Vector3 vPosOverlay = BottomLeft + ((vRight * scaleX) + (vUp * scaleY));

                //        if (debugText)
                //        {
                //            debugText.GetComponent<GUIText>().text = "Tracked user ID: " + depthViewer.userId2;  // new Vector2(scaleX, scaleY).ToString();
                //        }

                //        if (OverlayObject)
                //        {
                //            Vector3 vPosOverlay = Camera.main.ViewportToWorldPoint(new Vector3(scaleX, scaleY, distanceToCamera));
                //            OverlayObject.transform.position = Vector3.Lerp(OverlayObject.transform.position, vPosOverlay, smoothFactor * Time.deltaTime);
                //        }
                //    }
                //}
            }
        }
    }
Esempio n. 27
0
    //----------------------------------- end of public functions --------------------------------------//


    void Start()
    {
        try
        {
            // get sensor data
            KinectManager            kinectManager = KinectManager.Instance;
            KinectInterop.SensorData sensorData    = kinectManager != null?kinectManager.GetSensorData() : null;

            if (sensorData == null || sensorData.sensorInterface == null)
            {
                throw new Exception("Visual gesture tracking cannot be started, because the KinectManager is missing or not initialized.");
            }

            if (sensorData.sensorInterface.GetSensorPlatform() != KinectInterop.DepthSensorPlatform.KinectSDKv2)
            {
                throw new Exception("Visual gesture tracking is only supported by Kinect SDK v2");
            }

            // ensure the needed dlls are in place and face tracking is available for this interface
            bool bNeedRestart = false;
            if (IsVisualGesturesAvailable(ref bNeedRestart))
            {
                if (bNeedRestart)
                {
                    KinectInterop.RestartLevel(gameObject, "VG");
                    return;
                }
            }
            else
            {
                throw new Exception("Visual gesture tracking is not supported!");
            }

            // initialize visual gesture tracker
            if (!InitVisualGestures())
            {
                throw new Exception("Visual gesture tracking could not be initialized.");
            }

            // try to automatically detect the available gesture listeners in the scene
            if (visualGestureListeners.Count == 0)
            {
                MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];

                foreach (MonoBehaviour monoScript in monoScripts)
                {
                    if (typeof(VisualGestureListenerInterface).IsAssignableFrom(monoScript.GetType()) &&
                        monoScript.enabled)
                    {
                        visualGestureListeners.Add(monoScript);
                    }
                }
            }

            // all set
            instance = this;
            isVisualGestureInitialized = true;
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and FT-Library installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }
Esempio n. 28
0
 //Use this for initialization
 void Start()
 {
     text = new GameObject("SomeGUIText");
     Instantiate(text);
     myText = text.AddComponent<GUIText>();
     myText.transform.position = new Vector3(0.1f,0.9f,0f);
     myText.GetComponent<GUIText> ().text = "Score ";
     myText.GetComponent<GUIText> ().fontSize = 100;
     SetCountText ();
     anim = GetComponent<Animator>();
     highScore = PlayerPrefs.GetInt("HighScore");
     skin = Resources.Load("GUISkin") as GUISkin;
 }
Esempio n. 29
0
 private void update()
 {
     gt.GetComponent <GUIText>().text = story[storyMode, index];
 }