Esempio n. 1
0
        void Update()
        {
            // check for selection change
            if (activeSelector && selected >= 0 && selected < modelNames.Length && prevSelected != selected)
            {
                KinectManager kinectManager = KinectManager.Instance;

                if (kinectManager && kinectManager.IsInitialized() && kinectManager.IsUserDetected(playerIndex))
                {
                    OnDressingItemSelected(selected);
                }
            }

            if (selModel != null)
            {
                // update model settings as needed
                float curMuscleLimits = applyMuscleLimits ? 1f : 0f;
                float updModelOffset  = horizontalOffset + verticalOffset + forwardOffset + curMuscleLimits;

                if (Mathf.Abs(curModelOffset - updModelOffset) >= 0.001f)
                {
                    // update model offsets
                    curModelOffset = updModelOffset;

                    AvatarController ac = selModel.GetComponent <AvatarController>();
                    if (ac != null)
                    {
                        ac.horizontalOffset  = horizontalOffset;
                        ac.verticalOffset    = verticalOffset;
                        ac.forwardOffset     = forwardOffset;
                        ac.applyMuscleLimits = applyMuscleLimits;
                    }
                }

                if (Mathf.Abs(curScaleFactor - (bodyScaleFactor + bodyWidthFactor + armScaleFactor + legScaleFactor)) >= 0.001f)
                {
                    // update scale factors
                    curScaleFactor = bodyScaleFactor + bodyWidthFactor + armScaleFactor + legScaleFactor;

                    AvatarScaler scaler = selModel.GetComponent <AvatarScaler>();
                    if (scaler != null)
                    {
                        scaler.continuousScaling = continuousScaling;
                        scaler.bodyScaleFactor   = bodyScaleFactor;
                        scaler.bodyWidthFactor   = bodyWidthFactor;
                        scaler.armScaleFactor    = armScaleFactor;
                        scaler.legScaleFactor    = legScaleFactor;
                    }
                }
            }
        }
Esempio n. 2
0
        // sets the selected dressing model as user avatar
        private void LoadDressingModel(string modelDir)
        {
            string modelPath = modelCategory + "/" + modelDir + "/model";

            UnityEngine.Object modelPrefab = Resources.Load(modelPath, typeof(GameObject));
            if (modelPrefab == null)
            {
                return;
            }

            Debug.Log("Model: " + modelPath);

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

            selModel      = (GameObject)GameObject.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0, 180f, 0));
            selModel.name = "Model" + modelDir;

            AvatarController ac = selModel.GetComponent <AvatarController>();

            if (ac == null)
            {
                ac             = selModel.AddComponent <AvatarController>();
                ac.playerIndex = playerIndex;

                ac.mirroredMovement  = true;
                ac.verticalMovement  = true;
                ac.applyMuscleLimits = applyMuscleLimits;

                ac.horizontalOffset = horizontalOffset;
                ac.verticalOffset   = verticalOffset;
                ac.forwardOffset    = forwardOffset;
                ac.smoothFactor     = 0f;
            }

            ac.posRelativeToCamera = modelRelativeToCamera;
            ac.posRelOverlayColor  = (foregroundCamera != null);
            ac.Update();

            KinectManager km     = KinectManager.Instance;
            AvatarScaler  scaler = selModel.GetComponent <AvatarScaler>();

            if (scaler == null)
            {
                scaler                 = selModel.AddComponent <AvatarScaler>();
                scaler.playerIndex     = playerIndex;
                scaler.mirroredAvatar  = true;
                scaler.minUserDistance = km.minUserDistance;

                scaler.continuousScaling = continuousScaling;
                scaler.bodyScaleFactor   = bodyScaleFactor;
                scaler.bodyWidthFactor   = bodyWidthFactor;
                scaler.armScaleFactor    = armScaleFactor;
                scaler.legScaleFactor    = legScaleFactor;
            }

            scaler.foregroundCamera = foregroundCamera;
            //scaler.debugText = debugText;
            scaler.Update();
        }