示例#1
0
 private static int[] RowsToCheckForSweep(Tetramino tetramino)
 {
     Vector2Int[] absPoses = tetramino.AbsPoses;
     int[]        rowsToCheckForSweepNotUnique = LoopUtil.LoopFunc <int>((i) => absPoses[i].y, 4);
     int[]        rowsToCheckForSweepUnique    = rowsToCheckForSweepNotUnique.Distinct().OrderBy(i => i).ToArray();
     return(rowsToCheckForSweepUnique);
 }
示例#2
0
        public void CompareSpiralLoopToGenerateLoopCoords_BreakCondition()
        {
            var radius = 50;

            var expected = new List <Vector2>();

            LoopUtil.SpiralLoop(radius, radius, (x, y) => {
                if (x == 4)
                {
                    return(false);
                }

                expected.Add(new Vector2(x, y));
                return(true);
            });

            var actual = new List <Vector2>();

            foreach (var item in LoopUtil.GenerateSpiralGridCoordsClockwise().Take(radius * radius))
            {
                if (item.x == 4)
                {
                    break;
                }

                actual.Add(item);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
示例#3
0
        public void OnPointerMoved(PointerState po)
        {
            _pobak = po.Clone();
            if (isMenu)
            {
                return;
            }

            foreach (var link in LoopUtil <PartsJitProcessLink>
                     .From(
                         Parts.GetParts <PartsJitProcessLink>(LAYER.JitProcessConnector)
                         .OrderBy(a => (int)(a.SelectingScore(Pane.Target, po.Position) * 1000))
                         , out var loop))
            {
                loop.DoFirstTime(() =>
                {
                    if (link.SelectingScore(Pane.Target, po.Position) <= 1.0f)
                    {
                        link.State = PartsJitProcessLink.States.HOVER;
                    }
                    else
                    {
                        link.State = PartsJitProcessLink.States.LINE;
                    }
                });
                loop.DoSecondTimesAndSubsequent(() =>
                {
                    link.State = PartsJitProcessLink.States.LINE;
                });
            }
        }
 private void UndoInit()
 {
     Transform[] children = TransformUtil.GetChildren(transform);
     transform.DetachChildren();
     LoopUtil.LoopAction((i) => Destroy(children[i].gameObject), children.Length);
     inited = false;
 }
示例#5
0
        public void OnPointerMoved(PointerState po)
        {
            if (isTrigger(po))
            {
                var pts =
                    from sp in Parts.GetParts <ISelectableParts>(TargetLayer)
                    let score = sp.SelectingScore(Pane.Target, po.Position)
                                where score >= 0.0f
                                orderby score
                                select sp;

                foreach (var sp in LoopUtil <ISelectableParts> .From(pts, out var lu))
                {
                    lu.DoFirstTime(() =>
                    {
                        var score     = sp.SelectingScore(Pane.Target, po.Position);
                        sp.IsSelected = score <= 1.0f;
                    });
                    lu.DoSecondTimesAndSubsequent(() =>
                    {
                        sp.IsSelected = false;
                    });
                }
                Redraw();
            }
        }
示例#6
0
        public void PartsMoved(EventTokenPartsMovedTrigger token)
        {
            PartsJitProcess confrom = null;

            // Fix pcon's location by Angle when updated PartsJitProcessConnector location
            foreach (var pcon in LoopUtil <PartsConnectGrip> .From(
                         token.PartsSet
                         .Where(a => a is PartsConnectGrip)
                         .Select(a => (PartsConnectGrip)a), out var loop))
            {
                pcon.SetLocation(pcon.Angle = pcon.GetAngle()); // Update Angle and Location
                loop.DoFirstTime(() =>
                {
                    confrom = pcon.TargetProcess;
                });
            }

            // Fix pcon's location by Angle when updated PartsJitProcess position
            if (token.PartsSet.Where(a => a is PartsJitProcess).FirstOrDefault() != default)
            {
                foreach (var pcon in Parts.GetParts <PartsConnectGrip>(LAYER.JitProcessConnectorGrip))
                {
                    pcon.SetLocation(pcon.Angle);
                }
            }
            var conto = Parts.GetParts <PartsJitProcess>(LAYER.JitProcess, a => a.IsConnecting).FirstOrDefault();

            if (confrom != null && conto != null)
            {
                Connect(token, confrom, conto);
            }
        }
 static void Main(string[] args)
 {
     LoopUtil.SpiralLoop(0, 0, 3, 3, delegate(int x, int y) {
         Console.WriteLine($"x={x} y={y}");
         return(true);
     });
     Console.ReadLine();
 }
    private void SetColor(Tetramino.TetraminoType type)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers =
            GetComponentUtil.GetComponentsInChildren <SpriteRenderer>(transform, out childCount);
        LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount);
    }
 public static T[] GetComponentsInChildren <T>(Transform transform, out int childCount)
 {
     Transform[] children = TransformUtil.GetChildren(transform);
     childCount = children.Length;
     T[] components =
         LoopUtil.LoopFunc <T>((i) => children[i].GetComponent <T>(), childCount);
     return(components);
 }
        public void GenerateSpiralGridCoordsClockwise_Once_Radius17()
        {
            var radius = 17;
            var coords = LoopUtil.GenerateSpiralGridCoordsClockwise().Take(radius * radius);

            foreach (var coord in coords)
            {
            }
        }
示例#11
0
 public static void ApplyLocalPoses(Transform[] transforms, Vector2[] poses)
 {
     if (transforms.Length != poses.Length)
     {
         Debug.Log(transforms.Length + " : " + poses.Length);
         throw new System.Exception("transforms.Length != poses.Length");
     }
     LoopUtil.LoopAction((i) => transforms[i].localPosition = poses[i], transforms.Length);
 }
    private static SpriteRenderer[] GetSpriteRenderers(Transform transform, out int length)
    {
        Transform[] children   = TransformUtil.GetChildren(transform);
        int         childCount = children.Length;

        SpriteRenderer[] spriteRenderers =
            LoopUtil.LoopFunc <SpriteRenderer>((i) => children[i].GetComponent <SpriteRenderer>(), childCount);
        length = childCount;
        return(spriteRenderers);
    }
    public void SetOpacity(float opacity)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers =
            GetComponentUtil.GetComponentsInChildren <SpriteRenderer>(transform, out childCount);
        LoopUtil.LoopAction((i) =>
                            spriteRenderers[i].color =
                                ColorUtil.ColorWithOpacity(spriteRenderers[i].color, opacity), childCount);
    }
示例#14
0
        public void Test102()
        {
            string lastitem = "agro;jhn";

            foreach (var item in LoopUtil <string> .From(test102enum(), out var cu))
            {
                lastitem = item;
                Assert.AreEqual($"I-{cu.CurrentIndex}", item);
            }
            Assert.AreEqual("I-4", lastitem);
        }
示例#15
0
    private void _UpdateBlocks()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y].SetActive(blocks[x, y] != null);
        }
                            , xCount, yCount);
    }
示例#16
0
        public void GenerateSpiralGridCoordsClockwise_10Times_Radius17()
        {
            for (int i = 0; i < 10; i++)
            {
                var posX = 3621;
                var posY = 2342;
                var BUILDINGGRID_CELL_SIZE  = 64;
                var BUILDINGGRID_RESOLUTION = 270;

                var centerI = (int)((posX / BUILDINGGRID_CELL_SIZE) +
                                    (BUILDINGGRID_RESOLUTION / 2f));
                var centerJ = (int)((posY / BUILDINGGRID_CELL_SIZE) +
                                    (BUILDINGGRID_RESOLUTION / 2f));

                int radius = 17;

                ushort     ignoreParked   = 1;
                Vector3    refPos         = Vector3.back;
                float      width          = 5f;
                float      length         = 5f;
                bool       randomize      = true;
                ushort     foundSegmentId = 0;
                Vector3    myParkPos      = Vector3.back;
                Quaternion myParkRot      = Quaternion.identity;
                float      myParkOffset   = 10f;

                bool LoopHandler(int x, int y)
                {
                    if (randomize)
                    {
                        width = ignoreParked
                                + refPos.x
                                + length
                                + length
                                + foundSegmentId
                                + myParkPos.x
                                + myParkPos.x
                                + myParkRot.x
                                + myParkOffset;
                    }

                    return(true);
                }

                foreach (var position in LoopUtil.GenerateSpiralGridCoordsClockwise().Take(radius * radius))
                {
                    var positionWithOffset = position + new Vector2(centerI, centerJ);
                    if (LoopHandler((int)positionWithOffset.x, (int)positionWithOffset.y))
                    {
                        break;
                    }
                }
            }
        }
        public void GenerateSpiralGridCoordsClockwise_10Times_Radius17()
        {
            var radius = 17;

            for (int i = 0; i < 10; i++)
            {
                var coords = LoopUtil.GenerateSpiralGridCoordsClockwise().Take(radius * radius);
                foreach (var coord in coords)
                {
                }
            }
        }
示例#18
0
 private void Menu_Closed(object sender, object e)
 {
     foreach (var link in LoopUtil <PartsJitProcessLink> .From(Parts.GetParts <PartsJitProcessLink>(LAYER.JitProcessConnector), out var loop))
     {
         link.State = PartsJitProcessLink.States.LINE;
         loop.DoLastOneTime(() =>
         {
             Redraw();
         });
     }
     isMenu = false;
 }
示例#19
0
        public void Test101()
        {
            var data = new List <int>
            {
                0, 10, 20, 30, 40, 50, 60, 70, 80, 90,
            };

            foreach (var item in LoopUtil <int> .From(data, out var cu))
            {
                Assert.AreEqual(item / 10, cu.CurrentIndex);
            }
        }
示例#20
0
    // makes cells occupied by tetramino impassable
    public void FreezeTetraminoArea(TetraminoMono tetraminoMono)
    {
        Tetramino tetramino = tetraminoMono.tetramino;

        Vector2Int[] absPoses = tetramino.AbsPoses;
        LoopUtil.LoopAction((i) =>
        {
            this[absPoses[i]] =
                new WallBlock(BlockType.Unspecified, tetraminoMono.GetChildGameObject(i));
        }
                            , absPoses.Length);
        DisplayBlocks.UpdateBlocks();
    }
示例#21
0
    void Start()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        blockGameObjects = new GameObject[xCount, yCount];
        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y] = Instantiate
                                         (prefab, new Vector2(x, y), Quaternion.identity, transform);
        }
                            , xCount, yCount);
        _UpdateBlocks();
    }
示例#22
0
    public void Rotate(int rotationCount)
    {
        float sign = Mathf.Sign(rotationCount);
        int   abs  = Mathf.Abs(rotationCount);

        rotationCount = abs % 4;
        if (sign > 0)
        {
            LoopUtil.LoopAction((i) => RotateClockwise(), rotationCount);
        }
        else if (sign < 0)
        {
            LoopUtil.LoopAction((i) => RotateAntiClockwise(), rotationCount);
        }
    }
    private void SetColor(Tetramino.TetraminoType type)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers = GetSpriteRenderers(transform, out childCount);
        #region old version
        //for (int i = 0; i < 4; i++)
        //{
        //    Transform child = transform.GetChild(i);
        //    SpriteRenderer spriteRenderer = child.GetComponent<SpriteRenderer>();
        //    spriteRenderer.color = TetraminoUtil.Color(type);
        //}
        #endregion
        LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount);
    }
    // Start is called before the first frame update
    void Start()
    {
        PrintChildrenCount();
        var children = TransformUtil.GetChildren(transform);

        LoopUtil.LoopAction(
            (i) =>
        {
            children[i].parent = null;
            Destroy(children[i].gameObject);
        }, children.Length);
        PrintChildrenCount();
        LoopUtil.LoopAction((i) => new GameObject().transform.parent = transform, 1);
        PrintChildrenCount();
    }
        public void CompareSpiralLoopToGenerateLoopCoords_Radius33()
        {
            var radius = 33;

            var expected = new List <Vector2>();

            LoopUtil.SpiralLoop(radius, radius, (x, y) => {
                expected.Add(new Vector2(x, y));
                return(true);
            });

            var actual = LoopUtil.GenerateSpiralGridCoordsClockwise(radius)
                         .ToList();

            CollectionAssert.AreEqual(expected, actual);
        }
示例#26
0
        public void SpiralLoop_10Times_Radius17()
        {
            for (int i = 0; i < 10; i++)
            {
                var posX = 3621;
                var posY = 2342;
                var BUILDINGGRID_CELL_SIZE  = 64;
                var BUILDINGGRID_RESOLUTION = 270;

                var centerI = (int)((posX / BUILDINGGRID_CELL_SIZE) +
                                    (BUILDINGGRID_RESOLUTION / 2f));
                var centerJ = (int)((posY / BUILDINGGRID_CELL_SIZE) +
                                    (BUILDINGGRID_RESOLUTION / 2f));

                int radius = 17;

                ushort     ignoreParked   = 1;
                Vector3    refPos         = Vector3.back;
                float      width          = 5f;
                float      length         = 5f;
                bool       randomize      = true;
                ushort     foundSegmentId = 0;
                Vector3    myParkPos      = Vector3.back;
                Quaternion myParkRot      = Quaternion.identity;
                float      myParkOffset   = 10f;

                bool LoopHandler(int x, int y)
                {
                    if (randomize)
                    {
                        width = ignoreParked
                                + refPos.x
                                + length
                                + length
                                + foundSegmentId
                                + myParkPos.x
                                + myParkPos.x
                                + myParkRot.x
                                + myParkOffset;
                    }

                    return(true);
                }

                LoopUtil.SpiralLoop(centerI, centerJ, radius, radius, LoopHandler);
            }
        }
示例#27
0
        public void GenerateSpiralGridCoordsClockwise_Radius1()
        {
            var radius   = 1;
            var expected = new List <Vector2>()
            {
                new Vector2()
                {
                    x = 0f, y = 0f
                }
            };

            var actual = LoopUtil.GenerateSpiralGridCoordsClockwise()
                         .Take(radius * radius)
                         .ToList();

            CollectionAssert.AreEqual(expected, actual);
        }
    public void SetOpacity(float opacity)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers = GetSpriteRenderers(transform, out childCount);
        LoopUtil.LoopAction((i) =>
                            spriteRenderers[i].color =
                                ColorUtil.ColorWithOpacity(spriteRenderers[i].color, opacity), childCount);
        #region old version
        //for(int i = 0; i < 4; i++)
        //{
        //    Transform child = transform.GetChild(i);
        //    SpriteRenderer spriteRenderer = child.GetComponent<SpriteRenderer>();
        //    spriteRenderer.color = ColorUtil.ColorWithOpacity(spriteRenderer.color, opacity);
        //}
        #endregion
    }
示例#29
0
    void Start()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        blockGameObjects = new GameObject[xCount, yCount];
        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y] = Instantiate
                                         (prefab, new Vector2(x, y), Quaternion.identity, transform);
            if (blocks[x, y] == null)
            {
                blockGameObjects[x, y].SetActive(false);
            }
        }
                            , xCount, yCount);
    }
示例#30
0
    // makes cells occupied by tetramino impassable
    public void FreezeTetraminoArea(TetraminoMono tetraminoMono)
    {
        //foreach (Vector2Int pos in )
        //{
        //    blocks[pos.x, pos.y] = new WallBlock(BlockType.Unspecified);
        //}
        Tetramino tetramino = tetraminoMono.tetramino;

        Vector2Int[] absPoses = tetramino.AbsPoses;
        LoopUtil.LoopAction((i) =>
        {
            blocks[absPoses[i].x, absPoses[i].y] =
                new WallBlock(BlockType.Unspecified, tetraminoMono.GetChildGameObject(i));
        }
                            , absPoses.Length);
        DisplayBlocks.UpdateBlocks();
    }