示例#1
0
        public bool UpdateCollider(CGColliderEnum mode, bool convex, PhysicMaterial material)
        {
            if (Collider == null)
            {
                switch (mode)
                {
                    case CGColliderEnum.Mesh:
                        if (canAddMeshCollider(Filter.sharedMesh.bounds))
                        {
                            var mc = gameObject.AddComponent<MeshCollider>();
                            mc.convex = convex;
                            mCollider = mc;
                        }
                        break;
                    case CGColliderEnum.Box:
                        gameObject.AddComponent<BoxCollider>();
                        break;
                    case CGColliderEnum.Sphere:
                        gameObject.AddComponent<SphereCollider>();
                        break;
                }
            }

            if (Collider != null)
            {
                switch (mode)
                {
                    case CGColliderEnum.Mesh:
                        var mc = Collider as MeshCollider;
                        mc.sharedMesh = null;
                        if (!canAddMeshCollider(Filter.sharedMesh.bounds))
                            return false;
                        try
                        {
                            mc.sharedMesh = Filter.sharedMesh;
                        }
                        catch
                        {
                            return false;
                        }
                        break;
                    case CGColliderEnum.Box:
                        var bc = Collider as BoxCollider;
                        bc.center = Filter.sharedMesh.bounds.center;
                        bc.size = Filter.sharedMesh.bounds.size;
                        break;
                    case CGColliderEnum.Sphere:
                        var sc = Collider as SphereCollider;
                        sc.center = Filter.sharedMesh.bounds.center;
                        sc.radius = Filter.sharedMesh.bounds.extents.magnitude;
                        break;
                }
                Collider.material = material;
            }
            return true;

            
        }
示例#2
0
        public bool ColliderMatches(CGColliderEnum type)
        {
            if (Collider == null && type == CGColliderEnum.None)
                return true;
            if (Collider is MeshCollider && type == CGColliderEnum.Mesh)
                return true;
            if (Collider is BoxCollider && type == CGColliderEnum.Box)
                return true;
            if (Collider is SphereCollider && type == CGColliderEnum.Sphere)
                return true;

            return false;
        }
示例#3
0
        public bool ColliderMatches(CGColliderEnum type)
        {
            if (Collider == null && type == CGColliderEnum.None)
            {
                return(true);
            }
            if (Collider is MeshCollider && type == CGColliderEnum.Mesh)
            {
                return(true);
            }
            if (Collider is BoxCollider && type == CGColliderEnum.Box)
            {
                return(true);
            }
            if (Collider is SphereCollider && type == CGColliderEnum.Sphere)
            {
                return(true);
            }

            return(false);
        }
示例#4
0
        public bool UpdateCollider(CGColliderEnum mode, bool convex, PhysicMaterial material)
        {
            if (Collider == null)
            {
                switch (mode)
                {
                case CGColliderEnum.Mesh:
                    if (canAddMeshCollider(Filter.sharedMesh.bounds))
                    {
                        var mc = gameObject.AddComponent <MeshCollider>();
                        mc.convex = convex;
                        mCollider = mc;
                    }
                    break;

                case CGColliderEnum.Box:
                    gameObject.AddComponent <BoxCollider>();
                    break;

                case CGColliderEnum.Sphere:
                    gameObject.AddComponent <SphereCollider>();
                    break;
                }
            }

            if (Collider != null)
            {
                switch (mode)
                {
                case CGColliderEnum.Mesh:
                    var mc = Collider as MeshCollider;
                    mc.sharedMesh = null;
                    if (!canAddMeshCollider(Filter.sharedMesh.bounds))
                    {
                        return(false);
                    }
                    try
                    {
                        mc.sharedMesh = Filter.sharedMesh;
                    }
                    catch
                    {
                        return(false);
                    }
                    break;

                case CGColliderEnum.Box:
                    var bc = Collider as BoxCollider;
                    bc.center = Filter.sharedMesh.bounds.center;
                    bc.size   = Filter.sharedMesh.bounds.size;
                    break;

                case CGColliderEnum.Sphere:
                    var sc = Collider as SphereCollider;
                    sc.center = Filter.sharedMesh.bounds.center;
                    sc.radius = Filter.sharedMesh.bounds.extents.magnitude;
                    break;
                }
                Collider.material = material;
            }
            return(true);
        }