コード例 #1
0
        public ResourceObject Parse(ByteBuffer bb)
        {
            Schema.Skeletons skeleton = Schema.Skeletons.GetRootAsSkeletons(bb);
            GameObject[]     goes     = new GameObject[skeleton.JointsLength];
            for (int i = 0; i < skeleton.JointsLength; i++)
            {
                Schema.Joint joint = skeleton.GetJoints(i);
                GameObject   go    = new GameObject(joint.Names);

                // 设置局部 Transform 一定要在设置父节点之后进行,否则会因为设置了父节点导致局部transform而改变
                if (joint.Parent >= 0)
                {
                    go.transform.parent = goes[joint.Parent].transform;
                }

                Vec3 pos = joint.Transform.Pos;
                go.transform.localPosition = new Vector3(pos.X, pos.Y, pos.Z);

                Quat quat = joint.Transform.Rot;
                go.transform.localRotation = new Quaternion(quat.X, quat.Y, quat.Z, quat.W);

                Vec3 scl = joint.Transform.Scl;
                go.transform.localScale = new Vector3(scl.X, scl.Y, scl.Z);

                goes[i] = go;
            }

            goes [0].hideFlags |= HideFlags.HideInHierarchy;
            //GameObject.DontDestroyOnLoad (goes [0]);
            return(new ResourceObjectSingle(goes[0]));
        }
コード例 #2
0
        public void AllSourceBeExported()
        {
            List <UnityEngine.Transform> lstTfs = new List <UnityEngine.Transform> ();

            CollectTransforms.Do(lstTfs, go.transform);

            HashSet <string> hashJoints = new HashSet <string> ();

            for (int i = 0; i < skeletons.JointsLength; i++)
            {
                Schema.Joint j = skeletons.GetJoints(i);
                hashJoints.Add(j.Names);
            }

            for (int i = 0; i < lstTfs.Count; i++)
            {
                Assert.IsTrue(hashJoints.Contains(lstTfs [i].name));
            }
        }
コード例 #3
0
        public void JointEqualSource()
        {
            List <UnityEngine.Transform> lstTfs = new List <UnityEngine.Transform> ();

            CollectTransforms.Do(lstTfs, go.transform);
            Dictionary <string, UnityEngine.Transform> dictTfs = new Dictionary <string, UnityEngine.Transform> ();

            for (int i = 0; i < lstTfs.Count; i++)
            {
                dictTfs.Add(lstTfs [i].name, lstTfs [i]);
            }

            for (int i = 0; i < skeletons.JointsLength; i++)
            {
                Schema.Joint j = skeletons.GetJoints(i);

                Assert.IsTrue(dictTfs.ContainsKey(j.Names));
                UnityEngine.Transform tf = dictTfs [j.Names];

                Renderer r = tf.gameObject.GetComponent <Renderer> ();
                Assert.IsTrue(r == null);

                string parentGoName    = (tf.parent != go.transform) ? tf.parent.name : null;
                string parentJointName = (j.Parent >= 0) ? skeletons.GetJoints(j.Parent).Names : null;
                Assert.AreEqual(parentGoName, parentJointName);

                Assert.Less(Mathf.Abs(tf.localPosition.x - j.Transform.Pos.X), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localPosition.y - j.Transform.Pos.Y), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localPosition.z - j.Transform.Pos.Z), 0.0001f);

                Assert.Less(Mathf.Abs(tf.localRotation.x - j.Transform.Rot.X), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localRotation.y - j.Transform.Rot.Y), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localRotation.z - j.Transform.Rot.Z), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localRotation.w - j.Transform.Rot.W), 0.0001f);

                Assert.Less(Mathf.Abs(tf.localScale.x - j.Transform.Scl.X), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localScale.y - j.Transform.Scl.Y), 0.0001f);
                Assert.Less(Mathf.Abs(tf.localScale.z - j.Transform.Scl.Z), 0.0001f);
            }
        }
コード例 #4
0
        public void JointNoMultiple()
        {
            Dictionary <string, int> dictCount = new Dictionary <string, int>();

            for (int i = 0; i < skeletons.JointsLength; i++)
            {
                Schema.Joint j = skeletons.GetJoints(i);
                if (dictCount.ContainsKey(j.Names))
                {
                    dictCount[j.Names]++;
                }
                else
                {
                    dictCount.Add(j.Names, 1);
                }
            }
            Dictionary <string, int> .Enumerator e = dictCount.GetEnumerator();
            while (e.MoveNext())
            {
                Assert.AreEqual(e.Current.Value, 1);
            }
        }
コード例 #5
0
 public Joint GetJoints(Joint obj, int j)
 {
     int o = __offset(4); return(o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null);
 }