Esempio n. 1
0
    static void MenuGenerateGridAll()
    {
        State newState = new State(1);

        newState.scale = new Vector3(0.2f, 0.2f, 0.2f);
        int b = 1;

        for (int x = 0; x < 20; x++)
        {
            for (int y = 0; y < 15; y++)
            {
                newState.position.x = 0f + x;
                newState.position.y = 0f + y;
                Manipulate.CreateObject(newState, b);
                b++;
                if (b > 17 && b < 25)
                {
                    b = 25;
                }
                if (b > 89 && b < 144)
                {
                    b = 144;
                }
                if (b == 206)
                {
                    b = 207;
                }
                if (b > 251)
                {
                    b = 1;
                }
            }
        }
    }
Esempio n. 2
0
 void Update()
 {
     if (Input.GetButtonDown("Left") && 1 < playerPos)
     {
         Move.Invoke(--playerPos);
     }
     if (Input.GetButtonDown("Right") && playerPos < 5)
     {
         Move.Invoke(++playerPos);
     }
     if (Input.GetButtonDown("Capture"))
     {
         Manipulate.Invoke();
     }
     if (Input.GetButtonDown("Drop"))
     {
         Drop.Invoke();
         dropTimer = 0f;
     }
     dropTimer += Time.deltaTime;
     if (spawnRateMs <= dropTimer)
     {
         Drop.Invoke();
         dropTimer = 0f;
     }
 }
Esempio n. 3
0
 // See if new selected Prefab will allow the saved rotation
 private static bool IsSavedRotationValidForVisualizer()
 {
     // If there is a saved rotation
     if (Manipulate.GetCurrentRotation() != null)
     {
         // If the current saved rotation is allowed by the prefab
         //   (If allowed rotation divides evenly into current rotation)
         //       or (Both allowed and current rotations are set to 0)
         if (((int)(Manipulate.GetCurrentRotation().eulerAngles.x % Helper.GetRotationStep().x) == 0) ||
             (int)Manipulate.GetCurrentRotation().eulerAngles.x == 0 && (int)Helper.GetRotationStep().x == 0)
         {
             if (((int)(Manipulate.GetCurrentRotation().eulerAngles.y % Helper.GetRotationStep().y) == 0) ||
                 (int)Manipulate.GetCurrentRotation().eulerAngles.y == 0 && (int)Helper.GetRotationStep().y == 0)
             {
                 if (((int)(Manipulate.GetCurrentRotation().eulerAngles.z % Helper.GetRotationStep().z) == 0) ||
                     (int)Manipulate.GetCurrentRotation().eulerAngles.z == 0 && (int)Helper.GetRotationStep().z == 0)
                 {
                     // Return true, since saved rotation is allowed
                     return(true);
                 }
             }
         }
     }
     // Return false, since saved rotation is not allowed
     return(false);
 }
        public void NotShrinking()
        {
            Func <bool> runFunc =
                () =>
            {
                if (theInt == 42)
                {
                    return(true);                  // means failure
                }
                return(false);
            };

            theInt = 42;

            var shrinkStrat =
                new ShrinkingStrategy()
                .Add(Manipulate.This(this)
                     .Change(e => e.theInt, -1)
                     .Change(e => e.theInt, 0)
                     .Change(e => e.theInt, 1));

            shrinkStrat.Shrink(runFunc);

            Assert.False(shrinkStrat.Shrunk());
        }
Esempio n. 5
0
            // Create the visualizer GameObject
            public static void CreateVisualizer(GameObject selectedPrefab)
            {
                // Exit without creating, if no Prefab is selected in the palette
                if (selectedPrefab == null)
                {
                    return;
                }

                // Create a new visualizer
                visualizerGameObject = GameObject.Instantiate(selectedPrefab);
                SetLayerRecursively(visualizerGameObject.transform, Const.Placement.visualizerLayer);

                // Name it "MAST_Visualizer" incase it needs to be found later for deletion
                visualizerGameObject.name = "MAST_Visualizer";

                // If not selecting the Eraser
                if (Settings.Data.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    // If saved rotation is valid for the visualizer object, then apply the rotation to it
                    if (IsSavedRotationValidForVisualizer())
                    {
                        visualizerGameObject.transform.rotation = Manipulate.GetCurrentRotation();
                    }
                }

                // Set the visualizer and all it's children to be unselectable and not shown in the hierarchy
                visualizerGameObject.hideFlags = HideFlags.HideInHierarchy;
            }
Esempio n. 6
0
 public override void Shrink(Func <bool> runFunc)
 {
     shrunk =
         new ShrinkingStrategy()
         .Add(Manipulate.This(this)
              .Change(e => e.input, -1)
              .Change(e => e.input, 0)
              .Change(e => e.input, 1));
     shrunk.Shrink(runFunc);
 }
Esempio n. 7
0
 public void SetTarget(Transform obj, FindSelectables from)
 {
     if (obj)
     {
         targetObj = obj.gameObject.GetComponent <Manipulate>();
     }
     else
     {
         targetObj = null;
     }
     camScript = from;
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            // Invoking a normal method
            var normalMethodInvokeResult = NormalMethod(2);

            // Create an instance of the delegate
            var normalMethodDelegate = new Manipulate(NormalMethod);
            var normalResult         = normalMethodDelegate(3);

            // Pass a delegate method as a variable
            var anotherResult = RunAnotherMethod(normalMethodDelegate, 4);

            // Anonymous method is a a delegate() { } and it returns a delegate
            Manipulate anonymousMethodDelegate = delegate(int a) { return(a * 2); };
            var        anonymousResult         = anonymousMethodDelegate(3);

            // Lambda expressions are anything with => and a left/right value
            // They can return a delegate (so a method that can be invoked)
            // or an Expression of a delegate (so it can be compiled and then executed)
            Manipulate lambaDelegate = a => a * 2;
            var        lambaResult   = lambaDelegate(5);

            // Nicer way to write a lamba
            Manipulate nicerLambaDelegate = (a) => { return(a * 2); };
            var        nicerLambaResult   = nicerLambaDelegate(6);

            // Lamba can return an Expression
            Expression <Manipulate> expressionLambda = a => a * 2;

            // An Action is just a delegate with no return type and optional input
            Action       actionDelegate  = () => { lambaDelegate(2); };
            Action <int> action2Delegate = (a) => { var b = a * 2; };

            // A Func is just a delegate with a return type
            Func <int> myFunc = () => 2;

            // Replace Manipulate with a Func
            Func <int, int> funcDelegate = a => a * 2;
            var             funcResult   = funcDelegate(5);

            // Mimic the FirstOrDefault Linq expression
            var items    = new List <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });
            var itemInts = Enumerable.Range(1, 10).ToList();

            // Calling the nuilt in Linq FirstOrDefault
            var foundItem = items.FirstOrDefault(item => item == "c");

            // Calling our version
            var foundItem2 = items.GetFirstOrDefault(item => item == "c");
            var foundItem3 = itemInts.GetFirstOrDefault(item => item > 4);

            Console.ReadLine();
        }
Esempio n. 9
0
    private void Awake()
    {
        controls = new InputMaster();

        create     = GetComponent <Create>();
        manipulate = GetComponent <Manipulate>();

        color = GetComponent <SpriteRenderer>().color;

        print("START");
        //Jump
        controls.Player.Jump.performed += ctx => JumpStart();
        controls.Player.Jump.started   += ctx => JumpStart();
        controls.Player.Jump.canceled  += ctx => JumpStop();
    }
Esempio n. 10
0
 public override void Shrink(Func <bool> runFunc)
 {
     shrinkA =
         new ShrinkingStrategy()
         .Add(Manipulate.This(this)
              .Change(e => e.a, -1)
              .Change(e => e.a, 0)
              .Change(e => e.a, 1));
     shrinkB =
         new ShrinkingStrategy()
         .Add(Manipulate.This(this)
              .Change(e => e.b, -1)
              .Change(e => e.b, 0)
              .Change(e => e.b, 1));
     shrinkA.Shrink(runFunc);
     shrinkB.Shrink(runFunc);
 }
        public void SimpleShrinking()
        {
            Func <bool> runFunc = () => true; // means fail always

            theInt = 42;

            var shrinkStrat =
                new ShrinkingStrategy()
                .Add(Manipulate.This(this)
                     .Change(e => e.theInt, -1)
                     .Change(e => e.theInt, 0)
                     .Change(e => e.theInt, 1));

            shrinkStrat.Shrink(runFunc);

            Assert.True(shrinkStrat.Shrunk());
        }
Esempio n. 12
0
        // Func is a delegate with a return type
        // public delegate int MyFunc();

        static void Main(string[] args)
        {
            Manipulate lambdaDelegate = a => a * 2;
            var        result         = lambdaDelegate(5);

            MyFristAction myFirstAction = () => { var a = 2; };

            // An action is a delegate with no return type and optional input
            Action       myAction    = () => { lambdaDelegate(2); };
            Action <int> myScnAction = (a) => { var c = a * 2; };


            // A Func is a delegate with a return type
            Func <int> myFunc = () => 2;

            // Replace Manipulate with a Func
            Func <int, int> funcDelegate = a => a * 2;
            var             funcResult   = funcDelegate(5);
        }
        public void createTest()
        {
            FilterFactory target = new FilterFactory(); // TODO: Passenden Wert initialisieren

            ImageManipulatorType.Name name = ImageManipulatorType.Name.INVERT;
            Bitmap        bitmap           = new Bitmap(1, 1);
            IntPtr        Scan0            = new IntPtr(); // TODO: Passenden Wert initialisieren
            int           stride           = 0;            // TODO: Passenden Wert initialisieren
            int           height_start     = 0;            // TODO: Passenden Wert initialisieren
            int           height_end       = 0;            // TODO: Passenden Wert initialisieren
            ThreadHandler thHandler        = null;         // TODO: Passenden Wert initialisieren

            int[]      values   = null;                    // TODO: Passenden Wert initialisieren
            Manipulate expected = null;                    // TODO: Passenden Wert initialisieren
            Manipulate actual;

            actual = target.create(name, bitmap, Scan0, stride, height_start, height_end, thHandler, values);
            Assert.AreNotEqual(expected, actual);
            Assert.IsInstanceOfType(actual, typeof(Manipulate));
        }
Esempio n. 14
0
            // Moves the visualizer prefab to a position based on the current mouse position
            public static void UpdateVisualizerPosition()
            {
                // If a tool is selected
                if (Interface.placementMode != Interface.PlacementMode.None)
                {
                    // If visualizer exists
                    if (visualizerGameObject != null)
                    {
                        // Update visualizer position from pointer location on grid
                        visualizerGameObject.transform.position =
                            Helper.GetPositionOnGridClosestToMousePointer();

                        // If Eraser tool is not selected
                        if (Settings.Data.gui.toolbar.selectedDrawToolIndex != 4)
                        {
                            // Apply position offset
                            visualizerGameObject.transform.position += Helper.GetOffsetPosition();

                            // If Randomizer is selected
                            if (Settings.Data.gui.toolbar.selectedDrawToolIndex == 3)
                            {
                                // If Prefab in randomizable, apply Randomizer to transform
                                if (Helper.Randomizer.GetUseRandomizer())
                                {
                                    visualizerGameObject = Randomizer.ApplyRandomizerToTransform(
                                        visualizerGameObject, Manipulate.GetCurrentRotation());
                                }
                            }
                        }

                        // Set visualizer visibility based on if mouse over grid
                        if (pointerInSceneview)
                        {
                            visualizerGameObject.SetActive(visualizerOnGrid);
                        }
                    }
                }
            }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var b = NormalMethod(2);

            //Creates an instance of the delegate
            var normalMethodDelegate = new Manipulate(NormalMethod);

            var normalResult = normalMethodDelegate(3);


            //Pass a delegate method as a variable
            var anotherResult = RunAnotheMethod(normalMethodDelegate, 4);

            //Anonymous method is a delegate() { } and it returns a delegate
            Manipulate anonymousMethodDelegate = delegate(int a) { return(a * 2); };

            var anonymousResult = anonymousMethodDelegate(3);



            //Lambda expressions are anything with => and a left/right value
            //They can return a delegate (abling a method to be invoked)
            //or a Expression of a delegate(so it can be compiled and then executed)

            Manipulate lambdaDelegate = a => a * 2;
            var        lambdaResult   = lambdaDelegate(5);

            Manipulate anotherLambdaDelegate = (a) =>
            {
                var c = 2;
                return(c * a * 2);           //Full function.....
            };

            //Nicer way to write a lambda
            Manipulate nicerLambdaDelegate = (a) => { return(a * 2); };
        }
 public virtual void Awake()
 {
     manipulate = GetComponent <Manipulate>();
     player     = GetComponent <PlayerController>();
 }
Esempio n. 17
0
 /// <summary>
 /// Accept a method (delegate) as an input
 /// </summary>
 /// <param name="theMethod"></param>
 /// <param name="a"></param>
 /// <returns></returns>
 public static int RunAnotherMethod(Manipulate theMethod, int a)
 {
     return(theMethod(a));
 }
Esempio n. 18
0
 /// <summary>
 /// Removes reference from old selected object
 /// </summary>
 private void emptyTap()
 {
     currentlySelectedObject = null;
 }
Esempio n. 19
0
    // Update is called once per frame
    void Update()
    {
        // Track a single touch as a direction control
        if (Input.touchCount > 0)
        {
            // Input.touches - Returns list of objects representing status of all touches during last frame.
            // Each entry represents a status of a finger touching the screen.
            Touch theTouch = Input.touches[0];

            // Ray - A ray is an infinite line starting at origin and going in some direction
            Ray laser = Camera.main.ScreenPointToRay(theTouch.position);


            if (Input.touchCount == 1)
            {
                // https://docs.unity3d.com/ScriptReference/TouchPhase.html
                // Handle finger movements based on TouchPhase
                switch (theTouch.phase)
                {
                //When a touch has first been detected, record the starting position
                case TouchPhase.Began:

                    // Used to get information back from a raycast
                    RaycastHit info;
                    possibleTap = true;

                    //If Lazer hits object in World
                    if (Physics.Raycast(laser, out info))
                    {
                        // Get Manipulate Component off newly selected Object
                        newSelectedObject = info.collider.GetComponent <Manipulate>();
                        dragDistance      = info.distance;
                    }
                    // If nothing hits
                    else
                    {
                        newSelectedObject = null;
                    }

                    break;

                //Determine if the touch is a moving touch
                case TouchPhase.Moved:
                    possibleTap = false;
                    if (newSelectedObject)
                    {
                        //  Drag selected object
                        newSelectedObject.dragMoveTo(laser.GetPoint(dragDistance));
                    }
                    else
                    {
                        //Drag Camera Position (Not changing field of view)
                        Vector2 touchDeltaPosition = Input.touches[0].deltaPosition;
                        Camera.main.transform.Translate(-touchDeltaPosition.x * 0.005f,
                                                        -touchDeltaPosition.y * 0.001f, 0);
                    }

                    break;

                // Touch ended
                case TouchPhase.Ended:

                    //Is a tap
                    if (possibleTap)
                    {
                        if (newSelectedObject)
                        {
                            // Change newly selected Object color
                            newSelectedObject.Tap();
                            if (currentlySelectedObject)
                            {
                                //Change old selected object color back to normal
                                currentlySelectedObject.unTap();
                            }

                            // Set newly selected object to old selected object in prep for next frame
                            currentlySelectedObject = newSelectedObject;
                        }
                        //  Not a tap
                        else
                        {
                            emptyTap();
                        }
                    }

                    break;
                }
            }

            //Scaling and rotating
            if (Input.touchCount == 2)
            {
                float currentPinchDistance = Vector2.Distance(Input.touches[0].position, Input.touches[1].position);

                //Pinching in
                if (initialPinchDistance < 0f)
                {
                    initialPinchDistance = currentPinchDistance;
                }

                if (currentlySelectedObject)
                {
                    currentlySelectedObject.scale(currentPinchDistance / initialPinchDistance);
                }

                // Only runs if no object is currently selected
                if (currentlySelectedObject == null)
                {
                    // Zoom works
                    Camera.main.fieldOfView += (currentPinchDistance - initialPinchDistance) * 0.005f;
                }

                // Taken from class whiteboard
                // Mathf.Atan - Returns the arc-tangent of f - the angle in radians whose tangent is f.
                // https://gamedev.stackexchange.com/questions/14602/what-are-atan-and-atan2-used-for-in-games
                // atan(angle) = opposite/adjacent
                var currentTheta = Mathf.Atan2(
                    Input.touches[0].position.y - Input.touches[1].position.y,
                    Input.touches[0].position.x - Input.touches[1].position.x);

                if (currentlySelectedObject != null)
                {
                    // Object rotation
                    // Mathf.Rad2Deg - Radians-to-degrees conversion
                    currentlySelectedObject.rotate((currentTheta - pastTheta) * Mathf.Rad2Deg);
                }
                else
                {
                    // Camera rotation
                    Camera.main.transform.Rotate(Camera.main.transform.forward, currentTheta - pastTheta);
                }

                pastTheta = currentTheta;

                if (Input.touches[1].phase == TouchPhase.Ended)
                {
                    initialPinchDistance = -1;
                }
            }

            if (Input.touchCount == 4)
            {
                // https://answers.unity.com/questions/899037/applicationquit-not-working-1.html
                #if UNITY_EDITOR
                // Application.Quit() does not work in the editor so
                // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
                UnityEditor.EditorApplication.isPlaying = false;
                #else
                Application.Quit();
                #endif
            }
        }
    }
 private void btn_Add(object sender, RoutedEventArgs e)
 {
     Manipulate.Add(this);
 }
Esempio n. 21
0
        static void Main(string[] args)
        {
            List <Student> students = new List <Student>
            {
                new Student()
                {
                    Id = 1, Name = "John", Grade = 7, Credits = 5
                },
                new Student()
                {
                    Id = 2, Name = "Jelly", Grade = 9, Credits = 45
                },
                new Student()
                {
                    Id = 3, Name = "Jannie", Grade = 7, Credits = 25
                },
                new Student()
                {
                    Id = 4, Name = "Jolly", Grade = 8, Credits = 15
                }
            };



            IsPromotable delegatePromotable = new IsPromotable(Condition);

            Student.PromoteStudent(students, delegatePromotable);

            // CAN BE REDUCED INTO 1 LINE USING LAMPDA
            //Student.PromoteStudent(students, s=>s.Grade > 8);



            // Invoking a normal method
            var normalMethodInvokeResult = NormalMethod(2);

            // Create an instance of the delegate
            var normalMethodDelegate = new Manipulate(NormalMethod);
            var normalResult         = normalMethodDelegate(3);

            // Anonymous method is a a delegate() { } and it returns a delegate
            Manipulate anonymousMethodDelegate = delegate(int a) { return(a * 2); };
            var        anonymousResult         = anonymousMethodDelegate(3);

            // Lambda expressions are anything with => and a left/right value
            // They can return a delegate (so a method that can be invoked)
            // or an Expression of a delegate (so it can be compiled and then executed)
            Manipulate lambaDelegate = a => a * 2;
            var        lambaResult   = lambaDelegate(5);

            // Nicer way to write a lamba
            Manipulate nicerLambaDelegate = (a) => { return(a * 2); };
            var        nicerLambaResult   = nicerLambaDelegate(6);

            // Lamba can return an Expression
            Expression <Manipulate> expressionLambda = a => a * 2;

            // An Action is just a delegate with no return type and optional input
            Action       actionDelegate  = () => { lambaDelegate(2); };
            Action <int> action2Delegate = (a) => { var b = a * 2; };

            // A Func is just a delegate with a return type
            Func <int> myFunc = () => 2;

            // Replace Manipulate with a Func
            Func <int, int> funcDelegate = a => a * 2;
            var             funcResult   = funcDelegate(5);

            // Mimic the FirstOrDefault Linq expression
            var items    = new List <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });
            var itemInts = Enumerable.Range(1, 10).ToList();

            // Calling the nuilt in Linq FirstOrDefault
            var foundItem = items.FirstOrDefault(item => item == "c");

            // Calling our version
            var foundItem2 = items.GetFirstOrDefaultCustom(item => item == "c");
            var foundItem3 = itemInts.GetFirstOrDefaultCustom(item => item > 4);

            Console.ReadKey();
        }
 private void btn1_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show("Added value= " + Manipulate.Add(this.BoxA, this.BoxB));
 }
 private void btn1_Click(object sender, RoutedEventArgs e)
 {
     Manipulate.Add();
 }
Esempio n. 24
0
    static void MenuDuplicate()
    {
        State newState = cloneExistingState();

        Manipulate.CreateObject(newState, cloneExistingB());
    }