예제 #1
0
        // ---------------------
        override protected void OnUpdateControl()
        {
            base.OnUpdateControl();


            this.valPrev = this.valCur;



            // Touch started...

            if (this.touchStateWorld.JustPressedRaw())
            {
                this.startRawVal = this.rawValCur;

                if (this.physicalMode)
                {
                    this.startVec = this.touchStateOriented.GetCurPosSmooth();
                }
                else
                {
                    this.startVec = this.WorldToNormalizedPos(this.touchStateWorld.GetStartPos(), this.GetOriginOffset());
                }
            }


            if (this.touchStateWorld.PressedRaw())
            {
                float v = 0;

                if (this.physicalMode)
                {
                    v = (this.touchStateOriented.GetCurPosSmooth().x - this.startVec.x) / (this.physicalMoveRangeCm * CFScreen.dpcm * 0.5f);
                }
                else
                {
                    Vector3 np = this.WorldToNormalizedPos(this.touchStateWorld.GetCurPosSmooth(), this.GetOriginOffset());
                    v = (np.x - this.startVec.x);
                }


                float targetRawVal = this.startRawVal + v;         // * this.maxTurnAngle;

                this.rawValCur = CFUtils.MoveTowards(this.rawValCur, targetRawVal, (this.limitTurnSpeed ? this.minTurnTime : 0), Time.unscaledDeltaTime, 0.001f);
            }
            else
            {
                this.rawValCur = CFUtils.MoveTowards(this.rawValCur, 0, (this.limitTurnSpeed ? this.maxReturnTime : 0), Time.unscaledDeltaTime, 0.001f);
            }

            this.rawValCur = Mathf.Clamp(this.rawValCur, -1, 1);

            this.valCur = this.analogConfig.GetAnalogVal(this.rawValCur);


            if (this.IsActive())
            {
                this.SyncRigState();
            }
        }
예제 #2
0
        // ---------------------
        override protected void OnUpdateControl()
        {
            base.OnUpdateControl();


            this.valPrev = this.valCur;



            // Touch started...

            if (this.touchStateWorld.JustPressedRaw())
            {
                this.startRawVal = this.rawValCur;

                // Swipe mode...

                if (this.wheelMode == WheelMode.Swipe)
                {
                    if (this.physicalMode)
                    {
                        this.startVec = this.touchStateOriented.GetCurPosSmooth();
                    }
                    else
                    {
                        this.startVec = this.WorldToNormalizedPos(this.touchStateWorld.GetStartPos(), this.GetOriginOffset());
                    }
                }

                // Real mode...
                else
                {
                    this.startVec = this.WorldToNormalizedPos(this.touchStateWorld.GetStartPos(), this.GetOriginOffset());

                    this.angleIsSafe = false;
                    this.curAngle    = 0;
                    this.startAngle  = 0;
                    this.angleDelta  = 0;
//(this.startVec.sqrMagnitude > (this.realModeDeadZone * this.realModeDeadZone));
//				this.startAngle	= this.angleIsSafe ? this.GetWheelAngle(this.startVec, 0) : 0;
//				this.curAngle		= this.startAngle;
                }
            }


            if (this.touchStateWorld.PressedRaw())
            {
                float v = 0;

                // Swipe mode...

                if (this.wheelMode == WheelMode.Swipe)
                {
                    if (this.physicalMode)
                    {
                        v = (this.touchStateOriented.GetCurPosSmooth().x - this.startVec.x) / (this.physicalMoveRangeCm * CFScreen.dpcm * 0.5f);
                    }
                    else
                    {
                        Vector3 np = this.WorldToNormalizedPos(this.touchStateWorld.GetCurPosSmooth(), this.GetOriginOffset());
                        v = (np.x - this.startVec.x);
                    }
                }

                // Real mode...

                else
                {
                    Vector3 np = this.WorldToNormalizedPos(this.touchStateWorld.GetCurPosSmooth(), this.GetOriginOffset());
                    if (np.sqrMagnitude < (this.turnModeDeadZone * this.turnModeDeadZone))
                    {
                        this.angleIsSafe = false;
                    }
                    else
                    {
                        this.curAngle = this.GetWheelAngle(np, this.curAngle);

                        if (!this.angleIsSafe)
                        {
                            this.startAngle  = this.curAngle;
                            this.startRawVal = this.rawValCur;
                            this.angleIsSafe = true;
                        }
                    }

                    this.angleDelta = CFUtils.SmartDeltaAngle(this.startAngle, this.curAngle, this.angleDelta);

                    //if (!this.angleIsSafe)
                    //	this.angleDelta = Mathf.Clamp(this.angleDelta, -this.maxTurnAngle, this.maxTurnAngle);

                    this.angleDelta = Mathf.Clamp(this.angleDelta, -this.maxTurnAngle - 360, this.maxTurnAngle + 360);

                    v = this.angleDelta / this.maxTurnAngle;
                }

                float targetRawVal = this.startRawVal + v;         // * this.maxTurnAngle;

                this.rawValCur = CFUtils.MoveTowards(this.rawValCur, targetRawVal, (this.limitTurnSpeed ? this.minTurnTime : 0), CFUtils.realDeltaTime, 0.001f);
            }

            else
            {
                this.rawValCur = CFUtils.MoveTowards(this.rawValCur, 0, (this.limitTurnSpeed ? this.maxReturnTime : 0), CFUtils.realDeltaTime, 0.001f);
            }

            this.rawValCur = Mathf.Clamp(this.rawValCur, -1, 1);

            this.valCur = this.analogConfig.GetAnalogVal(this.rawValCur);


            if (this.IsActive())
            {
                this.SyncRigState();
            }
        }