Пример #1
0
 public void ShowBornEffect(LVector2 pos)
 {
     _effectService.CreateEffect(_gameConfigService.BornPrefabAssetId, pos);
 }
Пример #2
0
 public static bool CheckCollision(ColliderPrefab col1, CTransform2D trans1, LVector2 pos, LVector2 size, LVector2 up)
 {
     tempOBB.size  = size;
     tempOBB.up    = up;
     tempTrans.pos = pos;
     foreach (var part1 in col1.parts)
     {
         if (CheckCollision(part1.collider, trans1 + part1.transform, tempOBB, tempTrans))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
 public override void UpdatePosition(LVector2 pos)
 {
     this.pos = pos;
 }
Пример #4
0
        public void CreateEnemy(LVector2 bornPos)
        {
            var type = _randomService.Range(0, _gameConfigService.enemyPrefabs.Count);

            CreateEnemy(bornPos, type);
        }
Пример #5
0
 public void Init(ColliderPrefab prefab, LVector2 pos)
 {
     Init(prefab, pos, LFloat.zero, LFloat.zero);
 }
Пример #6
0
 private void CreateItem(LVector2 createPos, int type)
 {
     UnityEngine.Debug.Log($"hehe CreateItem " + type);
     CreateUnit(createPos, _config.itemPrefabs, type, EDir.Up, transParentItem);
 }
Пример #7
0
 private void CreateItem(LVector2 createPos, int type)
 {
     CreateUnit(createPos, _gameConfigService.itemPrefabs, type, EDir.Up);
 }
Пример #8
0
 public static int GetHash(this LVector2 val, ref int idx)
 {
     return(PrimerLUT.GetPrimer(val._x) + PrimerLUT.GetPrimer(val._y) * 17);
 }
Пример #9
0
        public static LFloat TestSegmentSegment(LVector2 p0, LVector2 p1, LVector2 p2, LVector2 p3)
        {
            var diff = p2 - p0;
            var d1   = p1 - p0;
            var d2   = p3 - p2;


            var demo = Cross2D(d1, d2);           //det

            if (LMath.Abs(demo) < LFloat.EPSILON) //parallel
            {
                return(LFloat.negOne);
            }

            var t1 = Cross2D(d2, diff) / demo; // Cross2D(diff,-d2)
            var t2 = Cross2D(d1, diff) / demo; //Dot(v1,pd0) == cross(d0,d1)

            if ((t1 >= 0 && t1 <= 1) && (t2 >= 0 && t2 <= 1))
            {
                return(t1); // return p0 + (p1-p0) * t1
            }
            return(LFloat.negOne);
        }
 public static Vector2Int Floor(this LVector2 vec)
 {
     return(new Vector2Int(LMath.FloorToInt(vec.x), LMath.FloorToInt(vec.y)));
 }
Пример #11
0
 public void BindView(object entity, ushort assetId, LVector2 createPos, int deg = 0)
 {
 }
    public static bool CheckCollision(LVector2 posA, LFloat rA, LVector2 sizeA, LVector2 posB, LFloat rB, LVector2 sizeB)
    {
        var diff      = posA - posB;
        var allRadius = rA + rB;

        //circle 判定
        if (diff.sqrMagnitude > allRadius * allRadius)
        {
            return(false);
        }

        var isBoxA = sizeA != LVector2.zero;
        var isBoxB = sizeB != LVector2.zero;

        if (!isBoxA && !isBoxB)
        {
            return(true);
        }
        var absX = LMath.Abs(diff.x);
        var absY = LMath.Abs(diff.y);

        if (isBoxA && isBoxB)
        {
            //AABB and AABB
            var allSize = sizeA + sizeB;
            if (absX > allSize.x)
            {
                return(false);
            }
            if (absY > allSize.y)
            {
                return(false);
            }
            return(true);
        }
        else
        {
            //AABB & circle
            var size   = sizeB;
            var radius = rA;
            if (isBoxA)
            {
                size   = sizeA;
                radius = rB;
            }

            var x = LMath.Max(absX - size.x, LFloat.zero);
            var y = LMath.Max(absY - size.y, LFloat.zero);
            return(x * x + y * y < radius * radius);
        }
    }
Пример #13
0
 public CAABB(LVector2 size)
 {
     this.size = size;
     radius    = size.magnitude;
 }
Пример #14
0
 public void ShowDiedEffect(LVector2 pos)
 {
     _effectService.CreateEffect(_gameConfigService.DiedPrefabAssetId, pos);
 }
 public LFloat GetMaxMoveDist(EDir dir, LVector2 fHeadPos, LVector2 fTargetHeadPos)
 {
     return(GetMaxMoveDist(dir, fHeadPos, fTargetHeadPos, TANK_BORDER_SIZE));
 }
Пример #16
0
        public static bool TestCircleOBB(LVector2 posA, LFloat rA, LVector2 posB, LFloat rB, LVector2 sizeB,
                                         LVector2 up)
        {
            var diff      = posA - posB;
            var allRadius = rA + rB;

//circle 判定CollisionHelper
            if (diff.sqrMagnitude > allRadius * allRadius)
            {
                return(false);
            }

//空间转换
            var absX   = LMath.Abs(LVector2.Dot(diff, new LVector2(up.y, -up.x)));
            var absY   = LMath.Abs(LVector2.Dot(diff, up));
            var size   = sizeB;
            var radius = rA;
            var x      = LMath.Max(absX - size.x, LFloat.zero);
            var y      = LMath.Max(absY - size.y, LFloat.zero);

            return(x * x + y * y < radius * radius);
        }
Пример #17
0
 public static LVector2 Vector2Field(string label, LVector2 value, params GUILayoutOption[] options)
 {
     return(EditorGUILayout.Vector2Field(label, value.ToVector2(), options).ToLVector2());
 }
Пример #18
0
        public static bool TestOBBOBB(LVector2 posA, LFloat rA, LVector2 sizeA, LVector2 upA, LVector2 posB,
                                      LFloat rB,
                                      LVector2 sizeB,
                                      LVector2 upB)
        {
            var diff      = posA - posB;
            var allRadius = rA + rB;

//circle 判定
            if (diff.sqrMagnitude > allRadius * allRadius)
            {
                return(false);
            }

            var rightA = new LVector2(upA.y, -upA.x);
            var rightB = new LVector2(upB.y, -upB.x);

            {
//轴投影到 A.right
                var BuProjAr   = LMath.Abs(LVector2.Dot(upB, rightA));
                var BrProjAr   = LMath.Abs(LVector2.Dot(rightB, rightA));
                var DiffProjAr = LMath.Abs(LVector2.Dot(diff, rightA));
                var distX      = BuProjAr * sizeB.y + BrProjAr * sizeB.x;
                if (DiffProjAr > distX + sizeA.x)
                {
                    return(false);
                }

//轴投影到 A.up
                var BuProjAu   = LMath.Abs(LVector2.Dot(upB, upA));
                var BrProjAu   = LMath.Abs(LVector2.Dot(rightB, upA));
                var DiffProjAu = LMath.Abs(LVector2.Dot(diff, upA));
                var distY      = BuProjAu * sizeB.y + BrProjAu * sizeB.x;
                if (DiffProjAu > distY + sizeA.y)
                {
                    return(false);
                }
            }
            {
//轴投影到 B.right
                var AuProjBr   = LMath.Abs(LVector2.Dot(upA, rightB));
                var ArProjBr   = LMath.Abs(LVector2.Dot(rightA, rightB));
                var DiffProjBr = LMath.Abs(LVector2.Dot(diff, rightB));
                var distX      = AuProjBr * sizeA.y + ArProjBr * sizeA.x;
                if (DiffProjBr > distX + sizeB.x)
                {
                    return(false);
                }

//轴投影到 B.right
                var AuProjBu   = LMath.Abs(LVector2.Dot(upA, upB));
                var ArProjBu   = LMath.Abs(LVector2.Dot(rightA, upB));
                var DiffProjBu = LMath.Abs(LVector2.Dot(diff, upB));
                var distY      = AuProjBu * sizeA.y + ArProjBu * sizeA.x;
                if (DiffProjBu > distY + sizeB.x)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #19
0
 public void CreateCamp(LVector2 createPos, int type = 0)
 {
     CreateUnit(createPos + GameConfig.TankBornOffset, _config.CampPrefabs, 0, EDir.Up, transParentItem);
 }
Пример #20
0
        public static bool TestCircleAABB(LVector2 posA, LFloat rA, LVector2 posB, LFloat rB, LVector2 sizeB)
        {
            var diff      = posA - posB;
            var allRadius = rA + rB;

//circle 判定
            if (diff.sqrMagnitude > allRadius * allRadius)
            {
                return(false);
            }

            var absX = LMath.Abs(diff.x);
            var absY = LMath.Abs(diff.y);

//AABB & circle
            var size   = sizeB;
            var radius = rA;
            var x      = LMath.Max(absX - size.x, LFloat.zero);
            var y      = LMath.Max(absY - size.y, LFloat.zero);

            return(x * x + y * y < radius * radius);
        }
Пример #21
0
 public void CreateCamp(LVector2 createPos, int type = 0)
 {
     CreateUnit(createPos + _gameConfigService.TankBornOffset,
                _gameConfigService.CampPrefabs, 0, EDir.Up);
 }
Пример #22
0
        /// <summary>
        /// 判定两线段是否相交 并求交点
        /// https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/565282#
        /// </summary>
        public static bool IntersectSegment(ref LVector2 seg1Src, ref LVector2 seg1Vec, ref LVector2 seg2Src,
                                            ref LVector2 seg2Vec, out LVector2 interPoint)
        {
            interPoint = LVector2.zero;
            long denom = (long)seg1Vec._x * seg2Vec._y - (long)seg2Vec._x * seg1Vec._y;   //sacle 1000

            if (denom == 0L)
            {
                return(false); // Collinear
            }
            bool denomPositive = denom > 0L;
            var  s02_x         = seg1Src._x - seg2Src._x;
            var  s02_y         = seg1Src._y - seg2Src._y;
            long s_numer       = (long)seg1Vec._x * s02_y - (long)seg1Vec._y * s02_x; //scale 1000

            if ((s_numer < 0L) == denomPositive)
            {
                return(false);                                      // No collision
            }
            long t_numer = seg2Vec._x * s02_y - seg2Vec._y * s02_x; //scale 1000

            if ((t_numer < 0L) == denomPositive)
            {
                return(false); // No collision
            }
            if (((s_numer > denom) == denomPositive) || ((t_numer > denom) == denomPositive))
            {
                return(false); // No collision
            }
// Collision detected
            var t = t_numer * 1000 / denom; //sacle 1000

            interPoint._x = (int)(seg1Src._x + ((long)((t * seg1Vec._x)) / 1000));
            interPoint._y = (int)(seg1Src._y + ((long)((t * seg1Vec._y)) / 1000));
            return(true);
        }
Пример #23
0
 public static LRect CreateRect(LVector2 center, LVector2 halfSize)
 {
     return(new LRect(center - halfSize, halfSize * 2));
 }
Пример #24
0
        //http://www.kevlindev.com/geometry/2D/intersections/index.htm
        //http://www.kevlindev.com/geometry/2D/intersections/index.htm
        //https://bitlush.com/blog/circle-vs-polygon-collision-detection-in-c-sharp
        public static bool TestCirclePolygon(LVector2 c, LFloat r, LVector2 *_points, int vertexCount)
        {
            var radiusSquared   = r * r;
            var circleCenter    = c;
            var nearestDistance = LFloat.MaxValue;
            int nearestVertex   = -1;

            for (var i = 0; i < vertexCount; i++)
            {
                LVector2 axis     = circleCenter - _points[i];
                var      distance = axis.sqrMagnitude - radiusSquared;
                if (distance <= 0)
                {
                    return(true);
                }

                if (distance < nearestDistance)
                {
                    nearestVertex   = i;
                    nearestDistance = distance;
                }
            }

            LVector2 GetPoint(int index)
            {
                if (index < 0)
                {
                    index += vertexCount;
                }
                else if (index >= vertexCount)
                {
                    index -= vertexCount;
                }

                return(_points[index]);
            }

            var vertex = GetPoint(nearestVertex - 1);

            for (var i = 0; i < 2; i++)
            {
                var nextVertex        = GetPoint(nearestVertex + i);
                var edge              = nextVertex - vertex;
                var edgeLengthSquared = edge.sqrMagnitude;
                if (edgeLengthSquared != 0)
                {
                    LVector2 axis = circleCenter - vertex;
                    var      dot  = LVector2.Dot(edge, axis);
                    if (dot >= 0 && dot <= edgeLengthSquared)
                    {
                        LVector2 projection = vertex + (dot / edgeLengthSquared) * edge;
                        axis = projection - circleCenter;
                        if (axis.sqrMagnitude <= radiusSquared)
                        {
                            return(true);
                        }
                        else
                        {
                            if (edge.x > 0)
                            {
                                if (axis.y > 0)
                                {
                                    return(false);
                                }
                            }
                            else if (edge.x < 0)
                            {
                                if (axis.y < 0)
                                {
                                    return(false);
                                }
                            }
                            else if (edge.y > 0)
                            {
                                if (axis.x < 0)
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                if (axis.x > 0)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }

                vertex = nextVertex;
            }

            return(true);
        }
Пример #25
0
 public void Init(ColliderPrefab prefab, LVector2 pos, LFloat y, LFloat deg)
 {
     Init(prefab, new CTransform2D(pos, y, deg));
 }
 public List <Vector3Int> DebugQueryCollider(EDir dir, LVector2 fTargetHead)
 {
     return(DebugQueryCollider(dir, fTargetHead, TANK_BORDER_SIZE));
 }
Пример #27
0
 public List <long> GetBodies(LVector2 point, LFloat radius)
 {
     _tempPtrList.Clear();
     _GetBodies(point, radius, _tempPtrList);
     return(_tempPtrList);
 }
 public bool HasColliderWithBorder(EDir dir, LVector2 fTargetHead)
 {
     return(HasColliderWithBorder(dir, fTargetHead, TANK_BORDER_SIZE));
 }
Пример #29
0
 public Circle(LVector2 pos, LFloat radius)
 {
     this.pos    = pos;
     this.radius = radius;
 }
Пример #30
0
 public static void Write(this Serializer serializer, LVector2 val)
 {
     serializer.Write(val._x);
     serializer.Write(val._y);
 }