SuccessfulCalibration() public method

public SuccessfulCalibration ( uint userId ) : void
userId uint
return void
Beispiel #1
0
    // loads the avatar object from the input fbx file
    private bool LoadAvatarObject()
    {
        if (loadFilePath == string.Empty)
        {
            return(false);
        }

#if UNITY_EDITOR
        UnityEngine.Object avatarModel = UnityEditor.AssetDatabase.LoadAssetAtPath(loadFilePath, typeof(UnityEngine.Object));
        if (avatarModel == null)
        {
            return(false);
        }

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

        avatarObject = (GameObject)GameObject.Instantiate(avatarModel);
        if (avatarObject != null)
        {
            avatarObject.transform.position = new Vector3(-1f, 0f, -1f);             // Vector3.zero;
            avatarObject.transform.rotation = Quaternion.identity;

            AvatarController ac = avatarObject.AddComponent <AvatarController>();
            ac.playerIndex = playerIndex;

            ac.mirroredMovement = false;
            ac.verticalMovement = true;

            ac.smoothFactor       = smoothFactor;
            ac.fingerOrientations = fingerOrientations;
            ac.groundedFeet       = groundedFeet;

            ac.Awake();

            KinectManager km = KinectManager.Instance;

            if (km)
            {
                if (km.IsUserDetected())
                {
                    ac.SuccessfulCalibration(km.GetPrimaryUserID());
                }

                km.avatarControllers.Clear();
                km.avatarControllers.Add(ac);
            }
        }

        return(true);
#else
        return(false);
#endif
    }
Beispiel #2
0
    private void LoadModel(string modelDir)
    {
        string modelPath = "Clothing/" + modelDir + "/model";

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

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

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

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

        ac.posRelativeToCamera = modelRelativeToCamera;
        ac.posRelOverlayColor  = (foregroundCamera != null);
        ac.mirroredMovement    = true;
        ac.verticalMovement    = true;
        ac.smoothFactor        = 0f;

        KinectManager km = KinectManager.Instance;

        ac.Awake();

        if (km.IsUserDetected())
        {
            ac.SuccessfulCalibration(km.GetPrimaryUserID());
        }

        km.avatarControllers.Clear();         // = new List<AvatarController>();
        km.avatarControllers.Add(ac);

        AvatarScaler scaler = selModel.AddComponent <AvatarScaler>();

        scaler.mirroredAvatar    = true;
        scaler.bodyScaleFactor   = bodyScaleFactor;
        scaler.continuousScaling = continuousScaling;
        scaler.foregroundCamera  = foregroundCamera;

        scaler.Start();
    }
    // creates avatar for the given user
    private GameObject CreateUserAvatar(long userId, int userIndex)
    {
        GameObject avatarObj = null;

        if (avatarModel)
        {
            Vector3    userPos = new Vector3(userIndex, 0, 0);
            Quaternion userRot = Quaternion.Euler(!mirroredMovement ? Vector3.zero : new Vector3(0, 180, 0));

            avatarObj      = Instantiate(avatarModel, userPos, userRot);
            avatarObj.name = "User-" + userId;

            AvatarController ac = avatarObj.GetComponent <AvatarController>();
            if (ac == null)
            {
                ac             = avatarObj.AddComponent <AvatarController>();
                ac.playerIndex = userIndex;

                ac.smoothFactor        = smoothFactor;
                ac.posRelativeToCamera = posRelativeToCamera;

                ac.mirroredMovement = mirroredMovement;
                ac.verticalMovement = verticalMovement;

                ac.groundedFeet      = groundedFeet;
                ac.applyMuscleLimits = applyMuscleLimits;
            }

            // start the avatar controller
            ac.SuccessfulCalibration(userId, false);

            // refresh the KM-list of available avatar controllers
            MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
            kinectManager.avatarControllers.Clear();

            foreach (MonoBehaviour monoScript in monoScripts)
            {
                if ((monoScript is AvatarController) && monoScript.enabled)
                {
                    AvatarController avatar = (AvatarController)monoScript;
                    kinectManager.avatarControllers.Add(avatar);
                }
            }
        }

        return(avatarObj);
    }
    // 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.verticalOffset = verticalOffset;
            ac.forwardOffset  = forwardOffset;
            ac.smoothFactor   = 0f;
        }

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

        KinectManager km = KinectManager.Instance;

        //ac.Awake();

        if (km && km.IsInitialized())
        {
            long userId = km.GetUserIdByIndex(playerIndex);
            if (userId != 0)
            {
                ac.SuccessfulCalibration(userId);
            }

            // locate the available avatar controllers
            MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
            km.avatarControllers.Clear();

            foreach (MonoBehaviour monoScript in monoScripts)
            {
                if ((monoScript is AvatarController) && monoScript.enabled)
                {
                    AvatarController avatar = (AvatarController)monoScript;
                    km.avatarControllers.Add(avatar);
                }
            }
        }

        AvatarScaler scaler = selModel.GetComponent <AvatarScaler>();

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

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

        scaler.foregroundCamera = foregroundCamera;
        //scaler.debugText = debugText;

        //scaler.Start();
    }
Beispiel #5
0
    private void LoadModel(string modelDir)
    {
        string modelPath = modelCategory + "/" + modelDir + "/model";

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

        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.smoothFactor     = 0f;
        }

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

        KinectManager km = KinectManager.Instance;
        //ac.Awake();

        long userId = km.GetUserIdByIndex(playerIndex);

        if (userId != 0)
        {
            ac.SuccessfulCalibration(userId);
        }

        km.avatarControllers.Clear();         // = new List<AvatarController>();
        km.avatarControllers.Add(ac);

        AvatarScaler scaler = selModel.GetComponent <AvatarScaler>();

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

            scaler.bodyScaleFactor   = bodyScaleFactor;
            scaler.continuousScaling = continuousScaling;
        }

        scaler.foregroundCamera = foregroundCamera;
        //scaler.debugText = debugText;

        //scaler.Start();
    }
    // Token: 0x060000B6 RID: 182 RVA: 0x00009660 File Offset: 0x00007860
    private void LoadDressingModel(string modelDir, int select)
    {
        string modelPath   = this.modelCategory + "/" + modelDir + "/model";
        Object modelPrefab = Resources.Load(modelPath, typeof(GameObject));
        bool   flag        = modelPrefab == null;

        if (!flag)
        {
            bool flag2 = this.selModel != null;
            if (flag2)
            {
                Object.Destroy(this.selModel);
            }
            for (int i = 0; i < this.modelHat.Length; i++)
            {
                bool flag3 = i == select;
                if (flag3)
                {
                    this.selHat = this.modelHat[select];
                }
                else
                {
                    this.modelHat[i].SetActive(false);
                }
            }
            this.UserBodyBlender.ChangeBackGround(this.selected);
            this.selModel      = (GameObject)Object.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0f, 180f, 0f));
            this.selModel.name = "Model" + modelDir;
            ModelData data  = this.selModel.GetComponent <ModelData>();
            bool      flag4 = data == null;
            if (flag4)
            {
                throw new UnityException("没有找到模型数据");
            }
            this.CurInfo = GlobalSettings.GetRoleInfo(data.Name);
            bool flag5 = this.CurInfo == null;
            if (flag5)
            {
                throw new UnityException("没有找到角色数据,查找的角色是:" + data.Name);
            }
            this.editorModel.SetInfo(this.CurInfo);
            this.selHat.GetComponent <ModelHatController>().verticalOffset = this.CurInfo.HatHeight;
            bool flag6 = FacetrackingManager.Instance != null;
            if (flag6)
            {
                //FacetrackingManager.Instance.Shifting = this.CurInfo.Shifting;
                //FacetrackingManager.Instance.modelMeshScale = this.CurInfo.HeadScale;
            }
            AvatarController ac    = this.selModel.GetComponent <AvatarController>();
            bool             flag7 = ac == null;
            if (flag7)
            {
                ac                    = this.selModel.AddComponent <AvatarController>();
                ac.playerIndex        = this.playerIndex;
                ac.mirroredMovement   = true;
                ac.verticalMovement   = true;
                ac.applyMuscleLimits  = this.applyMuscleLimits;
                ac.verticalOffset     = this.verticalOffset;
                ac.forwardOffset      = this.forwardOffset;
                ac.smoothFactor       = 0f;
                ac.verticalOffset     = this.CurInfo.Vertacal;
                ac.forwardOffset      = this.CurInfo.Farward;
                ac.fingerOrientations = true;
                ac.applyMuscleLimits  = true;
            }
            ac.posRelativeToCamera = this.modelRelativeToCamera;
            ac.posRelOverlayColor  = (this.foregroundCamera != null);
            KinectManager km    = KinectManager.Instance;
            bool          flag8 = km && km.IsInitialized();
            if (flag8)
            {
                long userId = km.GetUserIdByIndex(this.playerIndex);
                bool flag9  = userId != 0L;
                if (flag9)
                {
                    ac.SuccessfulCalibration(userId, false);
                }
                MonoBehaviour[] monoScripts = Object.FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
                km.avatarControllers.Clear();
                foreach (MonoBehaviour monoScript in monoScripts)
                {
                    bool flag10 = monoScript is AvatarController && monoScript.enabled;
                    if (flag10)
                    {
                        AvatarController avatar = (AvatarController)monoScript;
                        km.avatarControllers.Add(avatar);
                    }
                }
            }
            AvatarScaler scaler = this.selModel.GetComponent <AvatarScaler>();
            bool         flag11 = scaler == null;
            if (flag11)
            {
                scaler                   = this.selModel.AddComponent <AvatarScaler>();
                scaler.playerIndex       = this.playerIndex;
                scaler.mirroredAvatar    = true;
                scaler.continuousScaling = this.continuousScaling;
                scaler.bodyScaleFactor   = this.bodyScaleFactor;
                scaler.bodyWidthFactor   = this.bodyWidthFactor;
                scaler.armScaleFactor    = this.armScaleFactor;
                scaler.legScaleFactor    = this.legScaleFactor;
                scaler.bodyScaleFactor   = this.CurInfo.BodyScale;
                scaler.legScaleFactor    = this.CurInfo.LegScale;
                scaler.armScaleFactor    = this.CurInfo.ArmScale;
            }
            scaler.foregroundCamera = this.foregroundCamera;
        }
    }
    private void LoadClothes(string clothesName)
    {
        app.model.modelClothes.verticalOffset = 0;
        app.model.modelClothes.forwardOffset  = 0;
        app.model.modelClothes.modelCategory  = "Clothing";
        string subPath     = ChangeSubPath();
        int    playerIndex = app.model.modelData.playerIndex;
        string modelPath   = app.model.modelClothes.modelCategory + "/" + subPath + "/" + clothesName;

        print(modelPath);
        UnityEngine.Object modelPrefab = Resources.Load(modelPath, typeof(GameObject));
        if (modelPrefab == null)
        {
            return;
        }
        print(clothesName);
        Debug.Log("Model: " + modelPath);

        if (app.model.modelClothes.listClothes.Length >= app.model.modelData.kinectManager.GetUsersCount())
        {
            if (app.model.modelClothes.listClothes[app.model.modelData.playerIndex])
            {
                GameObject.Destroy(app.model.modelClothes.listClothes[app.model.modelData.playerIndex]);
                //app.model.modelClothes.selModels.RemoveAt(app.model.modelData.playerIndex);
            }
        }

        app.model.modelClothes.listClothes[app.model.modelData.playerIndex]      = (GameObject)GameObject.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0, 180f, 0));
        app.model.modelClothes.listClothes[app.model.modelData.playerIndex].name = "Model000" + playerIndex;

        //app.model.modelClothes.selModels.Add(app.model.modelClothes.selModel);
        //app.model.modelClothes.selModels[playerIndex] = (GameObject)GameObject.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0, 180f, 0));
        //app.model.modelClothes.selModels[playerIndex].name = "Model000" + playerIndex;

        //app.model.modelClothes.selModel = (GameObject)GameObject.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0, 180f, 0));
        ////app.model.modelClothes.selModel.name = "Model" + "0000";

        AvatarController ac = app.model.modelClothes.listClothes[playerIndex].GetComponent <AvatarController>();

        if (ac == null)
        {
            ac             = app.model.modelClothes.listClothes[playerIndex].AddComponent <AvatarController>();
            ac.playerIndex = playerIndex;

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

            ac.verticalOffset = app.model.modelClothes.verticalOffset;
            ac.forwardOffset  = app.model.modelClothes.forwardOffset;
            ac.smoothFactor   = 0f;
        }

        ac.posRelativeToCamera = app.model.modelData.backgroundCamera;
        ac.posRelOverlayColor  = (app.model.modelData.foregroundCamera != null);

        KinectManager km = KinectManager.Instance;

        //ac.Awake();

        if (km && km.IsInitialized())
        {
            long userId = km.GetUserIdByIndex(playerIndex);
            if (userId != 0)
            {
                ac.SuccessfulCalibration(userId, false);
            }

            // locate the available avatar controllers
            MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
            km.avatarControllers.Clear();

            foreach (MonoBehaviour monoScript in monoScripts)
            {
                if ((monoScript is AvatarController) && monoScript.enabled)
                {
                    AvatarController avatar = (AvatarController)monoScript;
                    km.avatarControllers.Add(avatar);
                }
            }
        }

        AvatarScaler scaler = app.model.modelClothes.listClothes[app.model.modelData.playerIndex].GetComponent <AvatarScaler>();

        if (scaler == null)
        {
            scaler                = app.model.modelClothes.listClothes[app.model.modelData.playerIndex].AddComponent <AvatarScaler>();
            scaler.playerIndex    = playerIndex;
            scaler.mirroredAvatar = true;

            scaler.continuousScaling = true;
            scaler.bodyScaleFactor   = 1.1f;
            scaler.bodyWidthFactor   = 1.1f;
            scaler.armScaleFactor    = 1.1f;
            scaler.legScaleFactor    = 1.1f;
        }

        scaler.foregroundCamera = app.model.modelData.foregroundCamera;
    }