Пример #1
0
    void FixedUpdate()
    {
        if (!bInitDevice)
        {
            if (bCheckedDevices)
            {
                bInitDevice = true;
                switch (eAutoMotionCaptureDevicesSelecter)
                {
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_2:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_3:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_4:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_5:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_6:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_7:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_8:
                    int iDeviceSelect = eAutoMotionCaptureDevicesSelecter - EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1;
                    int iSelect       = 0;
                    foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
                    {
                        if (iDeviceSelect == iSelect)
                        {
                            GameObject goTopPerceptionNeuron = null;
                            if (sNeuronConnection.goAttach == null)
                            {
                                goTopPerceptionNeuron = Instantiate(sNeuronConnection.prefabDeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                                sNeuronConnections[iSelect].goAttach          = this.gameObject;
                                goTopPerceptionNeuron.transform.parent        = this.gameObject.transform;
                                goTopPerceptionNeuron.transform.localPosition = sNeuronConnections[iSelect].goAttach.transform.localPosition;
                                goTopPerceptionNeuron.transform.localRotation = sNeuronConnections[iSelect].goAttach.transform.localRotation;
                                goTopPerceptionNeuron.transform.localScale    = sNeuronConnections[iSelect].goAttach.transform.localScale;
                            }
                            else
                            {
                                goTopPerceptionNeuron = Instantiate(sNeuronConnection.prefabDeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                                goTopPerceptionNeuron.transform.parent        = sNeuronConnection.goAttach.transform;
                                goTopPerceptionNeuron.transform.localPosition = sNeuronConnection.goAttach.transform.localPosition;
                                goTopPerceptionNeuron.transform.localRotation = sNeuronConnection.goAttach.transform.localRotation;
                                goTopPerceptionNeuron.transform.localScale    = sNeuronConnection.goAttach.transform.localScale;
                            }
                            if (goTopPerceptionNeuron != null)
                            {
                                NeuronAnimatorInstance sNeuronAnimatorInstance = goTopPerceptionNeuron.GetComponent <NeuronAnimatorInstance>();
                                sNeuronAnimatorInstance.address = sNeuronConnection.address;
                                sNeuronAnimatorInstance.port    = sNeuronConnection.port;
                                //sNeuronAnimatorInstance.commandServerPort = sNeuronConnection.commandServerPort;
                                sNeuronAnimatorInstance.socketType       = sNeuronConnection.socketType;
                                sNeuronAnimatorInstance.actorID          = sNeuronConnection.actorID;
                                sNeuronAnimatorInstance.connectToAxis    = true;
                                sNeuronAnimatorInstance.bFixedUpdateMode = bFixedUpdateMode;
                                sNeuronAnimatorInstance.enabled          = true;
                            }
                        }
                        iSelect++;
                    }
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect1:
                    if (goKinect1_Attach == null)
                    {
                        GameObject goTopKinect1 = Instantiate(prefabKinect1_DeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                        goKinect1_Attach = this.gameObject;
                        goTopKinect1.transform.parent        = goKinect1_Attach.transform;
                        goTopKinect1.transform.localPosition = goKinect1_Attach.transform.localPosition;
                        goTopKinect1.transform.localRotation = goKinect1_Attach.transform.localRotation;
                        goTopKinect1.transform.localScale    = goKinect1_Attach.transform.localScale;
                        Kinect1ModelControllerV2 sKinect1ModelControllerV2 = goTopKinect1.GetComponentInChildren <Kinect1ModelControllerV2>();
                        if (sKinect1ModelControllerV2 != null)
                        {
                            sKinect1ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect1ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                            sKinect1ModelControllerV2.bFixedUpdateMode     = bFixedUpdateMode;
                            sKinect1ModelControllerV2.iFPS          = iFPS;
                            sKinect1ModelControllerV2.fLerpPosition = fLerpPosition;
                            sKinect1ModelControllerV2.fLerpRotation = fLerpRotation;
                        }
                    }
                    else
                    {
                        GameObject goTopKinect1 = Instantiate(prefabKinect1_DeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                        goTopKinect1.transform.parent        = goKinect1_Attach.transform;
                        goTopKinect1.transform.localPosition = goKinect1_Attach.transform.localPosition;
                        goTopKinect1.transform.localRotation = goKinect1_Attach.transform.localRotation;
                        goTopKinect1.transform.localScale    = goKinect1_Attach.transform.localScale;
                        Kinect1ModelControllerV2 sKinect1ModelControllerV2 = goTopKinect1.GetComponentInChildren <Kinect1ModelControllerV2>();
                        if (sKinect1ModelControllerV2 != null)
                        {
                            sKinect1ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect1ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                            sKinect1ModelControllerV2.bFixedUpdateMode     = bFixedUpdateMode;
                            sKinect1ModelControllerV2.iFPS          = iFPS;
                            sKinect1ModelControllerV2.fLerpPosition = fLerpPosition;
                            sKinect1ModelControllerV2.fLerpRotation = fLerpRotation;
                        }
                    }
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect2:
                    if (goKinect2_Attach == null)
                    {
                        GameObject goTopKinect2 = Instantiate(prefabKinect2_DeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                        goKinect2_Attach = this.gameObject;
                        goTopKinect2.transform.parent        = goKinect2_Attach.transform;
                        goTopKinect2.transform.localPosition = goKinect2_Attach.transform.localPosition;
                        goTopKinect2.transform.localRotation = goKinect2_Attach.transform.localRotation;
                        goTopKinect2.transform.localScale    = goKinect2_Attach.transform.localScale;
                        Kinect2ModelControllerV2 sKinect2ModelControllerV2 = goTopKinect2.GetComponentInChildren <Kinect2ModelControllerV2>();
                        if (sKinect2ModelControllerV2 != null)
                        {
                            sKinect2ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect2ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                            sKinect2ModelControllerV2.bFixedUpdateMode     = bFixedUpdateMode;
                            sKinect2ModelControllerV2.iFPS          = iFPS;
                            sKinect2ModelControllerV2.fLerpPosition = fLerpPosition;
                            sKinect2ModelControllerV2.fLerpRotation = fLerpRotation;
                        }
                    }
                    else
                    {
                        GameObject goTopKinect2 = Instantiate(prefabKinect2_DeviceJoints, Vector3.zero, Quaternion.identity) as GameObject;
                        goTopKinect2.transform.parent        = goKinect2_Attach.transform;
                        goTopKinect2.transform.localPosition = goKinect2_Attach.transform.localPosition;
                        goTopKinect2.transform.localRotation = goKinect2_Attach.transform.localRotation;
                        goTopKinect2.transform.localScale    = goKinect2_Attach.transform.localScale;
                        Kinect2ModelControllerV2 sKinect2ModelControllerV2 = goTopKinect2.GetComponentInChildren <Kinect2ModelControllerV2>();
                        if (sKinect2ModelControllerV2 != null)
                        {
                            sKinect2ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect2ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                            sKinect2ModelControllerV2.bFixedUpdateMode     = bFixedUpdateMode;
                            sKinect2ModelControllerV2.iFPS          = iFPS;
                            sKinect2ModelControllerV2.fLerpPosition = fLerpPosition;
                            sKinect2ModelControllerV2.fLerpRotation = fLerpRotation;
                        }
                    }
                    break;
                }
            }
        }
        else
        {
            if (!bInitTransform)
            {
                bInitTransform = true;
                switch (eAutoMotionCaptureDevicesSelecter)
                {
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_2:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_3:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_4:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_5:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_6:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_7:
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_8:
                    int iDeviceSelect = eAutoMotionCaptureDevicesSelecter - EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1;
                    int iSelect       = 0;
                    foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
                    {
                        if (iDeviceSelect == iSelect)
                        {
                            if (sNeuronConnection.goAttach != null)
                            {
                                sNeuronConnection.goAttach.transform.localPosition = sNeuronConnection.vecPosition;
                                sNeuronConnection.goAttach.transform.localRotation = Quaternion.Euler(sNeuronConnection.vecRotation);
                                sNeuronConnection.goAttach.transform.localScale    = sNeuronConnection.vecScale;
                            }
                        }
                        iSelect++;
                    }
                    //iInitReadyFrame = 120;
                    bInitMoveTransform = true;
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect1:
                    if (goKinect1_Attach != null)
                    {
                        goKinect1_Attach.transform.localPosition = vecKinect1_Position;
                        goKinect1_Attach.transform.localRotation = Quaternion.Euler(vecKinect1_Rotation);
                        goKinect1_Attach.transform.localScale    = vecKinect1_Scale;
                    }
                    //iInitReadyFrame = 120;
                    //bInitMoveTransform = true;
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect2:
                    if (goKinect2_Attach != null)
                    {
                        goKinect2_Attach.transform.localPosition = vecKinect2_Position;
                        goKinect2_Attach.transform.localRotation = Quaternion.Euler(vecKinect2_Rotation);
                        goKinect2_Attach.transform.localScale    = vecKinect2_Scale;
                    }
                    //iInitReadyFrame = 120;
                    //bInitMoveTransform = true;
                    break;
                }
            }
            else
            {
                if (!bInitEnableAnimator)
                {
                    if (bInitMoveTransform)
                    {
                        bInitEnableAnimator = true;
                        foreach (GameObject goLiveAnimator in goLiveAnimators)
                        {
                            HumanPoseRetargetLiveAnimator sHumanPoseRetargetLiveAnimator = goLiveAnimator.GetComponent <HumanPoseRetargetLiveAnimator>();
                            if (sHumanPoseRetargetLiveAnimator != null)
                            {
                                sHumanPoseRetargetLiveAnimator.bFixedUpdateMode = bFixedUpdateMode;
                                sHumanPoseRetargetLiveAnimator.iFPS             = iFPS;
                                sHumanPoseRetargetLiveAnimator.fLerpPosition    = fLerpPosition;
                                sHumanPoseRetargetLiveAnimator.fLerpRotation    = fLerpRotation;
                            }
                            HumanBodyBonesLiveAnimator HumanBodyBonesLiveAnimators = goLiveAnimator.GetComponent <HumanBodyBonesLiveAnimator>();
                            if (HumanBodyBonesLiveAnimators != null)
                            {
                                HumanBodyBonesLiveAnimators.bFixedUpdateMode = bFixedUpdateMode;
                                HumanBodyBonesLiveAnimators.iFPS             = iFPS;
                                HumanBodyBonesLiveAnimators.fLerpPosition    = fLerpPosition;
                                HumanBodyBonesLiveAnimators.fLerpRotation    = fLerpRotation;
                            }
                            HumanoidAvatarLiveAnimator sHumanoidAvatarLiveAnimator = goLiveAnimator.GetComponent <HumanoidAvatarLiveAnimator>();
                            if (sHumanoidAvatarLiveAnimator != null)
                            {
                                sHumanoidAvatarLiveAnimator.bFixedUpdateMode      = bFixedUpdateMode;
                                sHumanoidAvatarLiveAnimator.iFPS                  = iFPS;
                                sHumanoidAvatarLiveAnimator.fLerpPosition         = fLerpPosition;
                                sHumanoidAvatarLiveAnimator.fLerpRotation         = fLerpRotation;
                                sHumanoidAvatarLiveAnimator.bInitedEnableAnimator = true;
                            }
                        }
                    }
                }
                else
                {
                    if (iInitReadyFrame >= 0)
                    {
                        iInitReadyFrame--;
                        foreach (GameObject goLiveAnimator in goLiveAnimators)
                        {
                            if (goLiveAnimator != null)
                            {
                                if (goLiveAnimator.activeInHierarchy)
                                {
                                    HumanPoseRetargetLiveAnimator sHumanPoseRetargetLiveAnimator = goLiveAnimator.GetComponent <HumanPoseRetargetLiveAnimator>();
                                    if (sHumanPoseRetargetLiveAnimator != null)
                                    {
                                        if (iInitReadyFrame <= 0)
                                        {
                                            sHumanPoseRetargetLiveAnimator.bInitReady = true;
                                        }
                                    }
                                    HumanoidAvatarLiveAnimator sHumanoidAvatarLiveAnimator = goLiveAnimator.GetComponent <HumanoidAvatarLiveAnimator>();
                                    if (sHumanoidAvatarLiveAnimator != null)
                                    {
                                        if (iInitReadyFrame <= 0)
                                        {
                                            sHumanoidAvatarLiveAnimator.bInitReady = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!bAllInited)
                    {
                        bool bAllInitedCheck = true;
                        foreach (GameObject goLiveAnimator in goLiveAnimators)
                        {
                            if (goLiveAnimator != null)
                            {
                                if (goLiveAnimator.activeInHierarchy)
                                {
                                    HumanPoseRetargetLiveAnimator sHumanPoseRetargetLiveAnimator = goLiveAnimator.GetComponent <HumanPoseRetargetLiveAnimator>();
                                    if (sHumanPoseRetargetLiveAnimator != null)
                                    {
                                        if (sHumanPoseRetargetLiveAnimator.enabled)
                                        {
                                            if (!sHumanPoseRetargetLiveAnimator.bInited)
                                            {
                                                bAllInitedCheck = false;
                                            }
                                        }
                                    }
                                    HumanoidAvatarLiveAnimator sHumanoidAvatarLiveAnimator = goLiveAnimator.GetComponent <HumanoidAvatarLiveAnimator>();
                                    if (sHumanoidAvatarLiveAnimator != null)
                                    {
                                        if (sHumanoidAvatarLiveAnimator.enabled)
                                        {
                                            if (!sHumanoidAvatarLiveAnimator.bInited)
                                            {
                                                bAllInitedCheck = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (bAllInitedCheck)
                        {
                            bAllInited = true;
                            if (sFBXExporterForUnity != null)
                            {
                                sFBXExporterForUnity.bOutAnimation = true;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (!bInitDevice)
        {
            if (bCheckedDevices)
            {
                bInitDevice = true;
                switch (eAutoMotionCaptureDevicesSelecter)
                {
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron:
                    if (goNeuron_Attach == null)
                    {
                        GameObject goTopPerceptionNeuron = Instantiate(prefabNeuron_DeviceJoints) as GameObject;
                        goNeuron_Attach = this.gameObject;
                        goTopPerceptionNeuron.transform.parent = goNeuron_Attach.transform;
                    }
                    else
                    {
                        GameObject goTopPerceptionNeuron = Instantiate(prefabNeuron_DeviceJoints, goNeuron_Attach.transform.position, goNeuron_Attach.transform.rotation) as GameObject;
                        goTopPerceptionNeuron.transform.localPosition = goNeuron_Attach.transform.localPosition;
                        goTopPerceptionNeuron.transform.localRotation = goNeuron_Attach.transform.localRotation;
                        goTopPerceptionNeuron.transform.localScale    = goNeuron_Attach.transform.localScale;
                        goTopPerceptionNeuron.transform.parent        = goKinect1_Attach.transform;
                    }
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect1:
                    if (goKinect1_Attach == null)
                    {
                        GameObject goTopKinect1 = Instantiate(prefabKinect1_DeviceJoints) as GameObject;
                        goKinect1_Attach = this.gameObject;
                        goTopKinect1.transform.parent = goKinect1_Attach.transform;
                        Kinect1ModelControllerV2 sKinect1ModelControllerV2 = goTopKinect1.GetComponentInChildren <Kinect1ModelControllerV2>();
                        if (sKinect1ModelControllerV2 != null)
                        {
                            sKinect1ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect1ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                        }
                    }
                    else
                    {
                        GameObject goTopKinect1 = Instantiate(prefabKinect1_DeviceJoints, goKinect1_Attach.transform.position, goKinect1_Attach.transform.rotation) as GameObject;
                        goTopKinect1.transform.localPosition = goKinect1_Attach.transform.localPosition;
                        goTopKinect1.transform.localRotation = goKinect1_Attach.transform.localRotation;
                        goTopKinect1.transform.localScale    = goKinect1_Attach.transform.localScale;
                        goTopKinect1.transform.parent        = goKinect1_Attach.transform;
                        Kinect1ModelControllerV2 sKinect1ModelControllerV2 = goTopKinect1.GetComponentInChildren <Kinect1ModelControllerV2>();
                        if (sKinect1ModelControllerV2 != null)
                        {
                            sKinect1ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect1ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                        }
                    }
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect2:
                    if (goKinect2_Attach == null)
                    {
                        GameObject goTopKinect2 = Instantiate(prefabKinect2_DeviceJoints) as GameObject;
                        goKinect2_Attach = this.gameObject;
                        goTopKinect2.transform.parent = goKinect2_Attach.transform;
                        Kinect2ModelControllerV2 sKinect2ModelControllerV2 = goTopKinect2.GetComponentInChildren <Kinect2ModelControllerV2>();
                        if (sKinect2ModelControllerV2 != null)
                        {
                            sKinect2ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect2ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                        }
                    }
                    else
                    {
                        GameObject goTopKinect2 = Instantiate(prefabKinect2_DeviceJoints, goKinect2_Attach.transform.position, goKinect2_Attach.transform.rotation) as GameObject;
                        goTopKinect2.transform.localPosition = goKinect2_Attach.transform.localPosition;
                        goTopKinect2.transform.localRotation = goKinect2_Attach.transform.localRotation;
                        goTopKinect2.transform.localScale    = goKinect2_Attach.transform.localScale;
                        goTopKinect2.transform.parent        = goKinect2_Attach.transform;
                        Kinect2ModelControllerV2 sKinect2ModelControllerV2 = goTopKinect2.GetComponentInChildren <Kinect2ModelControllerV2>();
                        if (sKinect2ModelControllerV2 != null)
                        {
                            sKinect2ModelControllerV2.sAutoMotionCaptureDevicesSelecter = this;
                            sKinect2ModelControllerV2.sFBXExporterForUnity = sFBXExporterForUnity;
                        }
                    }
                    break;
                }
            }
        }
        else
        {
            if (!bInitTransform)
            {
                bInitTransform = true;
                foreach (HumanoidAvatarLiveAnimator sHumanoidAvatarLiveAnimator in sHumanoidAvatarLiveAnimators)
                {
                    sHumanoidAvatarLiveAnimator.bInitReady = true;
                }
                switch (eAutoMotionCaptureDevicesSelecter)
                {
                case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron:
                    if (goNeuron_Attach != null)
                    {
                        goNeuron_Attach.transform.localPosition = vecNeuron_Position;
                        goNeuron_Attach.transform.localRotation = Quaternion.Euler(vecNeuron_Rotation);
                        goNeuron_Attach.transform.localScale    = vecNeuron_Scale;
                    }
                    bMoveTransform = true;
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect1:
                    if (goKinect1_Attach != null)
                    {
                        goKinect1_Attach.transform.localPosition = vecKinect1_Position;
                        goKinect1_Attach.transform.localRotation = Quaternion.Euler(vecKinect1_Rotation);
                        goKinect1_Attach.transform.localScale    = vecKinect1_Scale;
                    }
                    break;

                case EAutoMotionCaptureDevicesSelecter.eKinect2:
                    if (goKinect2_Attach != null)
                    {
                        goKinect2_Attach.transform.localPosition = vecKinect2_Position;
                        goKinect2_Attach.transform.localRotation = Quaternion.Euler(vecKinect2_Rotation);
                        goKinect2_Attach.transform.localScale    = vecKinect2_Scale;
                    }
                    break;
                }
            }
            else
            {
                if (!bEnableAnimator)
                {
                    if (bMoveTransform)
                    {
                        if (sFBXExporterForUnity != null)
                        {
                            sFBXExporterForUnity.bOutAnimation = true;
                        }
                        bEnableAnimator = true;
                        foreach (HumanoidAvatarLiveAnimator sHumanoidAvatarLiveAnimator in sHumanoidAvatarLiveAnimators)
                        {
                            sHumanoidAvatarLiveAnimator.bEnableAnimator = true;
                        }
                    }
                }
            }
        }
    }