Пример #1
0
        public static ColliderPrefab CreateColliderPrefab(ColliderData data)
        {
            CBaseShape collider = null;

            if (LMath.Abs(data.deg - 45) < 1)
            {
            }

            //warning data.deg is unity deg
            //changed unity deg to ccw deg
            var collisionDeg = -data.deg + 90;

            if (data.radius > 0)
            {
                //circle
                collider = new CCircle(data.radius);
            }
            else
            {
                //obb
                collider = new COBB(data.size, collisionDeg);
            }

            collider.high = data.high;
            var colFab = new ColliderPrefab();

            colFab.parts.Add(new ColliderPart()
            {
                transform = new CTransform2D(data.pos, data.y, data.deg),
                collider  = collider
            });
            return(colFab);
        }
        public static ColliderPrefab CreateColliderPrefab(GameObject fab, ColliderData data)
        {
            Debug.Trace("CreateColliderPrefab " + fab.name);
            CBaseShape collider = null;

            if (data == null)
            {
                Debug.LogError(fab.name + " Miss ColliderDataMono ");
                return(null);
            }

            if (data.radius > 0)
            {
                //circle
                collider = new CCircle(data.radius);
            }
            else
            {
                //obb
                collider = new COBB(data.size, data.deg);
            }
            Debug.Trace($"{fab.name} !!!CreateCollider  deg: {data.deg} up:{data.size} radius:{data.radius}");
            var colFab = new ColliderPrefab();

            colFab.parts.Add(new ColliderPart()
            {
                transform = new CTransform2D(LVector2.zero),
                collider  = collider
            });
            return(colFab);
        }
Пример #3
0
        public static ColliderPrefab CreateColliderPrefab(GameObject fab)
        {
            Collider unityCollider = null;
            var      colliders     = fab.GetComponents <Collider>();

            foreach (var col in colliders)
            {
                if (col.isTrigger)
                {
                    unityCollider = col;
                    break;
                }
            }

            if (unityCollider == null)
            {
                foreach (var col in colliders)
                {
                    unityCollider = col;
                    break;
                }
            }

            if (unityCollider == null)
            {
                return(null);
            }
            CBaseShape collider = null;

            if (unityCollider is BoxCollider boxCol)
            {
                collider = new COBB(boxCol.size.ToLVector2XZ(), LFloat.zero);
            }

            if (unityCollider is SphereCollider cirCol)
            {
                collider = new CCircle(cirCol.radius.ToLFloat());
            }

            if (unityCollider is CapsuleCollider capCol)
            {
                collider = new CCircle(capCol.radius.ToLFloat());
            }

            var colFab = new ColliderPrefab();

            colFab.parts.Add(new ColliderPart()
            {
                transform = new CTransform2D(LVector2.zero),
                collider  = collider
            });
            return(colFab);
        }
Пример #4
0
        private static bool CheckCollision(CBaseShape col1, Transform2D trans1, CBaseShape col2,
                                           Transform2D trans2)
        {
            if (col1.TypeId > col2.TypeId)
            {
                return(CheckCollision(col2, trans2, col1, trans1));
            }
            var id = col1.TypeId << 4 | col2.TypeId;

            if (id > _dealFuncs.Length)
            {
                return(false);
            }
            var enumType = (ECollisionPair)id;
            var func     = _dealFuncs[id];

            if (func != null)
            {
                return(func(col1, trans1, col2, trans2));
            }
            return(false);
        }
Пример #5
0
        public static ColliderPrefab CreateColliderPrefab(GameObject fab)
        {
            Debug.Trace("CreateColliderPrefab " + fab.name);
#if false
            Collider unityCollider = null;
            var      colliders     = fab.GetComponents <Collider>();
            foreach (var col in colliders)
            {
                if (col.isTrigger)
                {
                    unityCollider = col;
                    break;
                }
            }

            if (unityCollider == null)
            {
                foreach (var col in colliders)
                {
                    unityCollider = col;
                    break;
                }
            }

            if (unityCollider == null)
            {
                return(null);
            }
            CBaseShape collider = null;
            if (unityCollider is BoxCollider boxCol)
            {
                collider = new COBB(boxCol.size.ToLVector2XZ(), LFloat.zero);
            }

            if (unityCollider is SphereCollider cirCol)
            {
                collider = new CCircle(cirCol.radius.ToLFloat());
            }

            if (unityCollider is CapsuleCollider capCol)
            {
                collider = new CCircle(capCol.radius.ToLFloat());
            }

            if (collider is COBB tObb)
            {
                Debug.LogTrace($"{fab.name} CreateCollider OBB deg: {tObb.deg} up:{tObb.up} radius:{tObb.radius}");
            }
            if (collider is CCircle tCircle)
            {
                Debug.LogTrace($"{fab.name} CreateCollider Circle deg: radius:{tCircle.radius}");
            }
#else
            CBaseShape collider = null;
            var        data     = fab.GetComponent <ColliderDataMono>()?.colliderData;
            if (data == null)
            {
                Debug.LogError(fab.name + " Miss ColliderDataMono ");
                return(null);
            }

            if (data.radius > 0)
            {
                //circle
                collider = new CCircle(data.radius);
            }
            else
            {
                //obb
                collider = new COBB(data.size, data.deg);
            }
            Debug.Trace($"{fab.name} !!!CreateCollider  deg: {data.deg} up:{data.size} radius:{data.radius}");
#endif
            var colFab = new ColliderPrefab();
            colFab.parts.Add(new ColliderPart()
            {
                transform = new CTransform2D(LVector2.zero),
                collider  = collider
            });
            return(colFab);
        }