Beispiel #1
0
        // Update is called once per frame
        void Update()
        {
            if (ep == null)
            {
                ep = GetComponent <ExpressionPlayer>();
                return;
            }

            for (int i = 0; i < ExpressionPlayer.PoseCount; i++)
            {
                if (!currentUseControl[i])
                {
                    currentTargetValues[i] = 0.0f;
                }
            }
            ep.Values = currentTargetValues;
        }
Beispiel #2
0
    public void Creat()
    {
        IObjectBase iob = new ObjectBase(fbx);
        Object      o   = iob.Load();

        go      = GameObject.Instantiate(o) as GameObject;
        go.name = name;

        SkinnedMeshRenderer[] smrs = go.GetComponentsInChildren <SkinnedMeshRenderer>();
        for (int i = 0; i < smrs.Length; i++)
        {
            if (smrs[i].gameObject.name.EndsWith("_Face"))
            {
                smrs[i].sharedMaterial = faceMat;
            }
            else
            {
                smrs[i].sharedMaterial = bodyMat;
            }
        }


        Animator an = go.GetComponent <Animator>();

        if (an)
        {
            GameObject.DestroyImmediate(an);
        }

        Transform skeletonRoot = go.transform.FindChild(rig);

        IObjectBase      set = new ObjectBase(expression_Set);
        UMAExpressionSet expressionPlayer = set.Load <UMAExpressionSet>();

        anim = go.AddComponent <Animation>();
        ep   = go.AddComponent <ExpressionPlayer>();
        EditModeExpressionPreview emp = go.AddComponent <EditModeExpressionPreview>();

        emp.expressionPlayer = ep;
        emp.expressionSet    = expressionPlayer;
        emp.skeletonRoot     = skeletonRoot;
        go.name = name;

        Selection.activeGameObject = go;//selected
    }
        public void UMAConfigure(UMAData umaData)
        {
            animator = umaData.animator;
            ep       = umaData.GetComponent <ExpressionPlayer>();
            expressionControlValues = new float[ExpressionPlayer.PoseCount];
            poseHandler             = new HumanPoseHandler(animator.avatar, transform);

            Transform head     = umaData.GetBoneGameObject("Head").transform;
            Transform skulltop = head.Find("skulltop");

            if (skulltop == null)
            {
                skulltop               = new GameObject("skulltop").transform;
                skulltop.parent        = head;
                skulltop.localPosition = new Vector3(-0.225f, 0.0f, 0.0f);
                skulltop.localRotation = Quaternion.identity;
            }

            headcenter = head.Find("head_" + id);
            if (headcenter == null)
            {
                headcenter               = new GameObject("head_" + id).transform;
                headcenter.parent        = head;
                headcenter.localPosition = new Vector3(-0.115f, 0.0f, 0.0f);
                headcenter.localRotation = Quaternion.identity;
                headcenter.gameObject.AddComponent <WorldObject>();
            }

            Transform LeftToeBase    = umaData.GetBoneGameObject("LeftToeBase").transform;
            Transform l_forefoot_tip = LeftToeBase.Find("l_forefoot_tip");

            if (l_forefoot_tip == null)
            {
                l_forefoot_tip               = new GameObject("l_forefoot_tip").transform;
                l_forefoot_tip.parent        = LeftToeBase;
                l_forefoot_tip.localRotation = Quaternion.identity;
                l_forefoot_tip.localPosition = new Vector3(-0.1f, 0.0f, 0.0f);
            }

            Transform RightToeBase   = umaData.GetBoneGameObject("RightToeBase").transform;
            Transform r_forefoot_tip = RightToeBase.Find("r_forefoot_tip");

            if (r_forefoot_tip == null)
            {
                r_forefoot_tip               = new GameObject("r_forefoot_tip").transform;
                r_forefoot_tip.parent        = RightToeBase;
                r_forefoot_tip.localRotation = Quaternion.identity;
                r_forefoot_tip.localPosition = new Vector3(-0.1f, 0.0f, 0.0f);
            }

            positionBone               = umaData.GetBoneGameObject("Position").transform;
            humanoidRoot               = new GameObject("HumanoidRoot").transform;
            rootToHipsOffset           = new Vector3(0.0f, 0.025f, 0f);
            humanoidRoot.position      = umaData.GetBoneGameObject("Hips").transform.position - rootToHipsOffset;
            humanoidRoot.parent        = positionBone;
            humanoidRoot.localRotation = Quaternion.identity;

            //hipShouldBeHere = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
            //hipShouldBeHere.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            //hipShouldBeHere.position = humanoidRoot.position;

            twistBones = GetComponentInChildren <TwistBones>();
            umaData.GetBoneGameObject("Hips").transform.parent = humanoidRoot;
            Initialize();
            umaData.GetBoneGameObject("Hips").transform.parent = positionBone;
        }
Beispiel #4
0
        private void SetRagdolled(bool ragdollState)
        {
            if (!Application.isPlaying)
            {
                _ragdolled = false;
                return;
            }

            //Player Collider stuff
            //Call Player Collider enable/disable event here
            if (ragdollState)
            {
                if (onRagdollStarted != null)
                {
                    onRagdollStarted.Invoke();
                }
            }
            else
            {
                if (onRagdollEnded != null)
                {
                    onRagdollEnded.Invoke();
                }
            }

            if (simplePlayerCollider)
            {
                if (_playerRigidbody)
                {
                    _playerRigidbody.isKinematic = ragdollState;
                }

                if (_playerCollider)
                {
                    _playerCollider.enabled = !ragdollState;
                }
            }

            // iterate through all rigidbodies and switch kinematic mode on/off
            //Set all rigidbodies.isKinematic to opposite of ragdolled state
            SetAllKinematic(!ragdollState);

            if (enableColliderTriggers)              //Change the trigger state on collider if we enable this flag.
            {
                SetBodyColliders(!ragdollState);
            }

            // switch animator on/off
            Animator animator = GetComponent <Animator>();

            if (animator != null)
            {
                animator.enabled = !ragdollState;
            }
            // switch expression player (locks head if left on)
            ExpressionPlayer expressionPlayer = GetComponent <ExpressionPlayer>();

            if (expressionPlayer != null)
            {
                expressionPlayer.enabled = !ragdollState;
            }

            // Prevent Mismatched Culling
            // Skinned mesh renderers cull based on their origonal position before ragdolling.
            // We use this property to prevent ragdolled meshes from popping in and out unexpectedly.
            SetUpdateWhenOffscreen(ragdollState);

            if (_ragdolled && !ragdollState)
            {
                //We were ragdolled and now we're not
                if (UpdateTransformAfterRagdoll)
                {
                    gameObject.transform.position = _rootBone.transform.position;
                }
            }

            _ragdolled = ragdollState;
        }
Beispiel #5
0
        public void UMAConfigure(UMAData umaData)
        {
            animator = umaData.animator;
            ep       = umaData.GetComponent <ExpressionPlayer>();
            expressionControlValues = new float[ExpressionPlayer.PoseCount];
            poseHandler             = new HumanPoseHandler(animator.avatar, transform);

            Transform head     = umaData.GetBoneGameObject("Head").transform;
            Transform skulltop = head.Find("skulltop");

            if (skulltop == null)
            {
                skulltop               = new GameObject("skulltop").transform;
                skulltop.rotation      = Quaternion.identity;
                skulltop.parent        = head;
                skulltop.localPosition = new Vector3(-0.225f, 0.0f, 0.0f);
            }

            headcenter = head.Find("headcenter_LOG");
            if (headcenter == null)
            {
                headcenter               = new GameObject("headcenter_LOG").transform;
                headcenter.rotation      = Quaternion.identity;
                headcenter.parent        = head;
                headcenter.localPosition = new Vector3(-0.115f, 0.0f, 0.0f);
            }

            leftEye = head.Find("leftEye_LOG");
            if (leftEye == null)
            {
                leftEye               = new GameObject("leftEye_LOG").transform;
                leftEye.rotation      = Quaternion.identity;
                leftEye.parent        = head.Find("LeftEye").Find("LeftEyeGlobe");
                leftEye.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
            }

            rightEye = head.Find("rightEye_LOG");
            if (rightEye == null)
            {
                rightEye               = new GameObject("rightEye_LOG").transform;
                rightEye.rotation      = Quaternion.identity;
                rightEye.parent        = head.Find("RightEye").Find("RightEyeGlobe");
                rightEye.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
            }


            Transform LeftToeBase    = umaData.GetBoneGameObject("LeftToeBase").transform;
            Transform l_forefoot_tip = LeftToeBase.Find("l_forefoot_tip");

            if (l_forefoot_tip == null)
            {
                l_forefoot_tip               = new GameObject("l_forefoot_tip").transform;
                l_forefoot_tip.parent        = LeftToeBase;
                l_forefoot_tip.localRotation = Quaternion.identity;
                l_forefoot_tip.localPosition = new Vector3(-0.1f, 0.0f, 0.0f);
            }

            Transform RightToeBase   = umaData.GetBoneGameObject("RightToeBase").transform;
            Transform r_forefoot_tip = RightToeBase.Find("r_forefoot_tip");

            if (r_forefoot_tip == null)
            {
                r_forefoot_tip               = new GameObject("r_forefoot_tip").transform;
                r_forefoot_tip.parent        = RightToeBase;
                r_forefoot_tip.localRotation = Quaternion.identity;
                r_forefoot_tip.localPosition = new Vector3(-0.1f, 0.0f, 0.0f);
            }

            positionBone               = umaData.GetBoneGameObject("Position").transform;
            humanoidRoot               = new GameObject("HumanoidRoot").transform;
            humanoidRoot.position      = umaData.GetBoneGameObject("Hips").transform.position - new Vector3(0f, 0.025f, 0f);
            humanoidRoot.parent        = positionBone;
            humanoidRoot.localRotation = Quaternion.identity;
            twistBones = GetComponentInChildren <TwistBones>();
            umaData.GetBoneGameObject("Hips").transform.parent = humanoidRoot;
            Initialize();
            umaData.GetBoneGameObject("Hips").transform.parent = positionBone;
        }