Beispiel #1
0
        public static glTF_VCAST_vci_Collider GetglTfColliderFromUnityCollider(Collider unityCollider)
        {
            var type     = unityCollider.GetType();
            var collider = new glTF_VCAST_vci_Collider();

            if (type == typeof(BoxCollider))
            {
                var box = unityCollider as BoxCollider;
                collider.type      = BoxColliderName;
                collider.center    = box.center.ReverseZ().ToArray();
                collider.shape     = box.size.ToArray();
                collider.isTrigger = box.isTrigger;
                if (unityCollider.sharedMaterial != null)
                {
                    collider.physicMaterial =
                        glTF_VCAST_vci_PhysicMaterial.GetglTFPhysicMaterial(unityCollider.sharedMaterial);
                }
                return(collider);
            }
            else if (type == typeof(CapsuleCollider))
            {
                var capsule = unityCollider as CapsuleCollider;
                collider.type      = CapsuleColliderName;
                collider.center    = capsule.center.ReverseZ().ToArray();
                collider.shape     = new float[3];
                collider.shape[0]  = capsule.radius;
                collider.shape[1]  = capsule.height;
                collider.shape[2]  = capsule.direction;
                collider.isTrigger = capsule.isTrigger;
                if (unityCollider.sharedMaterial != null)
                {
                    collider.physicMaterial =
                        glTF_VCAST_vci_PhysicMaterial.GetglTFPhysicMaterial(unityCollider.sharedMaterial);
                }
                return(collider);
            }
            else if (type == typeof(SphereCollider))
            {
                var sphere = unityCollider as SphereCollider;
                collider.type      = SphereColliderName;
                collider.center    = sphere.center.ReverseZ().ToArray();
                collider.shape     = new float[1];
                collider.shape[0]  = sphere.radius;
                collider.isTrigger = sphere.isTrigger;
                if (unityCollider.sharedMaterial != null)
                {
                    collider.physicMaterial =
                        glTF_VCAST_vci_PhysicMaterial.GetglTFPhysicMaterial(unityCollider.sharedMaterial);
                }
                return(collider);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public static Collider AddColliderComponent(GameObject go, glTF_VCAST_vci_Collider collider)
        {
            switch (collider.type)
            {
            case BoxColliderName:
            {
                var unityCollider = go.AddComponent <BoxCollider>();
                unityCollider.center = new Vector3(collider.center[0], collider.center[1], collider.center[2])
                                       .ReverseZ();
                unityCollider.size      = new Vector3(collider.shape[0], collider.shape[1], collider.shape[2]);
                unityCollider.isTrigger = collider.isTrigger;
                if (collider.physicMaterial != null)
                {
                    glTF_VCAST_vci_PhysicMaterial.AddPhysicMaterial(unityCollider, collider.physicMaterial);
                }
                return(unityCollider);
            }

            case CapsuleColliderName:
            {
                var unityCollider = go.AddComponent <CapsuleCollider>();
                unityCollider.center = new Vector3(collider.center[0], collider.center[1], collider.center[2])
                                       .ReverseZ();
                unityCollider.radius    = collider.shape[0];
                unityCollider.height    = collider.shape[1];
                unityCollider.direction = (int)collider.shape[2];
                unityCollider.isTrigger = collider.isTrigger;
                if (collider.physicMaterial != null)
                {
                    glTF_VCAST_vci_PhysicMaterial.AddPhysicMaterial(unityCollider, collider.physicMaterial);
                }
                return(unityCollider);
            }

            default:
            {
                var unityCollider = go.AddComponent <SphereCollider>();
                unityCollider.center = new Vector3(collider.center[0], collider.center[1], collider.center[2])
                                       .ReverseZ();
                unityCollider.radius    = collider.shape[0];
                unityCollider.isTrigger = collider.isTrigger;
                if (collider.physicMaterial != null)
                {
                    glTF_VCAST_vci_PhysicMaterial.AddPhysicMaterial(unityCollider, collider.physicMaterial);
                }
                return(unityCollider);
            }
            }
        }