示例#1
0
    void Update()
    {
        if (SystemController.isOnAndroid && sys.mode == 0)
        {
            if (Input.touchCount > 0)
            {
                if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                {
                    if (Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        isRotating = true;
                    }
                    else if (Input.GetTouch(0).phase == TouchPhase.Ended)
                    {
                        isRotating       = false;
                        finalizeRotation = true;
                        Vector3 rot = level.transform.rotation.eulerAngles;
                        rot.x         = ControlFunctions.getClosest(rot.x);
                        rot.y         = ControlFunctions.getClosest(rot.y);
                        rot.z         = ControlFunctions.getClosest(rot.z);
                        startRotation = level.transform.rotation;
                        finalRotation = Quaternion.Euler(rot);
                        step          = 0.1f;
                    }
                }
            }
        }
        else
        {
            if (sys.mode == 0 && !EventSystem.current.IsPointerOverGameObject())
            {
                if (Input.GetMouseButtonDown(0))
                {
                    isRotating = true;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    isRotating       = false;
                    finalizeRotation = true;
                    Vector3 rot = level.transform.rotation.eulerAngles;
                    rot.x         = ControlFunctions.getClosest(rot.x);
                    rot.y         = ControlFunctions.getClosest(rot.y);
                    rot.z         = ControlFunctions.getClosest(rot.z);
                    startRotation = level.transform.rotation;
                    finalRotation = Quaternion.Euler(rot);
                    step          = 0.1f;
                }
            }
        }

        if (finalizeRotation)
        {
            ControlFunctions.endRotating(level.gameObject, startRotation, finalRotation, ref step, ref finalizeRotation);
            foreach (Platform p in level.platforms)
            {
                p.resetRot();
            }
        }
    }
示例#2
0
    private void FixedUpdate()
    {
        if (isRotating)
        {
            float   inputX;
            float   inputY;
            Vector2 pos;
            if (SystemController.isOnAndroid)
            {
                inputX = Input.GetTouch(0).deltaPosition.x;
                inputY = Input.GetTouch(0).deltaPosition.y;
                pos    = Input.GetTouch(0).position;
            }
            else
            {
                inputX = Input.GetAxis("Mouse X");
                inputY = Input.GetAxis("Mouse Y");
                pos    = Input.mousePosition;
            }
            Quaternion rot;
            if (dir == '0' || (isInside &&
                               ControlFunctions.isInsideRadius(
                                   main.ScreenToViewportPoint(
                                       pos), initPos, 2f)))
            {
                rot = ControlFunctions.calcRot1D(inputX, inputY, sys.rotSpeed, ref dir);
                rotatorX.transform.rotation = hP[0].transform.localRotation;
                rotatorY.transform.rotation = vP[0].transform.localRotation;
            }
            else if (dir == 'H')
            {
                rot = Quaternion.Euler(-inputX * sys.rotSpeed * Time.deltaTime * Vector3.up);
                foreach (Platform p in hP)
                {
                    p.transform.SetParent(rotatorX);
                }
                rotatorX.Rotate(rot.eulerAngles, Space.World);

                isInside = false;
            }
            else
            {
                rot = Quaternion.Euler(inputY * sys.rotSpeed * Time.deltaTime * Vector3.right);
                foreach (Platform p in vP)
                {
                    p.transform.SetParent(rotatorY);
                }
                rotatorY.Rotate(rot.eulerAngles, Space.World);

                isInside = false;
            }
            for (int i = 0; i < 9; i++)
            {
                vP[i].resetRot();
                hP[i].resetRot();
            }
        }
    }
        private void KeybindChange(MenuPageEventArgs e)
        {
            var args = e as KeybindChangeEventArgs;

            if (args == null)
            {
                return;
            }

            _requestKeybindChange = true;
            _functionToChange     = args.Function;
        }
示例#4
0
        private void ExecuteAction(ControlFunctions controlFunction, ref GameStates gameState, ref bool paused)
        {
            switch (controlFunction)
            {
            case ControlFunctions.ExitMenu:
                ExitMenuFunction(ref gameState, ref paused);
                break;

            case ControlFunctions.Pause:
                PauseMenuFunction(ref gameState, ref paused);
                break;

            case ControlFunctions.SpecialAttack:
                SpecialAttackFunction();
                break;

            case ControlFunctions.Attack:
                AttackFunction();
                break;

            case ControlFunctions.Interact:
                InteractFunction();
                break;

            case ControlFunctions.ContinueJump:
                ContinueJumpFunction();
                break;

            case ControlFunctions.Jump:
                JumpFunction();
                break;

            case ControlFunctions.Dash:
                DashFunction();
                break;

            case ControlFunctions.MoveLeft:
            case ControlFunctions.MoveRight:
            case ControlFunctions.Crouch:
                MoveFunction(controlFunction);
                break;

            case ControlFunctions.Switch:
                SwitchFunction();
                break;

            default:
                Console.WriteLine("Not sure how we got to an invalid control function.");
                break;
            }
        }
示例#5
0
        private void CreateSpiceFunctions()
        {
            var functions = new List <IFunction>
            {
                MathFunctions.CreatePos(),
                RandomFunctions.CreateAGauss(),
                RandomFunctions.CreateAUnif(),
                MathFunctions.CreateBuf(),
                MathFunctions.CreateCbrt(),
                MathFunctions.CreateCeil(),
                MathFunctions.CreateDb(Mode),
                ControlFunctions.CreateDef(),
                RandomFunctions.CreateFlat(),
                MathFunctions.CreateFloor(),
                RandomFunctions.CreateGauss(),
                RandomFunctions.CreateExtendedGauss(),
                MathFunctions.CreateHypot(),
                ControlFunctions.CreateIf(),
                MathFunctions.CreateInt(),
                MathFunctions.CreateInv(),
                MathFunctions.CreateLn(),
                MathFunctions.CreateLimit(),
                RandomFunctions.CreateLimit(),
                MathFunctions.CreateMax(),
                RandomFunctions.CreateMc(),
                MathFunctions.CreateMin(),
                MathFunctions.CreateNint(),
                MathFunctions.CreateRound(),
                MathFunctions.CreatePwr(Mode),
                MathFunctions.CreatePwrs(),
                RandomFunctions.CreateRandom(),
                MathFunctions.CreateSgn(),
                MathFunctions.CreateTable(),
                MathFunctions.CreateU(),
                RandomFunctions.CreateUnif(),
                MathFunctions.CreateURamp(),
                MathFunctions.CreatePoly(),
            };

            foreach (var function in functions)
            {
                AddFunction(function.Name, function);
            }
        }
示例#6
0
        private void MoveFunction(ControlFunctions function)
        {
            Directions dir;

            if (function == ControlFunctions.MoveLeft)
            {
                dir = Directions.Left;
            }
            else if (function == ControlFunctions.MoveRight)
            {
                dir = Directions.Right;
            }
            else
            {
                dir = Directions.Down;
            }

            _player.ExecuteMove(dir);
        }
示例#7
0
        private static void SetupBuiltInModules()
        {
            // Была мысль как-то ещё поделить, но я не придумал как...
            // Все эти функции - основа языка
            _builtInModulesActivators.Add("lang", context =>
            {
                ListFunctions.Define(context);
                ListSugarFunctions.Define(context);
                ControlFunctions.Define(context);
                TypePredicateFunctions.Define(context);
            });

            // Более того, следующие три набора функций так же можно было бы объединить с lang...
            // Но я их всё же вынес, потому как язык может работать и без них
            _builtInModulesActivators.Add("context", ContextFunctions.Define);
            _builtInModulesActivators.Add("console", ConsoleFunctions.Define);
            _builtInModulesActivators.Add("math", MathFunctions.Define);

            // А вот этот модуль вполне удобно иметь отдельным, потому как тогда имена его функций упрощаются
            _builtInModulesActivators.Add("table", TableFunctions.Define);
        }
示例#8
0
        public void RebindInput(Buttons button, ControlFunctions function)
        {
            var oldButton = _controls[function].Buttons[0];

            foreach (var func in _controls.Keys)
            {
                if (_controls[func].Buttons.Contains(button))
                {
                    _controls[func].UpdateButtonBinding(oldButton);
                }
            }

            _controls[function].UpdateButtonBinding(oldButton);

            if (function == ControlFunctions.Confirm)
            {
                _controls[ControlFunctions.Grab].UpdateButtonBinding(button);
            }
            else if (function == ControlFunctions.Back)
            {
                _controls[ControlFunctions.Run].UpdateButtonBinding(button);
            }
        }
示例#9
0
        public void RebindInput(Keys key, ControlFunctions function)
        {
            var oldKey = _controls[function].Keys[0];

            foreach (var func in _controls.Keys)
            {
                if (_controls[func].Keys.Contains(key))
                {
                    _controls[func].UpdateKeyBinding(oldKey);
                }
            }

            _controls[function].UpdateKeyBinding(key);

            if (function == ControlFunctions.Confirm)
            {
                _controls[ControlFunctions.Grab].UpdateKeyBinding(key);
            }
            else if (function == ControlFunctions.Back)
            {
                _controls[ControlFunctions.Run].UpdateKeyBinding(key);
            }
        }
示例#10
0
 public bool IsFunctionReady(ControlFunctions function)
 {
     return(_controls[function].FunctionReady);
 }
示例#11
0
 public static bool IsInputValidForState(ControlFunctions function, CharacterStates state)
 {
     return(_validInputStates[function].Contains(state));
 }
示例#12
0
    void FixedUpdate()
    {
        if (SystemController.isOnAndroid)   // if sys.isonandroid
        // if (isScaling && Input.touchCount == 2){
        //     Touch t1 = Input.GetTouch(0);
        //     Touch t2 = Input.GetTouch(1);

        //     Vector2 pos1 = t1.position - t1.deltaPosition;
        //     Vector2 pos2 = t2.position - t2.deltaPosition;
        //     float prevMag = (pos1 - pos2).magnitude;
        //     float currMag = (t1.position - t2.position).magnitude;
        //     float scaling = (currMag - prevMag) * Time.deltaTime;
        //     Debug.Log(scaling);
        //     // accScale += scaling;
        //     accScale = Mathf.Clamp(accScale, 1, 1.5f); // need to tuned
        //     if (accScale >= 1.5f || accScale <= 1f)
        //         return;
        //     foreach(Platform p in level.platforms){   // Can be optimized bere
        //         p.transform.localPosition += p.transform.localPosition * scaling;
        //     }

        //     sys.rotSpeed = (int) ( sys.initRotSpeed * accScale);

        // }
        {
            if (isRotating)
            {
                float      inputX = Input.GetTouch(0).deltaPosition.x;
                float      inputY = Input.GetTouch(0).deltaPosition.y;
                Quaternion rot    = ControlFunctions.calcRot1D(inputX, inputY, sys.rotSpeed);
                level.transform.Rotate(rot.eulerAngles, Space.World);

                foreach (Platform p in level.platforms)   // Can be optimized here
                {
                    p.resetRot();
                }
            }
        }
        else
        {
            if (isRotating)
            {
                float      inputX = Input.GetAxis("Mouse X");
                float      inputY = Input.GetAxis("Mouse Y");
                Quaternion rot    = ControlFunctions.calcRot1D(inputX, inputY, sys.rotSpeed);
                level.transform.Rotate(rot.eulerAngles, Space.World);

                foreach (Platform p in level.platforms)   // Can be optimized here
                {
                    p.resetRot();
                }
            }
            // else if (isScaling){    // There is a bug when scaling up and down too fast
            //     float scaling = Input.GetAxis("Mouse X") * Time.deltaTime;
            //     accScale += scaling;
            //     accScale = Mathf.Clamp(accScale, 1, 1.5f); // need to tuned
            //     if (accScale >= 1.5f || accScale <= 1f)
            //         return;
            //     foreach(Platform p in level.platforms){   // Can be optimized bere
            //         p.transform.localPosition += p.transform.localPosition * scaling;
            //     }
            // }
        }
    }
示例#13
0
 public static string GetStringForFunction(ControlFunctions function)
 {
     return(string.Empty);
 }
示例#14
0
    private void Update()
    {
        if (SystemController.isOnAndroid && sys.mode == 1)
        {
            if (Input.touchCount > 0)
            {
                if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                {
                    if (!finalizeRotation)
                    {
                        Touch t = Input.GetTouch(0);
                        if (t.phase == TouchPhase.Began)
                        {
                            RaycastHit hit;
                            Ray        r = main.ScreenPointToRay(t.position);
                            initPos = main.ScreenToViewportPoint(t.position);
                            if (Physics.Raycast(r, out hit, 20, 1 << 9))   // Max distance may be reduced
                            {
                                Platform p = hit.collider.GetComponent <Platform>();
                                p.updateRnC();

                                for (int i = 0, k = 0, l = 0, j = 0; j < 27; j++)
                                {
                                    level.platforms[j].updateRnC();
                                    if (i < 9 && level.platforms[j].row == p.row)
                                    {
                                        hP[i++] = level.platforms[j];
                                    }
                                    if (k < 9 && level.platforms[j].column == p.column)
                                    {
                                        vP[k++] = level.platforms[j];
                                    }
                                    if (l < 9 && level.platforms[j].z == p.z)
                                    {
                                        zP[l++] = level.platforms[j];
                                    }
                                }
                                isRotating = true;
                                isInside   = true;
                            }
                        }
                        else if (t.phase == TouchPhase.Ended)
                        {
                            isRotating = false;
                            Vector3 rot;
                            rotator          = (dir == 'H')? rotatorX : rotatorY;
                            rot              = rotator.rotation.eulerAngles;
                            rot.x            = ControlFunctions.getClosest(rot.x);
                            rot.y            = ControlFunctions.getClosest(rot.y);
                            rot.z            = ControlFunctions.getClosest(rot.z);
                            startRot         = rotator.rotation;
                            finalRot         = Quaternion.Euler(rot);
                            step             = 0.1f;
                            dir              = '0';
                            finalizeRotation = true;
                        }
                    }
                }
            }
        }
        else
        {
            if (sys.mode == 1 && !EventSystem.current.IsPointerOverGameObject())
            {
                if (Input.GetMouseButtonDown(0) && !finalizeRotation)
                {
                    RaycastHit hit;
                    Ray        r = main.ScreenPointToRay(Input.mousePosition);
                    initPos = main.ScreenToViewportPoint(Input.mousePosition);
                    if (Physics.Raycast(r, out hit, 20, 1 << 9))   // Max distance may be reduced
                    {
                        Platform p = hit.collider.GetComponent <Platform>();
                        p.updateRnC();

                        for (int i = 0, k = 0, l = 0, j = 0; j < 27; j++)
                        {
                            level.platforms[j].updateRnC();
                            if (i < 9 && level.platforms[j].row == p.row)
                            {
                                hP[i++] = level.platforms[j];
                            }
                            if (k < 9 && level.platforms[j].column == p.column)
                            {
                                vP[k++] = level.platforms[j];
                            }
                            if (l < 9 && level.platforms[j].z == p.z)
                            {
                                zP[l++] = level.platforms[j];
                            }
                        }
                        isRotating = true;
                        isInside   = true;
                    }
                }
                else if (Input.GetMouseButtonUp(0) && isRotating)
                {
                    isRotating = false;
                    Vector3 rot;
                    rotator          = (dir == 'H')? rotatorX : rotatorY;
                    rot              = rotator.rotation.eulerAngles;
                    rot.x            = ControlFunctions.getClosest(rot.x);
                    rot.y            = ControlFunctions.getClosest(rot.y);
                    rot.z            = ControlFunctions.getClosest(rot.z);
                    startRot         = rotator.rotation;
                    finalRot         = Quaternion.Euler(rot);
                    step             = 0.1f;
                    dir              = '0';
                    finalizeRotation = true;
                }
            }
        }
        if (finalizeRotation)
        {
            ControlFunctions.endRotating(rotator.gameObject, startRot, finalRot, ref step, ref finalizeRotation);
            for (int i = 0; i < 9; i++)
            {
                vP[i].resetRot();
                hP[i].resetRot();
            }
            if (!finalizeRotation)
            {
                for (int i = 0; i < 9; i++)
                {
                    vP[i].wrapUp();
                    hP[i].wrapUp();
                }
            }
        }
    }
示例#15
0
 public KeybindChangeEventArgs(ControlFunctions function, MenuButton button)
 {
     Function = function;
     Button   = button;
 }
示例#16
0
        public bool RequestSingleKeyRebind(ControlFunctions function)
        {
            var keys = _keyboardState.GetPressedKeys();

            bool rebound = false;

            // check here to make sure that the key is not one of the movement keys?

            if (keys.Length != 0)
            {
                RebindInput(keys[0], function);
                rebound = true;
            }

            // how do we do buttons? I guess we have to check everything individually?
            // don't allow to rebind stick/dpad

            if (_padState.IsButtonDown(Buttons.A))
            {
                RebindInput(Buttons.A, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.B))
            {
                RebindInput(Buttons.B, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.X))
            {
                RebindInput(Buttons.X, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.Y))
            {
                RebindInput(Buttons.Y, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.Back))
            {
                RebindInput(Buttons.Back, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.LeftShoulder))
            {
                RebindInput(Buttons.LeftShoulder, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.LeftTrigger))
            {
                RebindInput(Buttons.LeftTrigger, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.Start))
            {
                RebindInput(Buttons.Start, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.RightShoulder))
            {
                RebindInput(Buttons.RightShoulder, function);
                rebound = true;
            }
            else if (_padState.IsButtonDown(Buttons.RightTrigger))
            {
                RebindInput(Buttons.RightTrigger, function);
                rebound = true;
            }

            if (rebound)
            {
                _resourceManager.UpdatePreferenceKeybindData(_controls);
            }

            return(rebound);
        }