Exemple #1
0
    private string GetDevicePrefabName(string deviceType, BhapticsPrefabMode prefabMode)
    {
        switch (deviceType)
        {
        case "Vest":
            return("BhapticsVRC_Vest_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "LeftArm":
            return("BhapticsVRC_LeftArm_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "RightArm":
            return("BhapticsVRC_RightArm_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "Head":
            return("BhapticsVRC_Head_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "LeftHand":
            return("BhapticsVRC_LeftHand_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "RightHand":
            return("BhapticsVRC_RightHand_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "LeftFoot":
            return("BhapticsVRC_LeftFoot_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));

        case "RightFoot":
            return("BhapticsVRC_RightFoot_" + Enum.GetName(typeof(BhapticsPrefabMode), prefabMode));
        }
        return(null);
    }
Exemple #2
0
    public void AddDevicePrefab(string deviceTypeStr, BhapticsPrefabMode prefabMode, bool activeOffset, Vector3 posOffset, Quaternion rotOffset, Vector3 scaleOffset)
    {
#if UNITY_EDITOR
        if (!AvatarCheck())
        {
            return;
        }

        DestroyDevicePrefab(deviceTypeStr);

        string prefabName = GetDevicePrefabName(deviceTypeStr, prefabMode);
        string path       = FindAssetPath(prefabName);
        if (path == null)
        {
            Debug.LogErrorFormat("BhapticsVRCEditor / Cannot find asset {0}, {1}", deviceTypeStr, prefabMode);
            return;
        }
        var ins = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(path), transform);
        ins.name = prefabName;
        Undo.RegisterCreatedObjectUndo(ins, "Create New GameObject");
        Undo.RecordObjects(ins.GetComponentsInChildren <Transform>(), "Change Transform Position");

        var deviceTypeNames = Enum.GetNames(typeof(BhapticsDeviceType));
        for (int i = 0; i < deviceTypeNames.Length; ++i)
        {
            if (deviceTypeStr != deviceTypeNames[i])
            {
                continue;
            }
            if (deviceTypeNames[i] == "LeftHand" || deviceTypeNames[i] == "RightHand")
            {
                ins.transform.parent = anim.GetBoneTransform(humanBodyBoneDic[i]);
                if (activeOffset)
                {
                    ins.transform.localPosition = posOffset;
                    ins.transform.localRotation = rotOffset;
                    ins.transform.localScale    = scaleOffset;
                }
                var joints = ins.GetComponentsInChildren <ParentConstraint>();
                for (int jointIndex = 0; jointIndex < joints.Length; ++jointIndex)
                {
                    var constraintSource = new ConstraintSource();
                    constraintSource.weight          = 1f;
                    constraintSource.sourceTransform = anim.GetBoneTransform(handBoneDic[jointIndex + i * 10]);
                    if (constraintSource.sourceTransform != null)
                    {
                        joints[jointIndex].SetSource(0, constraintSource);
                    }
                    else
                    {
                        Debug.LogError("BhapticsVRCEditor / " + deviceTypeNames[i] + " device's parentConstraint setting is wrong!"
                                       + "\n" + "<color=red>" + handBoneDic[jointIndex + i * 10] + " is null.</color>");
                    }
                }
                deviceGameObjects[i] = ins;
            }
            else
            {
                ins.transform.parent = anim.GetBoneTransform(humanBodyBoneDic[i]);
                if (activeOffset)
                {
                    ins.transform.localPosition = posOffset;
                    ins.transform.localRotation = rotOffset;
                    ins.transform.localScale    = scaleOffset;
                }
                deviceGameObjects[i] = ins;
            }
            break;
        }
#endif
    }
Exemple #3
0
 public void AddDevicePrefab(string deviceTypeStr, BhapticsPrefabMode prefabMode)
 {
     AddDevicePrefab(deviceTypeStr, prefabMode, false, Vector3.zero, Quaternion.identity, Vector3.one);
 }