Inheritance: MonoBehaviour
    // Use this for initialization
    void Start()
    {
        _bodyManager  = BodyManager.GetComponent <BodyManager>();
        _kinectSensor = _bodyManager.GetSensor();

        if (_kinectSensor != null)
        {
            // # of bodies (which is max. 6 like here)
            _bodyCount = _kinectSensor.BodyFrameSource.BodyCount;
            Debug.Log(_bodyCount);

            _bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();


            // initialize Body array with # of of bodies
            _bodies = new Body[_bodyCount];

            // Initialize new GestureDetector list
            _gestureDetectorList = new List <GestureDetector>();

            // For every body add a new GestureDetector instance to the list
            for (int bodyIndex = 0; bodyIndex < _bodyCount; bodyIndex++)
            {
                GestureTextGameObject.text = "none";
                _gestureDetectorList.Add(new GestureDetector(_kinectSensor));
            }

            // open KinectSensor for usage
            _kinectSensor.Open();
        }
        else
        {
            // kinect sensor not connected
        }
    }
Example #2
0
    static Vector3 index_to_position(int i, Texture2D aTex)
    {
        int x = i % aTex.width - aTex.width / 2;
        int y = i / aTex.width - aTex.height / 2;

        return(new Vector3(-BodyManager.convert_units(x), BodyManager.convert_units(y)));
    }
Example #3
0
    // Use this for initialization
    void Awake()
    {
        if (_instance == null)
        {
            _instance = this;
        }
        else
        {
            Destroy(this);
        }

        if (KinectSensor.CheckLibrary())
        {
            _sensor = KinectSensor.GetDefault();
            if (_sensor != null)
            {
                _bodyFrameReader = _sensor.BodyFrameSource.OpenReader();

                if (!_sensor.IsOpen)
                {
                    _sensor.Open();
                }
            }
        }
    }
Example #4
0
        /*
         * Methods
         */

        // Intializer
        public ParticleSim(Canvas simCanvas)
        {
            this.simCanvas  = simCanvas;
            graphicsManager = new GraphicsManager(simCanvas);
            bodyManager     = new BodyManager(graphicsManager);
            simEngine       = new SimEngine(bodyManager);
        }
    // Use this for initialization
    void Start()
    {
/*
        _gameObjectBM = BodyManager.BM;
        if (BodyManager == null)
        {
            return;
        }
*/
       // _bodyManager = BodyManager.GetComponent<BodyManager>();
        _bodyManager = BodyManager.BM;
        if (_bodyManager == null)
        {
            return;
        }
        _canvasExerciseManager = CanvasExerciseManager.GetComponent<CanvasExerciseManager>();

        _kinectSensor = _bodyManager.GetSensor();

        // initialize Body array with # of maximum bodies
        _bodies = _bodyManager.GetBodies();
        Debug.Log(_bodyManager + " | " + _bodies);
        //_bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();

        // Initialize new GestureDetector list
        _gestureDetectorList = new List<GestureDetector>();
        // For every body add a new GestureDetector instance to the list

        for (int bodyIndex = 0; bodyIndex < _bodies.Length; bodyIndex++)
        {
            GestureTextGameObject.text = "none";
            _gestureDetectorList.Add(new GestureDetector(_kinectSensor));
        }
    }
Example #6
0
        // Use this for initialization
        void Start()
        {
            feedback        = drawingPrefab.GetComponent <Feedback>();
            swapCanvas      = drawingPrefab.GetComponent <SwapCanvas>();
            settingsManager = gameManager.GetComponent <SettingsManager>();
            patientManager  = gameManager.GetComponent <PatientManager>();
            sceneManager    = gameManager.GetComponent <SceneManager>();
            soundManager    = gameManager.GetComponentInChildren <SoundManager>();

            bodyManager      = this.GetComponentInChildren <BodyManager>();
            statisticManager = this.GetComponentInChildren <WriteStatisticManager>();

            bodyManager.BodyDetected += BodyManager_BodyDetected;
            bodyManager.BodyLost     += BodyManager_BodyLost;

            waitPanel.GetComponentInChildren <Text>().text = DB.Model.GetModel <DB.ValueTranslation>("noUser").Translation;

            patientManager.SetStressedJoints(GameManager.ActiveExercise);

            movieTexture      = GameManager.ActiveExercise.Video;
            movieTexture.loop = true;

            menuTitle.GetComponentInChildren <Text>().text = GameManager.ActiveExercise.Name;

            GameObject.Find("Video").GetComponent <RawImage>().texture          = movieTexture;
            GameObject.Find("Description").GetComponentInChildren <Text>().text = GameManager.ActiveExercise.Description;
            GameObject.Find("Information").GetComponent <Text>().text           = GameManager.ActiveExercise.Information;
        }
Example #7
0
    // Update is called on each frames
    void Update()
    {
        //we need to store the keys of the tracked bodies in order to generate them
        //We check if the KinectManager has data to work with

        if (BodyManager == null)
        {
            return;
        }

        _BodyManager = BodyManager.GetComponent <BodyManager>();
        if (_BodyManager == null)
        {
            return;
        }
        //We store the data of the bodies detected
        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        /////////////////////////////////////////////////////////////////////////////////
        //List of the tracked bodies (ulong is a an unsigned integer)
        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);  //We add the ID of all the tracked body from the the current frame in the tracked body list

                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    //if the body isn't already in the _Bodies dictionnary, we create a new body object and add it to the dictionnary
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId, body);
                }
                //otherwise the body exists already and we have to refresh it
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))   //we check every Ids in knownIds and check if the body are still tracked. If it isn't the case we destroy the body
            {                                       //by updating the _Bodies dictionnary
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }
    }
    void Update()
    {
        if (BodyManager == null)
        {
            return;
        }

        _BodyManager = BodyManager.GetComponent <BodyManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        for (int idx = 0; idx < data.Length; idx++)
        {
            if (data[idx] == null)
            {
                continue;
            }

            if (data[idx].IsTracked /*&& idx == modelIndex*/)
            {
                RefreshBodyObject(data[idx]);
            }
        }
    }
        public InitialPositionComputer(BodyManager bodyManager)
        {
            initialPositionDeviation = new BodyDeviation();
            bodySamples = new List <Body>();

            this.bodyManager              = bodyManager;
            bodyManager.BodyEventHandler += BodyEventHandler;
        }
Example #10
0
 private void Awake()
 {
     _BodyManager     = this;
     lstObjectsInGame = new List <GameObject>();
     lstUsed          = new List <GameObject>();
     isSpawning       = false;
     _SUIManager      = UIManager.UI_Manager;
 }
Example #11
0
 public HandOverhipEngagementManager(KinectSensor kinectSensor, BodyManager bodyManager, int engagedPeopleAllowed)
 {
     _BodyManager              = bodyManager;
     _EngagedPeopleAllowed     = engagedPeopleAllowed;
     _BodyReader               = kinectSensor.BodyFrameSource.OpenReader();
     _BodyReader.FrameArrived += this.BodyReader_FrameArrived;
     _Bodies        = new Body[_BodyReader.BodyFrameSource.BodyCount];
     _HandsToEngage = new List <BodyHandPair>();
 }
Example #12
0
    void Awake()
    {
                #if !UNITY_XBOXONE
        string words = "";
        using (StreamReader reader = new StreamReader(Application.dataPath + "/StreamingAssets/language.txt"))
        {
            words = reader.ReadLine();
            GameConstants.language = System.Convert.ToInt32(words);
        }
                #endif

        Random.seed = System.Environment.TickCount;
        Application.targetFrameRate = (int)GameConstants.TARGET_FRAMERATE;
        GameEventDistributor       += delegate(string arg1, object[] arg2) { Log("ManagerManager.cs: GAME EVENT: " + arg1); };

        Cursor.visible = false;
        gameObject.AddComponent <AudioListener>();

        //Debug.Log("setting up managers");
        mReferences = GetComponent <PrefabReferenceBehaviour>();
        //mMenuReferences = GetComponent<MenuReferenceBehaviour>();
        mNewRef = GetComponent <NewMenuReferenceBehaviour>();

        Manager = this;

        mCharacterBundleManager       = new CharacterBundleManager(this);
        mMusicManager                 = new MusicManager(this);
        mZigManager                   = new ZgManager(this);
        mProjectionManager            = new ProjectionManager(this);
        mBodyManager                  = new BodyManager(this);
        mTransparentBodyManager       = new BodyManager(this);
        mTransparentBodyManager.mMode = 1;         //nasty
        mBackgroundManager            = new BackgroundManager(this);
        mCameraManager                = new CameraManager(this);
        mAssetLoader                  = new AssetBundleLoader(this);
        mGameManager                  = new NewGameManager(this);
        mTransitionCameraManager      = new TransitionCameraManager(this);
        mMetaManager                  = new MetaManager(this);

        if (mStartDelegates != null)
        {
            /* CAN DELETE
             * var time = Time.time;
             * string output = "";
             * foreach(var e in mStartDelegates.GetInvocationList())
             * {
             *  e.DynamicInvoke();
             *  output += e.ToString() + " took: " + (Time.time - time) + "\n";
             *  time = Time.time;
             * }
             * Debug.Log(output);*/

            mStartDelegates();
        }

        ManagerManager.Log("ManagerManager.cs: AWAKE() COMPLETE");
    }
Example #13
0
    // Use this for initialization

    private void Start()
    {
        gameManager     = this;
        initValueBodies = 5;
        _BodyManager    = BodyManager._BodyManager;
        S_UIManager     = UIManager.UI_Manager;
        initGame();
        _InGame = false;
    }
Example #14
0
    void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
        }

        instance = this;
    }
Example #15
0
 // Use this for initialization
 void Start()
 {
     //sr = GetComponent<SpriteRenderer>();
     spriteRenderers = GetComponentsInChildren <SpriteRenderer>();
     ui          = FindObjectOfType <UIManager>();
     bodyManager = FindObjectOfType <BodyManager>();
     spriteRenderers[0].sprite  = fullFountain;
     spriteRenderers[1].sprite  = emptyFountain;
     spriteRenderers[1].enabled = false;
 }
        public NearestPersonEngagementManager2(KinectManager kinectManager, BodyManager bodyManager)
        {
            _KinectManager = kinectManager;
            _KinectManager.FrameArrived += KinectManager_FrameArrived;

            _BodyManager              = bodyManager;
            _BodyManager.BodyAdded   += BodyManager_BodyAdded;
            _BodyManager.BodyRemoved += BodyManager_BodyRemoved;
            _BodyManager.BodyUpdated += BodyManager_BodyUpdated;
        }
        public FacePhotoTaker(int totalSamples, KinectSensor kinectSensor, BodyManager bodyManager, bool onlyCaptureTrackedBodies)
        {
            _TotalSamples = totalSamples;
            _KinectSensor = kinectSensor;
            _BodyManager  = bodyManager;

            _ColorFrameDescription = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat);
            _ColorPixels           = new byte[_ColorFrameDescription.Width * _ColorFrameDescription.Height * _ColorFrameDescription.BytesPerPixel];

            _OnlyCaptureTrackedBodies = onlyCaptureTrackedBodies;
        }
Example #18
0
File: Milk.cs Project: wushupei/SHE
    void GrowTaller()                                      //牺牲自己,令主角长高
    {
        BodyManager bm = FindObjectOfType <BodyManager>(); //找到身体管理器脚本

        for (int i = 0; i < number; i++)
        {
            bm.AddBody();                                 //根据长高数量增加肢节
        }
        Destroy(gameObject);                              //销毁自身
        FindObjectOfType <AudioManager>().PlayAudio("M"); //播放牛奶声音
    }
        public bool IsCorrectGesture(string gestureName, Body[] record)
        {
            GestureData gestureData = gestureIndex.GestureDB[gestureName];

            List <string> files = new List <string>();

            foreach (string s in Directory.EnumerateFiles(@"..\..\..\..\database\"))
            {
                if (s.Contains(gestureData.fileName))
                {
                    files.Add(s);
                }
            }

            DTWComputer computer = new DTWComputer();
            float       sum      = 0;

            for (int i = 0; i < files.Count; i++)
            {
                sum = 0;

                BodyManager reference = new BodyManager();
                reference.LoadBodyData(files[i]);

                computer.ComputeDTW(reference.RecordedDataAsArray, record);

                foreach (BoneName boneName in Enum.GetValues(typeof(BoneName)))
                {
                    for (int k = 0; k < 4; k++)
                    {
                        sum += computer.Result.Data[Mapper.BoneIndexMap[boneName]].BestCost[k];
                    }
                }


                // we need a confidence threshold... getting the max difference between samples is not
                // the best solution... for now * 2 seems to work
                if (sum < gestureData.threshold * 2)
                {
                    Console.WriteLine("correct gesture threshold: " + sum);

                    closestSample = reference;
                    return(true);
                }
            }

            Console.WriteLine("incorrect gesture threshold: " + sum);


            closestSample = new BodyManager();
            closestSample.LoadBodyData(files[0]);

            return(false);
        }
Example #20
0
    // Use this for initialization
    void Start()
    {
        absorbing   = false;
        targets     = new List <GameObject>();
        mixer       = GetComponentInParent <BodyMixer>();
        bodyManager = FindObjectOfType <BodyManager>();

        if (bodyManager == null)
        {
            Debug.Log("Body Manger is not found");
        }
    }
Example #21
0
    float h = 0.05f;   //颜色的H值
    void OnEnable()
    {
        //来一个随机数字作为血量并显示
        hp        = Random.Range(1, 61);
        text      = GetComponentInChildren <TextMesh>();
        text.text = hp.ToString();

        bm = FindObjectOfType <BodyManager>(); //获取肢体管理器脚本
        p  = FindObjectOfType <Player>();      //主角脚本

        material = GetComponent <Renderer>().material;
        RandomColor(hp);
    }
Example #22
0
        // to refactor
        private float ComputeDTWThreshold()
        {
            float         maxSum = 0;
            List <string> files  = new List <string>();

            foreach (string s in Directory.EnumerateFiles(@"..\..\..\..\database\"))
            {
                if (s.Contains(gestureDB[newGesture].fileName))
                {
                    files.Add(s);
                }
            }

            DTWComputer computer = new DTWComputer();

            for (int i = 0; i < files.Count; i++)
            {
                BodyManager reference = new BodyManager();
                reference.LoadBodyData(files[i]);

                for (int j = 0; j < files.Count; j++)
                {
                    float      sum = 0;
                    FileStream recordFileStream = new FileStream(files[j], FileMode.Open, FileAccess.Read);

                    BodyManager record = new BodyManager();
                    record.LoadBodyData(files[j]);
                    computer.ComputeDTW(reference.RecordedDataAsArray, record.RecordedDataAsArray);

                    foreach (BoneName boneName in Enum.GetValues(typeof(BoneName)))
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            sum += computer.Result.Data[Mapper.BoneIndexMap[boneName]].BestCost[k];
                        }
                    }


                    if (sum > maxSum)
                    {
                        maxSum = sum;
                    }
                }
            }

            maxSum *= 1.5f;

            Console.WriteLine("threshold will be " + maxSum);

            return(maxSum);
        }
Example #23
0
    public static void resize_camera(Camera aCam, Vector2 aSize, float aDistance = 1)
    {
        //TODO what if camera is not orthographic
        float texRatio = aSize.x / (float)aSize.y;
        float camRatio = aCam.aspect;

        if (camRatio > texRatio) //match width
        {
            aCam.orthographicSize = BodyManager.convert_units(aSize.x / camRatio) / 2.0f;
        }
        else
        {
            aCam.orthographicSize = BodyManager.convert_units(aSize.y) / 2.0f;
        }
    }
Example #24
0
        public FaceManager(KinectManager kinectManager, BodyManager bodyManager, FaceFrameFeatures faceFrameFeatures)
        {
            _KinectManager = kinectManager;

            _BodyManager = bodyManager;
            _BodyManager.EngagedBodyUpdated += BodyManager_EngagedBodyUpdated;
            _BodyManager.BodyRemoved        += BodyManager_BodyRemoved;

            _FaceFrameFeatures = faceFrameFeatures;

            _ColorFrameDesc = kinectManager.KinectSensor.ColorFrameSource.CreateFrameDescription(ImageFormat);
            _ColorPixels    = new byte[_ColorFrameDesc.Width * _ColorFrameDesc.Height * _ColorFrameDesc.BytesPerPixel];

            CreateFaceTrackers(_KinectManager.KinectSensor.BodyFrameSource.BodyCount);
        }
Example #25
0
 private void Awake()
 {
     if (BM == null)
     {
         DontDestroyOnLoad(gameObject);
         BM = this;
     }
     else
     {
         if (BM != null)
         {
             Destroy(gameObject);
         }
     }
 }
        private Body[] GetSelectedGestureSample()
        {
            try {
                string gestureName     = (string)gestureList.SelectedItem;
                string gestureFileName = @"..\..\..\..\database\" + gestureIndex.GestureDB[gestureName].fileName + "0.xml";

                // load the gesture
                BodyManager b = new BodyManager();
                b.LoadBodyData(gestureFileName);

                return(b.RecordedDataAsArray);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
    private void Update()
    {
        // get average hand velocities
        var average = BodyManager.GetAverageVelocity(new JointType[] { JointType.HandLeft, JointType.HandRight });

        if (average.magnitude >= triggerForce)
        {
            huskEmission.enabled = true;
            SoundEffect.volume   = Mathf.Lerp(SoundEffect.volume, 1, Time.deltaTime);
        }
        else
        {
            huskEmission.enabled = false;
            SoundEffect.volume   = Mathf.Lerp(SoundEffect.volume, 0, Time.deltaTime);
        }
    }
    public void focus_camera_on_element(FlatElementBase aElement)
    {
        Rect focus = aElement.BoundingBox;
        //TODO what if camera is not orthographic
        float texRatio = focus.width / (float)focus.height;
        float camRatio = this.Camera.aspect;

        if (camRatio > texRatio) //match width
        {
            Interpolator.TargetOrthographicHeight = BodyManager.convert_units(focus.width / camRatio) / 2.0f;
        }
        else
        {
            Interpolator.TargetOrthographicHeight = BodyManager.convert_units(focus.height) / 2.0f;
        }
        Vector3 position = aElement.HardPosition;

        position.z = Center.z + Distance;
        Interpolator.TargetSpatialPosition = new SpatialPosition(position, Camera.transform.rotation);
    }
        void Awake()
        {
            if (bodyManager == null)
            {
                bodyManager = FindObjectOfType <BodyManager>();
                if (bodyManager == null)
                {
                    Debug.LogError("KeyPressController unable to find BodyManager");
                }
            }

            if (cameraController == null)
            {
                cameraController = FindObjectOfType <CameraController>();
                if (cameraController == null)
                {
                    Debug.LogError("KeyPressController unable to find CameraController");
                }
            }
        }
Example #30
0
    GameObject create_object(ZgJointId aId, Texture2D aTex, Vector2 aDim, List <Vector3> aAttach)
    {
        GameObject parent = new GameObject("genParent" + aId.ToString());
        //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //sphere.transform.localScale = Vector3.one * 0.2f;
        //sphere.transform.parent = parent.transform;
        GameObject kid = (GameObject)GameObject.Instantiate(ManagerManager.Manager.mReferences.mPlanePrefab);

        //GameObject kid = (GameObject)GameObject.CreatePrimitive(PrimitiveType.Plane); //TODO use prefab instead
        kid.GetComponent <Renderer>().material             = new Material(ManagerManager.Manager.mReferences.mDefaultCharacterShader);
        kid.GetComponent <Renderer>().material.mainTexture = aTex;
        kid.transform.rotation = Quaternion.AngleAxis(90, Vector3.right) * kid.transform.rotation;

        kid.transform.localScale = new Vector3(BodyManager.convert_units(aDim.x) / 10.0f, 1, BodyManager.convert_units(aDim.y) / 10.0f) * GameConstants.SCALE;
        kid.transform.position   = -aAttach[0] * GameConstants.SCALE;
        kid.transform.parent     = parent.transform;

        mParts[aId] = parent;
        return(parent);
    }
Example #31
0
    void Update()
    {
        if (BodyManager == null) {
            return;
        }

        SourceManager = BodyManager.GetComponent<BodyManager>();
        if (SourceManager == null) {
            return;
        }

        Kinect.Body[] data = SourceManager.GetData();
        if (data == null) {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data) {
            if (body == null) {
                continue;
            }

            if (body.IsTracked) {
                trackedIds.Add(body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(Bodies.Keys);
        // First delete untracked bodies
        foreach(ulong trackingId in knownIds) {
            if(!trackedIds.Contains(trackingId)) {
                Destroy(Bodies[trackingId]);
                Bodies.Remove(trackingId);
            }
        }

        foreach(var body in data) {
            if (body == null) {
                continue;
            }

            if(body.IsTracked) {
                if(!Bodies.ContainsKey(body.TrackingId)) {
                    Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, Bodies[body.TrackingId]);
            }
        }
    }
    void Update()
    {
        int state = 0;

        if (BodyManager == null)
        {
            return;
        }

        _BodyManager = BodyManager.GetComponent<BodyManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);

                //Check Hand State if body is being Tracked
                state = (CheckHandState(body.HandLeftState) + (2 * CheckHandState(body.HandRightState)));

                switch (state)
                {
                    case 0:
                        break;
                    case 1:
                        //Left
                        Debug.Log("Left");
                        break;
                    case 2:
                        //Right
                        Debug.Log("Right");
                        break;
                    case 3:
                        //Both
                        Debug.Log("Both");
                        break;
                    default:
                        break;
                }

                /*
                CheckRightHandState(body.HandRightState);
                CheckLeftHandState(body.HandLeftState);

                if(rightHandActive && leftHandActive)
                {
                    //flip
                    Debug.LogError("BOTH");
                }
                */
            }
        }


    }
Example #33
0
    // Update is called once per frame
    void Update () {
        int state = 0;

        //If we don't have a body manager Game Object
        if( bodyManagerGO == null )
        {
            //Exit the function
            return;
        }

        //Try to get the body manager game object's BodyManager component
        bodyManager = bodyManagerGO.GetComponent<BodyManager>();

        //If the body manager game object doesn't have a BodyManager component
        if (bodyManager == null)
        {
            //Exit the function
            return;
        }

        //Create a local copy of the bodyManager data
        Body[] data = bodyManager.getData();

        //If that data doesn't exist
        if( data == null )
        {
            //Exit the function
            return;
        }


        //List of tracked body ID numbers
        List<ulong> trackedIDs = new List<ulong>();


        //Fill that list
        //For each body in Kinect FOV
        foreach ( var body in data )
        {
            //If the body data is empty
            if( body == null )
            {
                //Skip this entry
                continue;
            }

            //If the body is being tracked
            if( body.IsTracked )
            {
                //Add its ID to the trackedIDs list
                trackedIDs.Add(body.TrackingId);
            }
        }

        //Get list of all body gameobjec
        List<ulong> knownIDs = new List<ulong>(_Bodies.Keys);

        //Delete GameObjects for bodies that aren't being tracked
        foreach ( ulong trackingID in knownIDs )
        {
            //If the currently tracked body ID list doesn't contain a body with this tracking ID
            if( !trackedIDs.Contains(trackingID) )
            {
                //Delete the GameObject
                Destroy(_Bodies[trackingID]);
                //Remove the body from the list of gameObjects
                _Bodies.Remove(trackingID);
            }
        }


        //Update body objects that need to be updated and create body objects that need to be created

        foreach ( var body in data )
        {
            //If the body doesn't exist
            if( body == null )
            {
                //Skip it
                continue;
            }

            //If the body is tracked
            if( body.IsTracked )
            {
                //If the body GameObject dictionary doesn't contain the body's tracking ID
                if( !_Bodies.ContainsKey(body.TrackingId) )
                {
                    //Create a body object with thr body's tracking ID and add it to the body GameObject dictionary (using the tracking ID as a key)
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                //Refresh the body object
                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
	}
    void Update()
    {
        int state = 0;

        if (BodyManager == null)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.J))
        {
            //Left
            platformRotate.TurnLeft();
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            //Right
            platformRotate.TurnRight();
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            //Flip
            platformRotate.Flip();

        }

        //if (playerScript.flipjump)
        //{
        //    // .. increment a timer to count up to restarting.
        //    flipTimer += Time.deltaTime;

        //    if (flipTimer >= flipDelay)
        //    {
        //        playerScript.flipjump = false;

        //    }
        //}


        //if (playerScript.flipjump)
        //    playerScript.flipjump = false; 

        _BodyManager = BodyManager.GetComponent<BodyManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
                Debug.Log("Found Body");
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(_Bodies[trackingId]);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {

                    //Check Hand State if body is being Tracked
                    state = CheckLeftHandState(body.HandLeftState) + (2 * CheckRightHandState(body.HandRightState));
                Debug.Log("state: " + state);
                    switch (state)
                    {
                        case 0:
                            signalStart = false; 
                            break;
                        case 1:
                            //Left
                            Debug.Log("Left");
                            if (prevState == 0)
                                platformRotate.TurnLeft();
                            break;
                        case 2:
                            //Right
                            Debug.Log("Right");
                            signalStart = true; 
                            if (prevState == 0)
                                platformRotate.TurnRight();
                            break;
                        case 3:
                            //Both
                            Debug.Log("Both");
                            if (prevState == 0)
                            {
                                //                     playerScript.flipjump = true; 
                                platformRotate.Flip();
                            }

                            break;
                        default:
                            break;
                    }
                    prevState = state;
                
            }
        }
    }