Ejemplo n.º 1
0
    // 境界判定
    private bool isOverborder()
    {
        Vector3 movedVector = transform.position - startPosition;

        // XZ用判定
        CheckLength checkLengthXZ = () =>
        {
            float length = Mathf.Sqrt(movedVector.x * movedVector.x + movedVector.z * movedVector.z);

            if (length > OverborderLength)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        };

        // YZ用判定
        CheckLength checkLengthYZ = () =>
        {
            float length = Mathf.Sqrt(movedVector.y * movedVector.y + movedVector.z * movedVector.z);

            if (length > OverborderLength)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        };

        // 判定
        if (isXZmove)
        {
            if (checkLengthXZ())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            if (checkLengthYZ())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Ejemplo n.º 2
0
    public void onClickAdd(int value)
    {
        var thisAdd = new CheckLength();

        for (int k = 0; k < Slots.transform.childCount; k++)
        {
            if (Slots.transform.GetChild(k).gameObject.tag == "if")
            {
                numOfthisSlot = k;
            }
        }
        Debug.Log(numOfthisSlot);

        if (newSlotsListUp.Count < 14 - (numOfthisSlot + 1))
        {
            if (value == 5) //верхние слоты условия
            {
                thisAdd.current = isLengthUp();
                SlotParrentUp.SetActive(true);
                if (newSlotsListUp.Count == 0)       //если пока ничего нет
                {
                    if (newSlotsListDown.Count == 0) //если нижний тоже нет
                    {
                        //тогда берем позиции следующего слота, но выше по игрику

                        newSlot = Instantiate(example, new Vector3(Slots.transform.GetChild(numOfthisSlot + 1).transform.position.x,
                                                                   Slots.transform.GetChild(numOfthisSlot + 1).transform.position.y + 0.7f,
                                                                   Slots.transform.GetChild(numOfthisSlot + 1).transform.position.z),
                                              Quaternion.identity, SlotParrentUp.transform);

                        newSlot.SetActive(true);
                        newSlotsListUp.Add(newSlot);
                    }
                    else
                    { //если есть нижний, то берем его позицию, но выше по игрику
                        newSlot = Instantiate(example, new Vector3(newSlotsListDown[0].transform.position.x,
                                                                   newSlotsListDown[0].transform.position.y + 1.35f,
                                                                   newSlotsListDown[0].transform.position.z),
                                              Quaternion.identity, SlotParrentUp.transform);

                        newSlot.SetActive(true);
                        newSlotsListUp.Add(newSlot);
                    }
                }
                else //если же это не первый
                {
                    //Debug.Log(newSlot.transform.position.x);
                    //Debug.Log(Mathf.Round(newSlot.transform.position.x));

                    if (Mathf.Round(newSlotsListUp[newSlotsListUp.Count - 1].transform.position.x) == Mathf.Round(10.4143f))
                    {
                        //проверяем не на грани ли он экрана (позиции последнего слота)
                        //даем новую позицию внизу
                        newSlot = Instantiate(example, new Vector3(1.7f, -3f, 0f),
                                              Quaternion.identity, SlotParrentUp.transform);

                        newSlot.SetActive(true);
                        newSlotsListUp.Add(newSlot);
                    }
                    else
                    {   //копируем позицию последнего, и двигаем по иксу
                        newSlot = Instantiate(example, new Vector3(newSlotsListUp[newSlotsListUp.Count - 1].transform.position.x + 1.45f,
                                                                   newSlotsListUp[newSlotsListUp.Count - 1].transform.position.y,
                                                                   newSlotsListUp[newSlotsListUp.Count - 1].transform.position.z),
                                              Quaternion.identity, SlotParrentUp.transform);

                        newSlot.SetActive(true);
                        newSlotsListUp.Add(newSlot);
                    }
                }

                //красим его в тот цвет, в который покрашен родительский
                newSlot.GetComponent <Image>().color = new Color(Slots.transform.GetChild(numOfthisSlot).transform.GetComponent <Image>().color.r, 213,
                                                                 Slots.transform.GetChild(numOfthisSlot).transform.GetComponent <Image>().color.b,
                                                                 255);


                thisAdd.current = isLengthUp();

                if (thisAdd.current > thisAdd.old) //проверяем слоты, если новый условный слот, то смещаем главные слоты
                {
                    for (int k = numOfthisSlot; k < Slots.transform.childCount; k++)
                    {
                        Slots.transform.GetChild(k + 1).position = Slots.transform.GetChild(k + 2).position;
                        if (k == 11)
                        {
                            Slots.transform.GetChild(12).position = Slots.transform.GetChild(13).position;
                            break;
                        }
                    }

                    if (z > 1)
                    {
                        Slots.transform.GetChild(z - 1).gameObject.SetActive(false);
                        z--;
                    }
                }
            }
        }

        if (newSlotsListDown.Count < 14 - (numOfthisSlot + 1))
        {
            if (value == 6) //для нижних действий
            {
                thisAdd.current = isLength();
                SlotParrentDown.SetActive(true);
                if (newSlotsListDown.Count == 0)
                {
                    if (newSlotsListUp.Count == 0) //когда нет верхнего
                    {
                        newSlot = Instantiate(example, new Vector3(Slots.transform.GetChild(numOfthisSlot + 1).transform.position.x,
                                                                   Slots.transform.GetChild(numOfthisSlot + 1).transform.position.y - 0.7f,
                                                                   Slots.transform.GetChild(numOfthisSlot + 1).transform.position.z),
                                              Quaternion.identity, SlotParrentDown.transform);

                        newSlot.SetActive(true);
                        newSlotsListDown.Add(newSlot);
                    }
                    else//есть верхний
                    {
                        newSlot = Instantiate(example, new Vector3(newSlotsListUp[0].transform.position.x,
                                                                   newSlotsListUp[0].transform.position.y - 1.35f,
                                                                   newSlotsListUp[0].transform.position.z),
                                              Quaternion.identity, SlotParrentDown.transform);

                        newSlot.SetActive(true);
                        newSlotsListDown.Add(newSlot);
                    }
                }
                else //есть существующие нижние
                {
                    if (Mathf.Round(newSlotsListUp[newSlotsListUp.Count - 1].transform.position.x) == Mathf.Round(10.4143f))
                    {
                        //если на грани
                        newSlot = Instantiate(example, new Vector3(1.7f, -4.4f, 0f),
                                              Quaternion.identity, SlotParrentDown.transform);

                        newSlot.SetActive(true);
                        newSlotsListDown.Add(newSlot);
                    }
                    else //если не на грани, копируем последнюю позицию
                    {
                        newSlot = Instantiate(example, new Vector3(newSlotsListDown[newSlotsListDown.Count - 1].transform.position.x + 1.45f,
                                                                   newSlotsListDown[newSlotsListDown.Count - 1].transform.position.y,
                                                                   newSlotsListDown[newSlotsListDown.Count - 1].transform.position.z),
                                              Quaternion.identity, SlotParrentDown.transform);

                        newSlot.SetActive(true);
                        newSlotsListDown.Add(newSlot);
                    }

                    thisAdd.current = isLength();

                    if (thisAdd.current > thisAdd.old) //проверяем слоты, если новый условный слот, то смещаем главные слоты
                    {
                        for (int k = numOfthisSlot; k < Slots.transform.childCount; k++)
                        {
                            Slots.transform.GetChild(k + 1).position = Slots.transform.GetChild(k + 2).position;
                            if (k == 11)
                            {
                                Slots.transform.GetChild(12).position = Slots.transform.GetChild(13).position;
                                break;
                            }
                        }

                        if (z > 1)
                        {
                            Slots.transform.GetChild(z - 1).gameObject.SetActive(false);
                            z--;
                        }
                    }
                }
                newSlot.GetComponent <Image>().color = new Color(Slots.transform.GetChild(numOfthisSlot).transform.GetComponent <Image>().color.r, 213,
                                                                 Slots.transform.GetChild(numOfthisSlot).transform.GetComponent <Image>().color.b,
                                                                 255);
            }
        }
    }
Ejemplo n.º 3
0
        public static void Main()
        {
            var separator = new string('-', 30);

            string[] names = { "Alice", "Bob", "Siggi", "Magdalena", "Oliver", "Lisi", "Todd", "Al", "Petra", "Alex" };


            #region Example 4 - Anonymous Methods

            Func <int, int, bool> checkIntegers = (i, j) => i < 8 + j;
            Action printSomething = () => Console.WriteLine("Printing");
            printSomething();
            Action <int, int> sumOfTwoNumbers = (i, j) =>
            {
                Console.WriteLine("First number: " + i);
                Console.WriteLine("Second number: " + j);
                Console.WriteLine("The sum is: " + (j + i));
            };
            sumOfTwoNumbers(7, 4);

            List <int> nums = new List <int>()
            {
                1, 2, 3
            };

            Func <string[], Func <string, bool>, List <string> > extractStrings2 = (array, func) =>
            {
                List <string> result = new();

                foreach (var item in array)
                {
                    if (func(item))
                    {
                        result.Add(item);
                    }
                }

                return(result);
            };
            Func <string, bool> lessThanFive2 = x => x.Length < 5;

            List <string> namesLessThanFive2 = extractStrings2(names, lessThanFive2);
            namesLessThanFive2.ForEach(Console.WriteLine);

            #endregion



            #region Example 3 - Func and Action

            Func <string, bool> lessThanFive   = LessThanFive;
            Func <string, bool> greaterThanSix = x => x.Length > 6;
            Action <string>     printer        = PrintTwice;
            printer += Print;

            List <string> namesLessThanFive = ExtractStrings(names, greaterThanSix);
            namesLessThanFive.ForEach(Console.WriteLine);
            printer("message test!");

            #endregion



            #region Example 2 - Delegate Chain

            Console.WriteLine("\n" + separator + " Example 2 " + separator);

            //assigning Print-method to Printer-delegate and save it in p-delegate value - PUBLISHER
            Printer p = Print;

            // chaining delegates - SUBSCRIBERS
            p += PrintTwice;
            p += Print;
            p += Print;
            p -= Print;
            p("message");

            // show all delegates
            foreach (var del in p.GetInvocationList())
            {
                Console.WriteLine(del.Method);
            }
            Delegate[] delegates = p.GetInvocationList();

            #endregion



            #region Example 1

            Console.WriteLine("\n" + separator + " Example 1 " + separator);

            List <string> resultList  = NamesLengthFilter(names, EqualsFive);
            List <string> resultList2 = NamesLengthFilter(names, item => item.Length == 4);
            //resultList2.OrderBy(i => i.Length).ToList().ForEach(i => Console.WriteLine($"Length: {i.Length} - {i}"));

            Filters filter = LessThanFive;
            filter += GreaterThanFive;
            filter += EqualsFive;
            //Console.WriteLine(filter("TestWord"));

            List <bool> results0 = new();
            foreach (var del in filter.GetInvocationList())
            {
                var result = del.DynamicInvoke("TestWord");
                results0.Add((bool)result);
                //Console.WriteLine(result);
            }

            List <bool> results1 = filter.GetInvocationList()
                                   .Select(del => (bool)del.DynamicInvoke("TestWord"))
                                   .ToList();
            //Console.WriteLine(String.Join(", ", results1));


            var filterResults = GetAllDelegateResults <bool>(filter, "TestWord");
            filterResults.ForEach(i => Console.WriteLine(i));

            CheckLength checkLength = x => x.Length;
            checkLength += x => x.Length + 1;
            checkLength += x => x.Length + 2;
            List <int> lengthResults = GetAllDelegateResults <int>(checkLength, "TestWord");
            lengthResults.ForEach(Console.WriteLine);   // method group instead of lambda

            #endregion
        }