Esempio n. 1
0
 private void DeleteInvalidJoints(GPUSkinningPlayerJoint[] joints)
 {
     if (joints != null)
     {
         for (int i = 0; i < joints.Length; ++i)
         {
             if (joints[i] != null)
             {
                 for (int j = 0; j < joints[i].transform.childCount; ++j)
                 {
                     Transform child = joints[i].transform.GetChild(j);
                     child.parent        = go.transform;
                     child.localPosition = Vector3.zero;
                 }
                 Object.DestroyImmediate(joints[i].transform.gameObject);
                 GPUSkinningUtil.MarkAllScenesDirty();
             }
         }
     }
 }
Esempio n. 2
0
    private void ConstructJoints()
    {
        if (joints == null)
        {
            GPUSkinningPlayerJoint[] existingJoints = go.GetComponentsInChildren <GPUSkinningPlayerJoint>();

            GPUSkinningBone[] bones = res.anim.bones;
            int numBones            = bones == null ? 0 : bones.Length;
            for (int i = 0; i < numBones; ++i)
            {
                GPUSkinningBone bone = bones[i];
                if (bone.isExposed)
                {
                    if (joints == null)
                    {
                        joints = new List <GPUSkinningPlayerJoint>();
                    }

                    bool inTheExistingJoints = false;
                    if (existingJoints != null)
                    {
                        for (int j = 0; j < existingJoints.Length; ++j)
                        {
                            if (existingJoints[j] != null && existingJoints[j].BoneGUID == bone.guid)
                            {
                                if (existingJoints[j].BoneIndex != i)
                                {
                                    existingJoints[j].Init(i, bone.guid);
                                    GPUSkinningUtil.MarkAllScenesDirty();
                                }
                                joints.Add(existingJoints[j]);
                                existingJoints[j]   = null;
                                inTheExistingJoints = true;
                                break;
                            }
                        }
                    }

                    if (!inTheExistingJoints)
                    {
                        GameObject jointGo = new GameObject(bone.name);
                        jointGo.transform.parent        = go.transform;
                        jointGo.transform.localPosition = Vector3.zero;
                        jointGo.transform.localScale    = Vector3.one;

                        GPUSkinningPlayerJoint joint = jointGo.AddComponent <GPUSkinningPlayerJoint>();
                        joints.Add(joint);
                        joint.Init(i, bone.guid);
                        GPUSkinningUtil.MarkAllScenesDirty();
                    }
                }
            }

            if (!Application.isPlaying)
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.CallbackFunction DelayCall = null;
                DelayCall = () =>
                {
                    UnityEditor.EditorApplication.delayCall -= DelayCall;
                    DeleteInvalidJoints(existingJoints);
                };
                UnityEditor.EditorApplication.delayCall += DelayCall;
#endif
            }
            else
            {
                DeleteInvalidJoints(existingJoints);
            }
        }
    }