public static glTF_VCAST_vci_Collider glTF_VCAST_vci_colliders_Deserializevci_colliders_ITEM(JsonNode parsed)
        {
            var value = new glTF_VCAST_vci_Collider();

            foreach (var kv in parsed.ObjectItems())
            {
                var key = kv.Key.GetString();

                if (key == "type")
                {
                    value.type = kv.Value.GetString();
                    continue;
                }

                if (key == "layer")
                {
                    value.layer = kv.Value.GetString();
                    continue;
                }

                if (key == "center")
                {
                    value.center = glTF_VCAST_vci_colliders_Deserializevci_colliders__center(kv.Value);
                    continue;
                }

                if (key == "shape")
                {
                    value.shape = glTF_VCAST_vci_colliders_Deserializevci_colliders__shape(kv.Value);
                    continue;
                }

                if (key == "grabable")
                {
                    value.grabable = kv.Value.GetBoolean();
                    continue;
                }

                if (key == "useGravity")
                {
                    value.useGravity = kv.Value.GetBoolean();
                    continue;
                }

                if (key == "isTrigger")
                {
                    value.isTrigger = kv.Value.GetBoolean();
                    continue;
                }

                if (key == "physicMaterial")
                {
                    value.physicMaterial = glTF_VCAST_vci_colliders_Deserializevci_colliders__physicMaterial(kv.Value);
                    continue;
                }
            }
            return(value);
        }
Exemple #2
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);
            }
        }
        public static void Serialize_vci_colliders_ITEM(JsonFormatter f, glTF_VCAST_vci_Collider value)
        {
            f.BeginMap();


            if (!string.IsNullOrEmpty(value.type))
            {
                f.Key("type");
                f.Value(value.type);
            }

            if (!string.IsNullOrEmpty(value.layer))
            {
                f.Key("layer");
                f.Value(value.layer);
            }

            if (value.center != null && value.center.Length >= 3)
            {
                f.Key("center");
                Serialize_vci_colliders__center(f, value.center);
            }

            if (value.shape != null && value.shape.Length >= 1)
            {
                f.Key("shape");
                Serialize_vci_colliders__shape(f, value.shape);
            }

            if (true)
            {
                f.Key("grabable");
                f.Value(value.grabable);
            }

            if (true)
            {
                f.Key("useGravity");
                f.Value(value.useGravity);
            }

            if (true)
            {
                f.Key("isTrigger");
                f.Value(value.isTrigger);
            }

            if (value.physicMaterial != null)
            {
                f.Key("physicMaterial");
                Serialize_vci_colliders__physicMaterial(f, value.physicMaterial);
            }

            f.EndMap();
        }
Exemple #4
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);
            }
            }
        }