コード例 #1
0
    /// <summary>
    /// Message from Button Components
    /// </summary>
    /// <param name="name">Button name</param>
    void ButtonPressed(string name)
    {
        // If hand is selected
        if (state == HAND_CALIBRATION_LEVEL_STATES.HandSelection && (name == BUTTON_NAMES.LeftHand.ToString() || name == BUTTON_NAMES.RightHand.ToString()))
        {
            // hide and destroy buttons
            GameObject[] buttons = GameObject.FindGameObjectsWithTag("Button");
            foreach (GameObject button in buttons)
            {
                button.GetComponent <Button>().DisableClick();
                if (button.transform.position.x > 0)
                {
                    iTween.MoveTo(button, iTween.Hash("x", 11.6f, "easeType", "easeInOutQuad", "oncomplete", "DestroyMe"));                                     //, "time", 1.0f));
                }
                else
                {
                    iTween.MoveTo(button, iTween.Hash("x", -11.6f, "easeType", "easeInOutQuad", "oncomplete", "DestroyMe"));                                    //, "time", 1.0f));
                }
            }

            if (name == BUTTON_NAMES.LeftHand.ToString())
            {
                rightHand = false;
            }
            else if (name == BUTTON_NAMES.RightHand.ToString())
            {
                rightHand = true;
            }

            // Create HandCalibrator to use in next state
            HandCalibrator = Instantiate(HandCalibratorPrefab) as HandXYCalibrator;
            HandCalibrator.transform.position = new Vector2(0.0f, 0.0f);

            // Create button that must be pressed after calibration
            Button calibrationDone = Instantiate(ButtonWidePrefab, new Vector2(0.0f, 6.0f), Quaternion.identity) as Button;
            calibrationDone.name = BUTTON_NAMES.CalibrationDone.ToString();
            calibrationDone.SetCaption("Done");
            calibrationDone.Listeners    = new GameObject[1];
            calibrationDone.Listeners[0] = gameObject;
            iTween.MoveTo(calibrationDone.gameObject, iTween.Hash("y", 3.1f, "easeType", "easeInOutQuad"));//, "time", buttonAppearenceAnimationTime));

            state++;
        }
        // If calibration is over
        else if (state == HAND_CALIBRATION_LEVEL_STATES.HandCalibration && name == BUTTON_NAMES.CalibrationDone.ToString())
        {
            // hide and destroy button
            GameObject[] buttons = GameObject.FindGameObjectsWithTag("Button");
            foreach (GameObject button in buttons)
            {
                button.GetComponent <Button>().DisableClick();
            }

            MinHandPosition = HandCalibrator.GetMinHandPosition();
            MaxHandPosition = HandCalibrator.GetMaxHandPosition();

            CalibrationData.Instance().SetData(MinHandPosition, MaxHandPosition, rightHand);

            state++;
            StartCoroutine(FinalAnimation());
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        // If there is no ball, let's create a new one
        if (CurrentBall == null)
        {
            CurrentBall = Instantiate(BallPrefab) as GameObject;
            CurrentBall.transform.position = new Vector3(UnityEngine.Random.Range(BallPositionBounds.xMin, BallPositionBounds.xMax),
                                                         UnityEngine.Random.Range(BallPositionBounds.yMin, BallPositionBounds.yMax), 0.0f);

            // Simple scaling animation
            CurrentBall.transform.localScale = new Vector2(0.1f, 0.1f);
            iTween.ScaleTo(CurrentBall, iTween.Hash("x", 1.0f, "y", 1.0f, "easeType", "easeInOutQuad"));
        }

        if (KinectManager.SkeletonIsTracked && GoodPlayerPosition)
        {
            // Move our hand
            float calibratedX = 0.0f;
            float calibratedY = 0.0f;

            // Get data from kinect
            if (CalibrationData.Instance().CheckIfRightHand())
            {
                calibratedX = KinectManager.RightHandPosition.x;
                calibratedY = KinectManager.RightHandPosition.y;
            }
            else
            {
                calibratedX = KinectManager.LeftHandPosition.x;
                calibratedY = KinectManager.LeftHandPosition.y;
            }

            // Normalize
            calibratedX = (calibratedX - CalibrationData.Instance().GetMinHandPosition().x) / (CalibrationData.Instance().GetMaxHandPosition().x - CalibrationData.Instance().GetMinHandPosition().x);
            calibratedY = (calibratedY - CalibrationData.Instance().GetMinHandPosition().y) / (CalibrationData.Instance().GetMaxHandPosition().y - CalibrationData.Instance().GetMinHandPosition().y);
            if (calibratedX > 1)
            {
                calibratedX = 1;
            }
            if (calibratedX < 0)
            {
                calibratedX = 0;
            }
            if (calibratedY > 1)
            {
                calibratedY = 1;
            }
            if (calibratedY < 0)
            {
                calibratedY = 0;
            }

            // Now calibratedX and calibratedY are in [0; 1]
            // Lo let's add some smoothing
            calibratedX = GetNextXExtrapolationValue(calibratedX);
            calibratedY = GetNextYExtrapolationValue(calibratedY);

            //Debug.Log(calibratedX);

            CurrentHand.transform.position = new Vector2(BallPositionBounds.xMin + BallPositionBounds.width * calibratedX, BallPositionBounds.yMin + BallPositionBounds.height * calibratedY);
        }

        // Set data to TopView
        if (TopView != null)
        {
            SetDataToTopView();
        }
    }