コード例 #1
0
        void Update()
        {
            if (rtClient == null)
            {
                rtClient = RTClient.GetInstance();
            }

            var skeleton = rtClient.GetSkeleton(SkeletonName);

            if (mQtmSkeletonCache != skeleton)
            {
                mQtmSkeletonCache = skeleton;

                if (mQtmSkeletonCache == null)
                {
                    return;
                }

                CreateMecanimToQtmSegmentNames(SkeletonName);

                if (mStreamedRootObject != null)
                {
                    GameObject.Destroy(mStreamedRootObject);
                }

                mStreamedRootObject = new GameObject(this.SkeletonName);

                mQTmSegmentIdToGameObject = new Dictionary <uint, GameObject>(mQtmSkeletonCache.Segments.Count);

                foreach (var segment in mQtmSkeletonCache.Segments.ToList())
                {
                    var gameObject = new GameObject(this.SkeletonName + "_" + segment.Value.Name);
                    gameObject.transform.parent                 = segment.Value.ParentId == 0 ? mStreamedRootObject.transform : mQTmSegmentIdToGameObject[segment.Value.ParentId].transform;
                    gameObject.transform.localPosition          = segment.Value.TPosition;
                    mQTmSegmentIdToGameObject[segment.Value.Id] = gameObject;
                }

                BuildMecanimAvatarFromQtmTPose();

                mStreamedRootObject.transform.SetParent(this.transform, false);
                mStreamedRootObject.transform.Rotate(new Vector3(0, 90, 0), Space.Self);
                return;
            }

            if (mQtmSkeletonCache == null)
            {
                return;
            }

            // Update all the game objects
            foreach (var segment in mQtmSkeletonCache.Segments.ToList())
            {
                GameObject gameObject;
                if (mQTmSegmentIdToGameObject.TryGetValue(segment.Key, out gameObject))
                {
                    gameObject.transform.localPosition = segment.Value.Position;
                    gameObject.transform.localRotation = segment.Value.Rotation;
                }
            }
            if (mSourcePoseHandler != null && mDestiationPoseHandler != null)
            {
                mSourcePoseHandler.GetHumanPose(ref mHumanPose);
                mDestiationPoseHandler.SetHumanPose(ref mHumanPose);
            }
        }