예제 #1
0
    private void Awake()
    {
        _objectConfigModule   = ModuleManager.Instance.Get <ObjectsConfigModule>();
        _assemblyObjectModule = ModuleManager.Instance.Get <AssemblyObjectsModule>();

        _leftGrab  = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent <VRTK_InteractGrab>();
        _rightGrab = VRTK_DeviceFinder.GetControllerRightHand().GetComponent <VRTK_InteractGrab>();
        string name = gameObject.name.Replace("(Clone)", "");

        _id = _objectConfigModule.GetObjectInfoIDByName(name);
        _assemblyObjectModule.RegisterAssemblyObjectTransform(_id, transform);
        _jsonAssemblyObject = _assemblyObjectModule.GetJsonAssemblyObjectByID(_id);
        InitialChildPos(out _ID_HasPos_List);
    }
예제 #2
0
    private void SetToValidParentPosition()
    {
        var rigidBody = transform.GetComponent <Rigidbody>();

        for (int i = 0; i < _jsonAssemblyObject.parentIDs.Length; ++i)
        {
            int parentID = _jsonAssemblyObject.parentIDs[i];
            JsonAssemblyObject jsonParent  = _assemblyObjectModule.GetJsonAssemblyObjectByID(parentID);
            Transform[]        parentTrans = _assemblyObjectModule.GetTransformWithoutSelfByID(parentID, transform);
            if (parentTrans == null)
            {
                return;
            }
            for (int j = 0; j < parentTrans.Length; ++j)
            {
                JsonChildPosInfo[] childPosInfos = jsonParent.jsonChildPosInfos;
                if (childPosInfos == null)
                {
                    Debug.LogError("The childPosInfo in null,This is Error!");
                    return;
                }
                for (int k = 0; k < childPosInfos.Length; ++k)
                {
                    if (childPosInfos[k].childID == _id && parentTrans[j].GetComponent <AssemblyObject>().IsHasChildPos(_id, k))
                    {
                        Vector3 validPos = parentTrans[j].TransformPoint(childPosInfos[k].JsonChildPos.ToVector3());
                        if (Vector3.Distance(validPos, transform.position) < 0.07f)
                        {
                            transform.parent           = parentTrans[j];
                            transform.localPosition    = childPosInfos[k].JsonChildPos.ToVector3();
                            transform.localEulerAngles = childPosInfos[k].JsonChildRot.ToVector3();
                            transform.localScale       = childPosInfos[k].JsonChildScal.ToVector3();
                            parentTrans[j].GetComponent <AssemblyObject>().GetAChildPos(k, _id);
                            rigidBody.isKinematic = true;
                            return;
                        }
                    }
                }
            }
        }
        transform.parent      = null;
        rigidBody.isKinematic = false;
    }