public JsonCollider(Collider col, int colliderIndex_, ResourceMapper resMap)
        {
            colliderIndex = colliderIndex_;
            if (!col)
            {
                throw new System.ArgumentNullException("col");
            }
            if (resMap == null)
            {
                throw new System.ArgumentNullException("resMap");
            }
            var box     = col as BoxCollider;
            var sphere  = col as SphereCollider;
            var capsule = col as CapsuleCollider;
            var meshCol = col as MeshCollider;

            collider = col;
            if (box)
            {
                colliderType = colliderTypeBox;
                center       = box.center;
                size         = box.size;
            }
            if (sphere)
            {
                colliderType = colliderTypeSphere;
                center       = sphere.center;
                radius       = sphere.radius;
            }
            if (capsule)
            {
                colliderType = colliderTypeCapsule;
                center       = capsule.center;
                radius       = capsule.radius;
                height       = capsule.height;
                direction    = capsule.direction;
            }
            if (meshCol)
            {
                colliderType = colliderTypeMesh;
                meshId       = resMap.getMeshId(meshCol.sharedMesh,
                                                meshCol.convex ? MeshUsageFlags.ConvexCollider: MeshUsageFlags.TriangleCollider
                                                );

                bool isConvex = meshCol.convex;

                /*
                 * if (resMap.isValidMeshId(meshId))
                 *      resMap.flagMeshId(meshId, isConvex, !isConvex);//by default there will be no flags on a mesh...
                 */
            }
        }
Exemplo n.º 2
0
        public MeshIdData(GameObject srcObj, ResourceMapper resMap)
        {
            if (!srcObj)
            {
                return;
            }
            var filter = srcObj.GetComponent <MeshFilter>();

            if (filter && filter.sharedMesh)
            {
                meshId = resMap.getMeshId(filter.sharedMesh, MeshUsageFlags.None);
            }
            var renderer = srcObj.GetComponent <Renderer>();

            if (renderer)
            {
                foreach (var cur in renderer.sharedMaterials)
                {
                    meshMaterials.Add(resMap.getMaterialId(cur));
                }
            }
        }