Here are the examples of the csharp api UnityEngine.Mathf.Clamp01(float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
175 Examples
19
Source : Animation.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private static byte ToByte(float f)
{
f = Mathf.Clamp01(f);
return (byte)(f * 255);
}
19
Source : LagPosition.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void CoroutineUpdate(float delta)
{
Transform parent = this.mTrans.parent;
if (parent != null)
{
Vector3 vector = parent.position + parent.rotation * this.mRelative;
this.mAbsolute.x = Mathf.Lerp(this.mAbsolute.x, vector.x, Mathf.Clamp01(delta * this.speed.x));
this.mAbsolute.y = Mathf.Lerp(this.mAbsolute.y, vector.y, Mathf.Clamp01(delta * this.speed.y));
this.mAbsolute.z = Mathf.Lerp(this.mAbsolute.z, vector.z, Mathf.Clamp01(delta * this.speed.z));
this.mTrans.position = this.mAbsolute;
}
}
19
Source : LookAtTarget.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void LateUpdate()
{
if (this.target != null)
{
Vector3 forward = this.target.position - this.mTrans.position;
float magnitude = forward.magnitude;
if (magnitude > 0.001f)
{
Quaternion to = Quaternion.LookRotation(forward);
this.mTrans.rotation = Quaternion.Slerp(this.mTrans.rotation, to, Mathf.Clamp01(this.speed * Time.deltaTime));
}
}
}
19
Source : UICursor.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void Update()
{
if (this.mSprite.atlas != null)
{
Vector3 mousePosition = Input.mousePosition;
if (this.uiCamera != null)
{
mousePosition.x = Mathf.Clamp01(mousePosition.x / (float)Screen.width);
mousePosition.y = Mathf.Clamp01(mousePosition.y / (float)Screen.height);
this.mTrans.position = this.uiCamera.ViewportToWorldPoint(mousePosition);
if (this.uiCamera.isOrthoGraphic)
{
this.mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(this.mTrans.localPosition, this.mTrans.localScale);
}
}
else
{
mousePosition.x -= (float)Screen.width * 0.5f;
mousePosition.y -= (float)Screen.height * 0.5f;
this.mTrans.localPosition = NGUIMath.ApplyHalfPixelOffset(mousePosition, this.mTrans.localScale);
}
}
}
19
Source : UIDraggablePanel.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void LateUpdate()
{
if (this.repositionClipping)
{
this.repositionClipping = false;
this.mCalculatedBounds = false;
this.SetDragAmount(this.relativePositionOnReset.x, this.relativePositionOnReset.y, true);
}
if (!Application.isPlaying)
{
return;
}
float num = base.UpdateRealTimeDelta();
if (this.showScrollBars != UIDraggablePanel.ShowCondition.Always)
{
bool flag = false;
bool flag2 = false;
if (this.showScrollBars != UIDraggablePanel.ShowCondition.WhenDragging || this.mDragID != -10 || this.mMomentum.magnitude > 0.01f)
{
flag = this.shouldMoveVertically;
flag2 = this.shouldMoveHorizontally;
}
if (this.verticalScrollBar)
{
float num2 = this.verticalScrollBar.alpha;
num2 += ((!flag) ? (-num * 3f) : (num * 6f));
num2 = Mathf.Clamp01(num2);
if (this.verticalScrollBar.alpha != num2)
{
this.verticalScrollBar.alpha = num2;
}
}
if (this.horizontalScrollBar)
{
float num3 = this.horizontalScrollBar.alpha;
num3 += ((!flag2) ? (-num * 3f) : (num * 6f));
num3 = Mathf.Clamp01(num3);
if (this.horizontalScrollBar.alpha != num3)
{
this.horizontalScrollBar.alpha = num3;
}
}
}
if (this.mShouldMove && !this.mPressed)
{
this.mMomentum -= this.scale * (this.mScroll * 0.05f);
if (this.mMomentum.magnitude > 0.0001f)
{
this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, num);
Vector3 absolute = NGUIMath.SpringDampen(ref this.mMomentum, 9f, num);
this.MoveAbsolute(absolute);
if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None)
{
this.RestrictWithinBounds(false);
}
if (this.mMomentum.magnitude < 0.0001f && this.onDragFinished != null)
{
this.onDragFinished();
}
return;
}
this.mScroll = 0f;
this.mMomentum = Vectors.zero;
}
else
{
this.mScroll = 0f;
}
NGUIMath.SpringDampen(ref this.mMomentum, 9f, num);
}
19
Source : UIDraggablePanel.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void UpdateScrollbars(bool recalculateBounds)
{
if (this.mPanel == null)
{
return;
}
if (this.horizontalScrollBar != null || this.verticalScrollBar != null)
{
if (recalculateBounds)
{
this.mCalculatedBounds = false;
this.mShouldMove = this.shouldMove;
}
Bounds bounds = this.bounds;
Vector2 a = bounds.min;
Vector2 a2 = bounds.max;
if (this.mPanel.clipping == UIDrawCall.Clipping.SoftClip)
{
Vector2 clipSoftness = this.mPanel.clipSoftness;
a -= clipSoftness;
a2 += clipSoftness;
}
if (this.horizontalScrollBar != null && a2.x > a.x)
{
Vector4 clipRange = this.mPanel.clipRange;
float num = clipRange.z * 0.5f;
float num2 = clipRange.x - num - bounds.min.x;
float num3 = bounds.max.x - num - clipRange.x;
float num4 = a2.x - a.x;
num2 = Mathf.Clamp01(num2 / num4);
num3 = Mathf.Clamp01(num3 / num4);
float num5 = num2 + num3;
this.mIgnoreCallbacks = true;
this.horizontalScrollBar.barSize = 1f - num5;
this.horizontalScrollBar.scrollValue = ((num5 <= 0.001f) ? 0f : (num2 / num5));
this.mIgnoreCallbacks = false;
}
if (this.verticalScrollBar != null && a2.y > a.y)
{
Vector4 clipRange2 = this.mPanel.clipRange;
float num6 = clipRange2.w * 0.5f;
float num7 = clipRange2.y - num6 - a.y;
float num8 = a2.y - num6 - clipRange2.y;
float num9 = a2.y - a.y;
num7 = Mathf.Clamp01(num7 / num9);
num8 = Mathf.Clamp01(num8 / num9);
float num10 = num7 + num8;
this.mIgnoreCallbacks = true;
this.verticalScrollBar.barSize = 1f - num10;
this.verticalScrollBar.scrollValue = ((num10 <= 0.001f) ? 0f : (1f - num7 / num10));
this.mIgnoreCallbacks = false;
}
}
else if (recalculateBounds)
{
this.mCalculatedBounds = false;
}
}
19
Source : UIScrollBar.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void ForceUpdate()
{
this.mIsDirty = false;
if (this.mBG != null && this.mFG != null)
{
this.mSize = Mathf.Clamp01(this.mSize);
this.mScroll = Mathf.Clamp01(this.mScroll);
Vector4 border = this.mBG.border;
Vector4 border2 = this.mFG.border;
Vector2 vector = new Vector2(Mathf.Max(0f, this.mBG.cachedTransform.localScale.x - border.x - border.z), Mathf.Max(0f, this.mBG.cachedTransform.localScale.y - border.y - border.w));
float num = (!this.mInverted) ? this.mScroll : (1f - this.mScroll);
if (this.mDir == UIScrollBar.Direction.Horizontal)
{
Vector2 vector2 = new Vector2(vector.x * this.mSize, vector.y);
this.mFG.pivot = UIWidget.Pivot.Left;
this.mBG.pivot = UIWidget.Pivot.Left;
this.mBG.cachedTransform.localPosition = Vectors.zero;
this.mFG.cachedTransform.localPosition = new Vector3(border.x - border2.x + (vector.x - vector2.x) * num, 0f, 0f);
this.mFG.cachedTransform.localScale = new Vector3(vector2.x + border2.x + border2.z, vector2.y + border2.y + border2.w, 1f);
if (num < 0.999f && num > 0.001f)
{
this.mFG.MakePixelPerfect();
}
}
else
{
Vector2 vector3 = new Vector2(vector.x, vector.y * this.mSize);
this.mFG.pivot = UIWidget.Pivot.Top;
this.mBG.pivot = UIWidget.Pivot.Top;
this.mBG.cachedTransform.localPosition = Vectors.zero;
this.mFG.cachedTransform.localPosition = new Vector3(0f, -border.y + border2.y - (vector.y - vector3.y) * num, 0f);
this.mFG.cachedTransform.localScale = new Vector3(vector3.x + border2.x + border2.z, vector3.y + border2.y + border2.w, 1f);
if (num < 0.999f && num > 0.001f)
{
this.mFG.MakePixelPerfect();
}
}
}
}
19
Source : UISlider.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void Set(float input, bool force)
{
if (!this.mInitDone)
{
this.Init();
}
float num = Mathf.Clamp01(input);
if (num < 0.001f)
{
num = 0f;
}
float sliderValue = this.sliderValue;
this.rawValue = num;
float sliderValue2 = this.sliderValue;
if (force || sliderValue != sliderValue2)
{
Vector3 localScale = this.mSize;
if (this.direction == UISlider.Direction.Horizontal)
{
localScale.x *= sliderValue2;
}
else
{
localScale.y *= sliderValue2;
}
if (this.mFGFilled != null && this.mFGFilled.type == UISprite.Type.Filled)
{
this.mFGFilled.fillAmount = sliderValue2;
}
else if (this.foreground != null)
{
this.mFGTrans.localScale = localScale;
if (this.mFGWidget != null)
{
if (sliderValue2 > 0.001f)
{
this.mFGWidget.enabled = true;
this.mFGWidget.MarkAsChanged();
}
else
{
this.mFGWidget.enabled = false;
}
}
}
if (this.thumb != null)
{
Vector3 localPosition = this.thumb.localPosition;
if (this.mFGFilled != null && this.mFGFilled.type == UISprite.Type.Filled)
{
if (this.mFGFilled.fillDirection == UISprite.FillDirection.Horizontal)
{
localPosition.x = ((!this.mFGFilled.invert) ? localScale.x : (this.mSize.x - localScale.x));
}
else if (this.mFGFilled.fillDirection == UISprite.FillDirection.Vertical)
{
localPosition.y = ((!this.mFGFilled.invert) ? localScale.y : (this.mSize.y - localScale.y));
}
else
{
Debug.LogWarning("Slider thumb is only supported with Horizontal or Vertical fill direction", this);
}
}
else if (this.direction == UISlider.Direction.Horizontal)
{
localPosition.x = localScale.x;
}
else
{
localPosition.y = localScale.y;
}
this.thumb.localPosition = localPosition;
}
UISlider.current = this;
if (this.eventReceiver != null && !string.IsNullOrEmpty(this.functionName) && Application.isPlaying)
{
this.eventReceiver.SendMessage(this.functionName, sliderValue2, SendMessageOptions.DontRequireReceiver);
}
if (this.onValueChange != null)
{
this.onValueChange(sliderValue2);
}
UISlider.current = null;
}
}
19
Source : UISprite.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
protected bool AdjustRadial(Vector2[] xy, Vector2[] uv, float fill, bool invert)
{
if (fill < 0.001f)
{
return false;
}
if (!invert && fill > 0.999f)
{
return true;
}
float num = Mathf.Clamp01(fill);
if (!invert)
{
num = 1f - num;
}
num *= 1.57079637f;
float num2 = Mathf.Sin(num);
float num3 = Mathf.Cos(num);
if (num2 > num3)
{
num3 *= 1f / num2;
num2 = 1f;
if (!invert)
{
xy[0].y = Mathf.Lerp(xy[2].y, xy[0].y, num3);
xy[3].y = xy[0].y;
uv[0].y = Mathf.Lerp(uv[2].y, uv[0].y, num3);
uv[3].y = uv[0].y;
}
}
else if (num3 > num2)
{
num2 *= 1f / num3;
num3 = 1f;
if (invert)
{
xy[0].x = Mathf.Lerp(xy[2].x, xy[0].x, num2);
xy[1].x = xy[0].x;
uv[0].x = Mathf.Lerp(uv[2].x, uv[0].x, num2);
uv[1].x = uv[0].x;
}
}
else
{
num2 = 1f;
num3 = 1f;
}
if (invert)
{
xy[1].y = Mathf.Lerp(xy[2].y, xy[0].y, num3);
uv[1].y = Mathf.Lerp(uv[2].y, uv[0].y, num3);
}
else
{
xy[3].x = Mathf.Lerp(xy[2].x, xy[0].x, num2);
uv[3].x = Mathf.Lerp(uv[2].x, uv[0].x, num2);
}
return true;
}
19
Source : UITooltip.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void SetText(string tooltipText)
{
if (this.text != null && !string.IsNullOrEmpty(tooltipText))
{
this.mTarget = 1f;
if (this.text != null)
{
this.text.text = tooltipText;
}
this.mPos = Input.mousePosition;
if (this.background != null)
{
Transform transform = this.background.transform;
Transform transform2 = this.text.transform;
Vector3 localPosition = transform2.localPosition;
Vector3 localScale = transform2.localScale;
this.mSize = this.text.relativeSize;
this.mSize.x = this.mSize.x * localScale.x;
this.mSize.y = this.mSize.y * localScale.y;
this.mSize.x = this.mSize.x + (this.background.border.x + this.background.border.z + (localPosition.x - this.background.border.x) * 2f);
this.mSize.y = this.mSize.y + (this.background.border.y + this.background.border.w + (-localPosition.y - this.background.border.y) * 2f);
this.mSize.z = 1f;
transform.localScale = this.mSize;
}
if (this.uiCamera != null)
{
this.mPos.x = Mathf.Clamp01(this.mPos.x / (float)Screen.width);
this.mPos.y = Mathf.Clamp01(this.mPos.y / (float)Screen.height);
float num = this.uiCamera.orthographicSize / this.mTrans.parent.lossyScale.y;
float num2 = (float)Screen.height * 0.5f / num;
Vector2 vector = new Vector2(num2 * this.mSize.x / (float)Screen.width, num2 * this.mSize.y / (float)Screen.height);
this.mPos.x = Mathf.Min(this.mPos.x, 1f - vector.x);
this.mPos.y = Mathf.Max(this.mPos.y, vector.y);
this.mTrans.position = this.uiCamera.ViewportToWorldPoint(this.mPos);
this.mPos = this.mTrans.localPosition;
this.mPos.x = Mathf.Round(this.mPos.x);
this.mPos.y = Mathf.Round(this.mPos.y);
this.mTrans.localPosition = this.mPos;
}
else
{
if (this.mPos.x + this.mSize.x > (float)Screen.width)
{
this.mPos.x = (float)Screen.width - this.mSize.x;
}
if (this.mPos.y - this.mSize.y < 0f)
{
this.mPos.y = this.mSize.y;
}
this.mPos.x = this.mPos.x - (float)Screen.width * 0.5f;
this.mPos.y = this.mPos.y - (float)Screen.height * 0.5f;
}
}
else
{
this.mTarget = 0f;
}
}
19
Source : UITweener.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void Update()
{
float num = (!this.ignoreTimeScale) ? Time.deltaTime : base.UpdateRealTimeDelta();
float num2 = (!this.ignoreTimeScale) ? Time.time : base.realTime;
if (!this.mStarted)
{
this.mStarted = true;
this.mStartTime = num2 + this.delay;
}
if (num2 < this.mStartTime)
{
return;
}
this.mFactor += this.amountPerDelta * num;
if (this.style == UITweener.Style.Loop)
{
if (this.mFactor > 1f)
{
this.mFactor -= Mathf.Floor(this.mFactor);
}
}
else if (this.style == UITweener.Style.PingPong)
{
if (this.mFactor > 1f)
{
this.mFactor = 1f - (this.mFactor - Mathf.Floor(this.mFactor));
this.mAmountPerDelta = -this.mAmountPerDelta;
}
else if (this.mFactor < 0f)
{
this.mFactor = -this.mFactor;
this.mFactor -= Mathf.Floor(this.mFactor);
this.mAmountPerDelta = -this.mAmountPerDelta;
}
}
if (this.style == UITweener.Style.Once && (this.mFactor > 1f || this.mFactor < 0f))
{
this.mFactor = Mathf.Clamp01(this.mFactor);
this.Sample(this.mFactor, true);
if (this.onFinished != null)
{
this.onFinished(this);
}
if (this.eventReceiver != null && !string.IsNullOrEmpty(this.callWhenFinished))
{
this.eventReceiver.SendMessage(this.callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
}
if ((this.mFactor == 1f && this.mAmountPerDelta > 0f) || (this.mFactor == 0f && this.mAmountPerDelta < 0f))
{
base.enabled = false;
}
}
else
{
this.Sample(this.mFactor, false);
}
}
19
Source : UITweener.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void Sample(float factor, bool isFinished)
{
float num = Mathf.Clamp01(factor);
if (this.method == UITweener.Method.EaseIn)
{
num = 1f - Mathf.Sin(1.57079637f * (1f - num));
if (this.steeperCurves)
{
num *= num;
}
}
else if (this.method == UITweener.Method.EaseOut)
{
num = Mathf.Sin(1.57079637f * num);
if (this.steeperCurves)
{
num = 1f - num;
num = 1f - num * num;
}
}
else if (this.method == UITweener.Method.EaseInOut)
{
num -= Mathf.Sin(num * 6.28318548f) / 6.28318548f;
if (this.steeperCurves)
{
num = num * 2f - 1f;
float num2 = Mathf.Sign(num);
num = 1f - Mathf.Abs(num);
num = 1f - num * num;
num = num2 * num * 0.5f + 0.5f;
}
}
else if (this.method == UITweener.Method.BounceIn)
{
num = this.BounceLogic(num);
}
else if (this.method == UITweener.Method.BounceOut)
{
num = 1f - this.BounceLogic(1f - num);
}
this.OnUpdate((this.animationCurve == null) ? num : this.animationCurve.Evaluate(num), isFinished);
}
19
Source : Spline.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public SplineControlPoint LenToSegment(float t, out float localF)
{
SplineControlPoint splineControlPoint = null;
t = Mathf.Clamp01(t);
float num = t * this.mSegments[this.mSegments.Count - 1].Dist;
int i;
for (i = 0; i < this.mSegments.Count; i++)
{
if (this.mSegments[i].Dist >= num)
{
splineControlPoint = this.mSegments[i];
break;
}
}
if (i == 0)
{
localF = 0f;
return splineControlPoint;
}
int index = splineControlPoint.SegmentIndex - 1;
SplineControlPoint splineControlPoint2 = this.mSegments[index];
float num2 = splineControlPoint.Dist - splineControlPoint2.Dist;
localF = (num - splineControlPoint2.Dist) / num2;
return splineControlPoint2;
}
19
Source : SplineControlPoint.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public Vector3 Interpolate(float localF)
{
localF = Mathf.Clamp01(localF);
return Spline.CatmulRom(this.PreviousPosition, this.Position, this.NextPosition, this.GetNext2Position(), localF);
}
19
Source : SplineControlPoint.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public Vector3 InterpolateNormal(float localF)
{
localF = Mathf.Clamp01(localF);
return Spline.CatmulRom(this.PreviousNormal, this.Normal, this.NextNormal, this.GetNext2Normal(), localF);
}
19
Source : Mathf.cs
with MIT License
from AnotherEnd15
with MIT License
from AnotherEnd15
public static float Lerp(float a, float b, float t)
{
return a + (b - a) * Mathf.Clamp01(t);
}
19
Source : Mathf.cs
with MIT License
from AnotherEnd15
with MIT License
from AnotherEnd15
public static float LerpAngle(float a, float b, float t)
{
float num = Mathf.Repeat(b - a, 360f);
if ((double) num > 180.0)
num -= 360f;
return a + num * Mathf.Clamp01(t);
}
19
Source : Mathf.cs
with MIT License
from AnotherEnd15
with MIT License
from AnotherEnd15
public static float SmoothStep(float from, float to, float t)
{
t = Mathf.Clamp01(t);
t = (float) (-2.0 * (double) t * (double) t * (double) t + 3.0 * (double) t * (double) t);
return (float) ((double) to * (double) t + (double) from * (1.0 - (double) t));
}
19
Source : Mathf.cs
with MIT License
from AnotherEnd15
with MIT License
from AnotherEnd15
public static float InverseLerp(float a, float b, float value)
{
if ((double) a != (double) b)
return Mathf.Clamp01((float) (((double) value - (double) a) / ((double) b - (double) a)));
return 0.0f;
}
19
Source : Mathf.cs
with MIT License
from bbepis
with MIT License
from bbepis
public static float LerpAngle( float a, float b, float t )
{
float num = Repeat( b - a, 360f );
if( num > 180f )
{
num -= 360f;
}
return a + num * Clamp01( t );
}
19
Source : Mathf.cs
with MIT License
from bbepis
with MIT License
from bbepis
public static float SmoothStep( float from, float to, float t )
{
t = Clamp01( t );
t = -2f * t * t * t + 3f * t * t;
return to * t + from * ( 1f - t );
}
19
Source : Mathf.cs
with MIT License
from bbepis
with MIT License
from bbepis
public static float InverseLerp( float a, float b, float value )
{
if( a != b )
{
return Clamp01( ( value - a ) / ( b - a ) );
}
return 0f;
}
19
Source : Mathf.cs
with MIT License
from bbepis
with MIT License
from bbepis
public static float Lerp( float a, float b, float t )
{
return a + ( b - a ) * Clamp01( t );
}
19
Source : TrafficMeasurementManager.cs
with MIT License
from CitiesSkylinesMods
with MIT License
from CitiesSkylinesMods
public ushort CalcLaneRelativeMeanSpeed(ushort segmentId,
byte laneIndex,
uint laneId,
NetInfo.Lane laneInfo) {
if (LaneTrafficData[segmentId] == null
|| laneIndex >= LaneTrafficData[segmentId].Length)
{
return REF_REL_SPEED;
}
ushort currentBuf = LaneTrafficData[segmentId][laneIndex].trafficBuffer;
ushort curRelSpeed = REF_REL_SPEED;
// we use integer division here because it's faster
if (currentBuf > 0) {
uint laneVehicleSpeedLimit = Math.Min(
3u * 8u,
(uint)((Options.customSpeedLimitsEnabled
? SpeedLimitManager.Instance.GetLockFreeGameSpeedLimit(
segmentId,
laneIndex,
laneId,
laneInfo)
: laneInfo.m_speedLimit) * 8f));
if (laneVehicleSpeedLimit <= 0) {
// fallback: custom lanes may not have valid values set for speed limit
laneVehicleSpeedLimit = 1;
}
// 0 .. 10000, m_speedLimit of highway is 2 (100 km/h), actual max. vehicle speed
// on highway is 16, that's why we use x*8 == x<<3 (don't ask why CO uses different
// units for velocity)
curRelSpeed = (ushort)Math.Min(
REF_REL_SPEED,
(LaneTrafficData[segmentId][laneIndex].acreplacedulatedSpeeds * REF_REL_SPEED)
/ currentBuf
/ laneVehicleSpeedLimit);
if (curRelSpeed >=
GlobalConfig.Instance.DynamicLaneSelection.VolumeMeasurementRelSpeedThreshold *
(uint)REF_REL_SPEED_PERCENT_DENOMINATOR)
{
ushort lastBuf = LaneTrafficData[segmentId][laneIndex].lastTrafficBuffer;
ushort maxBuf = LaneTrafficData[segmentId][laneIndex].maxTrafficBuffer;
float factor = Mathf.Clamp01(1f - (lastBuf / (float)maxBuf));
curRelSpeed =
(ushort)(curRelSpeed + (uint)(factor * (REF_REL_SPEED - (uint)curRelSpeed)));
}
}
return curRelSpeed;
}
19
Source : BoxSlider.cs
with MIT License
from codeyuan666
with MIT License
from codeyuan666
void UpdateDrag(PointerEventData eventData, Camera cam)
{
RectTransform clickRect = m_HandleContainerRect;
if (clickRect != null && clickRect.rect.size[0] > 0)
{
Vector2 localCursor;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor))
return;
localCursor -= clickRect.rect.position;
float val = Mathf.Clamp01((localCursor - m_Offset)[0] / clickRect.rect.size[0]);
normalizedValue = (val);
float valY = Mathf.Clamp01((localCursor - m_Offset)[1] / clickRect.rect.size[1]);
normalizedValueY = ( valY);
}
}
19
Source : UIMirrorReflection.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
void MirrorReflectVertex(ref UIVertex vt)
{
var col = vt.color;
var pos = vt.position;
// Reflected color
var factor = Mathf.Clamp01((pos.y - _rect.yMin) / m_Height);
col *= Color.Lerp(m_StartColor, m_EndColor, factor);
// Reflected position.
pos.y = _rect.yMin * 2 - m_Spacing - pos.y + offset;
vt.position = pos;
vt.color = col;
}
19
Source : SoftMask.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera, Graphic g, int[] interactions)
{
if (!isActiveAndEnabled || (g == graphic && !g.raycastTarget))
{
return true;
}
int x = (int)((softMaskBuffer.width - 1) * Mathf.Clamp01(sp.x / Screen.width));
int y = (int)((softMaskBuffer.height - 1) * Mathf.Clamp01(sp.y / Screen.height));
// EDIT: Cytoid
return true;
return 0.5f < GetPixelValue(x, y, interactions);
}
19
Source : Packer.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public static float ToFloat(Vector4 factor)
{
return ToFloat(Mathf.Clamp01(factor.x), Mathf.Clamp01(factor.y), Mathf.Clamp01(factor.z), Mathf.Clamp01(factor.w));
}
19
Source : EffectArea.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public static void GetPositionFactor (this EffectArea area, int index, Rect rect, Vector2 position, bool isText, bool isTMPro, out float x, out float y)
{
if (isText && area == EffectArea.Character)
{
index = isTMPro ? (index + 3) % 4 : index % 4;
x = splitedCharacterPosition [index].x;
y = splitedCharacterPosition [index].y;
}
else if (area == EffectArea.Fit)
{
x = Mathf.Clamp01 ((position.x - rect.xMin) / rect.width);
y = Mathf.Clamp01 ((position.y - rect.yMin) / rect.height);
}
else
{
x = Mathf.Clamp01 (position.x / rect.width + 0.5f);
y = Mathf.Clamp01 (position.y / rect.height + 0.5f);
}
}
19
Source : ParameterTexture.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void SetData(IParameterTexture target, int channelId, float value)
{
SetData(target, channelId, (byte)(Mathf.Clamp01(value) * 255));
}
19
Source : LeanPath.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private Vector3 GetClosestPoint(Vector3 position, Vector3 origin, Vector3 direction)
{
var denom = Vector3.Dot(direction, direction);
// If the line doesn't point anywhere, return origin
if (denom == 0.0f)
{
return origin;
}
var dist01 = Vector3.Dot(position - origin, direction) / denom;
return origin + direction * Mathf.Clamp01(dist01);
}
19
Source : LeanPath.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private Vector3 GetClosestPoint(Ray ray, Vector3 origin, Vector3 direction)
{
var crossA = Vector3.Cross(ray.direction, direction);
var denom = Vector3.Dot(crossA, crossA);
// If lines are parallel, we can return any point on line
if (denom == 0.0f)
{
return origin;
}
var crossB = Vector3.Cross(ray.direction, ray.origin - origin);
var dist01 = Vector3.Dot(crossA, crossB) / denom;
return origin + direction * Mathf.Clamp01(dist01);
}
19
Source : DragLineElement.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private void OnGameUpdate(Game _)
{
UpdateTransform();
spriteRenderer.enabled = !Game.State.Mods.Contains(Mod.HideNotes);
if (outroRatio >= 1)
{
Collect();
return;
}
if (Game.SpawnedNotes.ContainsKey(FromNoteModel.id))
{
var note = Game.SpawnedNotes[FromNoteModel.id];
if (!note.IsCleared)
{
if (note.Renderer is ClreplacedicNoteRenderer clreplacedicNoteRenderer)
{
var fill = clreplacedicNoteRenderer.Fill;
spriteRenderer.color = spriteRenderer.color.WithAlpha(fill.enabled ? fill.color.a : 0);
}
else
{
var f = 1 - note.TimeUntilStart / (note.Model.start_time - note.Model.intro_time);
f = Mathf.Clamp01(f);
spriteRenderer.color = Color.white.WithAlpha(f);
}
}
}
var time = Game.Time;
introRatio = (FromNoteModel.nextdraglinestoptime - time) /
(FromNoteModel.nextdraglinestoptime - FromNoteModel.nextdraglinestarttime);
outroRatio = (time - FromNoteModel.start_time) / (ToNoteModel.start_time - FromNoteModel.start_time);
if (introRatio > 0 && introRatio < 1)
{
spriteRenderer.material.SetFloat(MaterialEnd, 1.0f - introRatio);
}
else if (introRatio <= 0)
{
spriteRenderer.material.SetFloat(MaterialEnd, 1.0f);
}
else
{
spriteRenderer.material.SetFloat(MaterialEnd, 0.0f);
}
if (outroRatio > 0 && outroRatio < 1)
{
spriteRenderer.material.SetFloat(MaterialStart, outroRatio);
}
}
19
Source : LoopAudioPlayer.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void UpdateMaxVolume(float volume)
{
var previousMaxVolume = MaxVolume;
MaxVolume = volume;
if (MaxVolume == 0) MaxVolume = 0.000001f;
audioMixerGroup.audioMixer.GetFloat("MasterVolume", out var currentMixerGroupVolume);
if (PrintDebugMessages) print($"LoopAudioPlayer: Current mixer group volume is {currentMixerGroupVolume}");
var currentVolume = ConvertTo01Volume(currentMixerGroupVolume);
var currentVolumePercentage = Mathf.Clamp01(currentVolume / previousMaxVolume);
var mixerGroupVolume = ConvertToMixerGroupVolume(currentVolumePercentage * MaxVolume);
audioMixerGroup.audioMixer.SetFloat("MasterVolume", mixerGroupVolume);
if (PrintDebugMessages) print($"LoopAudioPlayer: Mixer group volume set to {mixerGroupVolume}");
}
19
Source : ObjectiveCardView.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void SetModel(Objective objective)
{
completedIcon.gameObject.SetActive(objective.Completed);
LayoutFixer.Fix(completedIcon.parent);
descriptionText.text = objective.Description;
switch (objective.ProgressType)
{
case ProgressType.Percentage:
progressText.text = $"{objective.Progress}%/{objective.Completion}%";
break;
case ProgressType.OneDecimal:
progressText.text = $"{objective.Progress:F2}/{objective.Completion:F2}";
break;
case ProgressType.TwoDecimal:
progressText.text = $"{objective.Progress:F1}/{objective.Completion:F1}";
break;
default:
progressText.text = $"{Math.Round(objective.Progress)}/{Math.Round(objective.Completion)}";
break;
}
progressBar.progress = Mathf.Clamp01(objective.Progress / objective.Completion);
}
19
Source : Easings.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public static float Spring(float start, float end, float value)
{
value = Mathf.Clamp01(value);
value = (Mathf.Sin(value * Mathf.PI * (0.2f + 2.5f * value * value * value)) * Mathf.Pow(1f - value, 2.2f) +
value) * (1f + (1.2f * (1f - value)));
return start + (end - start) * value;
}
19
Source : Run.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private static IEnumerator _RunLerp(Run aRun, float aDuration, System.Action<float> aAction)
{
aRun.isDone = false;
var t = 0f;
while (t < 1.0f)
{
t = Mathf.Clamp01(t + Time.deltaTime / aDuration);
if (!aRun.abort && aAction != null)
aAction(t);
yield return null;
}
aRun.isDone = true;
}
19
Source : ScrollRectFocusHelper.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void CenterOnItem(RectTransform target)
{
// Item is here
var itemCenterPositionInScroll = GetWorldPointInWidget(mScrollTransform, GetWidgetWorldPoint(target));
// But must be here
var targetPositionInScroll = GetWorldPointInWidget(mScrollTransform, GetWidgetWorldPoint(maskTransform));
// So it has to move this distance
var difference = targetPositionInScroll - itemCenterPositionInScroll;
difference.z = 0f;
//clear axis data that is not enabled in the scrollrect
if (!mScrollRect.horizontal)
{
difference.x = 0f;
}
if (!mScrollRect.vertical)
{
difference.y = 0f;
}
var normalizedDifference = new Vector2(
difference.x / (mContent.rect.size.x - mScrollTransform.rect.size.x),
difference.y / (mContent.rect.size.y - mScrollTransform.rect.size.y));
var newNormalizedPosition = mScrollRect.normalizedPosition - normalizedDifference;
if (mScrollRect.movementType != ScrollRect.MovementType.Unrestricted)
{
newNormalizedPosition.x = Mathf.Clamp01(newNormalizedPosition.x);
newNormalizedPosition.y = Mathf.Clamp01(newNormalizedPosition.y);
}
mScrollRect.DONormalizedPos(newNormalizedPosition, 0.4f).SetEase(Ease.OutCubic);
}
19
Source : TierCard.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void Update()
{
if (!active || fadedOut) return;
var t = Mathf.Clamp01(Math.Abs(rectTransform.GetScreenSpaceCenter(canvas).y - screenCenter.y) / 540);
var a = 0.4f + Mathf.Lerp(0.8f, 0, t);
cardOverlayImage.SetAlpha(1 - a);
if (characterDisplay.IsLoaded)
{
characterDisplay.canvasGroup.alpha = a;
}
rectTransform.localScale = Vector3.one * (0.9f + Mathf.Lerp(0.1f, 0, t));
if (t < 0.5f)
{
canvas.overrideSorting = true;
canvas.sortingOrder = 9;
}
else
{
canvas.overrideSorting = true;
canvas.sortingOrder = 8;
}
}
19
Source : TierCard.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void OnTierStart()
{
fadedOut = true;
var t = Mathf.Clamp01(Math.Abs(rectTransform.GetScreenSpaceCenter(canvas).y - screenCenter.y) / 540);
if (t < 0.5f)
{
DOTween.Sequence()
.Append(rectTransform.DOScale(Vector3.one * 0.95f, 0.3f).SetEase(Ease.OutCubic))
.Append(rectTransform.DOScale(Vector3.one, 0.3f).SetEase(Ease.InCubic));
}
else
{
cardOverlayImage.DOFade(1, 0.4f);
if (characterDisplay.IsLoaded)
{
characterDisplay.canvasGroup.DOFade(0, 0.4f);
}
}
}
19
Source : Easings.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public static float SpringD(float start, float end, float value)
{
value = Mathf.Clamp01(value);
end -= start;
// Damn... Thanks http://www.derivative-calculator.net/
return end * (6f * (1f - value) / 5f + 1f) * (-2.2f * Mathf.Pow(1f - value, 1.2f) *
Mathf.Sin(
Mathf.PI * value * (2.5f * value * value * value + 0.2f)) +
Mathf.Pow(1f - value, 2.2f) *
(Mathf.PI * (2.5f * value * value * value + 0.2f) +
7.5f * Mathf.PI * value * value * value) *
Mathf.Cos(
Mathf.PI * value * (2.5f * value * value * value + 0.2f)) +
1f) -
6f * end * (Mathf.Pow(1 - value, 2.2f) *
Mathf.Sin(Mathf.PI * value * (2.5f * value * value * value + 0.2f)) + value
/ 5f);
}
19
Source : Interpolator.cs
with MIT License
from dag10
with MIT License
from dag10
public void Update()
{
bool interpOccuredThisFrame = false;
if (AnimatingPosition)
{
Vector3 lerpTargetPosition = targetPosition;
if (SmoothLerpToTarget)
{
lerpTargetPosition = Vector3.Lerp(transform.position, lerpTargetPosition, SmoothPositionLerpRatio);
}
Vector3 newPosition = NonLinearInterpolateTo(transform.position, lerpTargetPosition, Time.deltaTime, PositionPerSecond);
if ((targetPosition - newPosition).sqrMagnitude <= smallNumber)
{
// Snap to final position
newPosition = targetPosition;
AnimatingPosition = false;
}
else
{
interpOccuredThisFrame = true;
}
transform.position = newPosition;
//calculate interpolatedVelocity and store position for next frame
PositionVelocity = oldPosition - newPosition;
oldPosition = newPosition;
}
// Determine how far we need to rotate
if (AnimatingRotation)
{
Quaternion lerpTargetRotation = targetRotation;
if (SmoothLerpToTarget)
{
lerpTargetRotation = Quaternion.Lerp(transform.rotation, lerpTargetRotation, SmoothRotationLerpRatio);
}
float angleDiff = Quaternion.Angle(transform.rotation, lerpTargetRotation);
float speedScale = 1.0f + (Mathf.Pow(angleDiff, RotationSpeedScaler) / 180.0f);
float ratio = Mathf.Clamp01((speedScale * RotationDegreesPerSecond * Time.deltaTime) / angleDiff);
if (angleDiff < Mathf.Epsilon)
{
AnimatingRotation = false;
transform.rotation = targetRotation;
}
else
{
// Only lerp rotation here, as ratio is NaN if angleDiff is 0.0f
transform.rotation = Quaternion.Slerp(transform.rotation, lerpTargetRotation, ratio);
interpOccuredThisFrame = true;
}
}
// Determine how far we need to rotate
if (AnimatingLocalRotation)
{
Quaternion lerpTargetLocalRotation = targetLocalRotation;
if (SmoothLerpToTarget)
{
lerpTargetLocalRotation = Quaternion.Lerp(transform.localRotation, lerpTargetLocalRotation, SmoothRotationLerpRatio);
}
float angleDiff = Quaternion.Angle(transform.localRotation, lerpTargetLocalRotation);
float speedScale = 1.0f + (Mathf.Pow(angleDiff, RotationSpeedScaler) / 180.0f);
float ratio = Mathf.Clamp01((speedScale * RotationDegreesPerSecond * Time.deltaTime) / angleDiff);
if (angleDiff < Mathf.Epsilon)
{
AnimatingLocalRotation = false;
transform.localRotation = targetLocalRotation;
}
else
{
// Only lerp rotation here, as ratio is NaN if angleDiff is 0.0f
transform.localRotation = Quaternion.Slerp(transform.localRotation, lerpTargetLocalRotation, ratio);
interpOccuredThisFrame = true;
}
}
if (AnimatingLocalScale)
{
Vector3 lerpTargetLocalScale = targetLocalScale;
if (SmoothLerpToTarget)
{
lerpTargetLocalScale = Vector3.Lerp(transform.localScale, lerpTargetLocalScale, SmoothScaleLerpRatio);
}
Vector3 newScale = NonLinearInterpolateTo(transform.localScale, lerpTargetLocalScale, Time.deltaTime, ScalePerSecond);
if ((targetLocalScale - newScale).sqrMagnitude <= smallNumber)
{
// Snap to final scale
newScale = targetLocalScale;
AnimatingLocalScale = false;
}
else
{
interpOccuredThisFrame = true;
}
transform.localScale = newScale;
}
// If all interpolations have completed, stop updating
if (!interpOccuredThisFrame)
{
if (InterpolationDone != null)
{
InterpolationDone();
}
enabled = false;
}
}
19
Source : UI.cs
with MIT License
from dag10
with MIT License
from dag10
private void Update_Colors()
{
const float TimeToFadeAfterQuery = 3.0f;
// Time since query (fade for a bit after a query)
float timeSinceQuery = (float)(DateTime.Now - timeLastQuery).TotalSeconds;
float alphaScale = Mathf.SmoothStep(0.0f, 1.0f, Mathf.Clamp01(timeSinceQuery - TimeToFadeAfterQuery)) * 0.8f + 0.2f;
// Colors
Color colorButtonActive = new Color(1.0f, 1.0f, 1.0f, 0.8f * alphaScale);
Color colorButtonInactive = new Color(1.0f, 1.0f, 1.0f, 0.25f * alphaScale);
Color colorPanelActive = new Color(1.0f, 1.0f, 1.0f, 0.6f * alphaScale);
Color colorPanelInactive = new Color(1.0f, 1.0f, 1.0f, 0.15f * alphaScale);
// Colors on buttons
for (int i = 0; i < (int)Panels.PANEL_COUNT; ++i)
{
bool isEnabled = (i == (int)ActivePanel);
ButtonPanels[i].Button.enabled = isEnabled;
ButtonPanels[i].ButtonImage.color = isEnabled ? colorButtonActive : colorButtonInactive;
ButtonPanels[i].Background.enabled = isEnabled;
ButtonPanels[i].Background.color = isEnabled ? colorPanelActive : colorPanelInactive;
ButtonPanels[i].ButtonGrid.enabled = isEnabled;
for (int j = 0; j < ButtonPanels[i].GridButtons.Count; ++j)
{
ButtonPanels[i].GridButtons[j].gameObject.SetActive(isEnabled);
}
}
}
19
Source : LinearDrive.cs
with MIT License
from dag10
with MIT License
from dag10
private void UpdateLinearMapping( Transform tr )
{
prevMapping = linearMapping.value;
linearMapping.value = Mathf.Clamp01( initialMappingOffset + CalculateLinearMapping( tr ) );
mappingChangeSamples[sampleCount % mappingChangeSamples.Length] = ( 1.0f / Time.deltaTime ) * ( linearMapping.value - prevMapping );
sampleCount++;
if ( repositionGameObject )
{
transform.position = Vector3.Lerp( startPosition.position, endPosition.position, linearMapping.value );
}
}
19
Source : LinearDrive.cs
with MIT License
from dag10
with MIT License
from dag10
void Update()
{
if ( maintainMomemntum && mappingChangeRate != 0.0f )
{
//Dampen the mapping change rate and apply it to the mapping
mappingChangeRate = Mathf.Lerp( mappingChangeRate, 0.0f, momemtumDampenRate * Time.deltaTime );
linearMapping.value = Mathf.Clamp01( linearMapping.value + ( mappingChangeRate * Time.deltaTime ) );
if ( repositionGameObject )
{
transform.position = Vector3.Lerp( startPosition.position, endPosition.position, linearMapping.value );
}
}
}
19
Source : SteamVR_LoadLevel.cs
with MIT License
from dag10
with MIT License
from dag10
void Update()
{
if (_active != this)
return;
alpha = Mathf.Clamp01(alpha + fadeRate * Time.deltaTime);
var overlay = OpenVR.Overlay;
if (overlay != null)
{
if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
overlay.SetOverlayAlpha(loadingScreenOverlayHandle, alpha);
if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
overlay.SetOverlayAlpha(progressBarOverlayHandle, alpha);
}
}
19
Source : CharacterMotor.cs
with MIT License
from deadgg
with MIT License
from deadgg
public CharacterMotorState Simulate(Vector3 moveDirection, bool shouldJump)
{
var deltaTime = Zapnet.Network.FixedDeltaTime;
var velocity = state.velocity;
velocity = ApplyInputVelocityChange(velocity, moveDirection);
velocity = ApplyGravityAndJumping(velocity, shouldJump);
var moveDistance = Vector3.zero;
var currentMovementOffset = velocity * deltaTime;
var lastPosition = transform.position;
var pushDownOffset = Mathf.Max(_controller.stepOffset, new Vector3(currentMovementOffset.x, 0, currentMovementOffset.z).magnitude);
if (state.isGrounded)
{
currentMovementOffset = currentMovementOffset - (pushDownOffset * Vector3.up);
}
if (!Physics.autoSyncTransforms)
{
Physics.SyncTransforms();
}
_groundNormal = Vector3.zero;
_controller.Move(Vector3.zero);
state.collisionFlags = _controller.Move(currentMovementOffset);
state.lastHitPoint = state.hitPoint;
_lastGroundNormal = _groundNormal;
var oldHorizontalVelocity = new Vector3(velocity.x, 0, velocity.z);
state.velocity = (transform.position - lastPosition) / deltaTime;
var newHorizontalVelocity = new Vector3(state.velocity.x, 0, state.velocity.z);
if (oldHorizontalVelocity == Vector3.zero)
{
state.velocity = new Vector3(0, state.velocity.y, 0);
}
else
{
float projectedNewVelocity = Vector3.Dot(newHorizontalVelocity, oldHorizontalVelocity) / oldHorizontalVelocity.sqrMagnitude;
state.velocity = (oldHorizontalVelocity * Mathf.Clamp01(projectedNewVelocity)) + (state.velocity.y * Vector3.up);
}
if (state.velocity.y < (velocity.y - 0.001f))
{
if (state.velocity.y < 0)
{
state.velocity.y = velocity.y;
}
else
{
state.holdingJumpButton = false;
}
}
if (state.isGrounded && !IsGroundedTest())
{
state.isGrounded = false;
transform.position = transform.position + (pushDownOffset * Vector3.up);
}
else
{
if (!state.isGrounded && IsGroundedTest())
{
state.isGrounded = true;
state.isJumping = false;
}
}
return state;
}
19
Source : NetworkHitbox.cs
with MIT License
from deadgg
with MIT License
from deadgg
public void Rewind(uint tick)
{
if (_enreplacedy)
{
var currentTick = Zapnet.Network.LocalTick;
var renderTick = tick - _enreplacedy.interpolationTicks;
var targetTick = tick;
if (!_history.TryGetValue(renderTick, out var render))
{
uint closestTick = 0;
foreach (var kv in _history)
{
var historyTick = kv.Key;
if (historyTick <= renderTick && historyTick > closestTick)
{
closestTick = historyTick;
renderTick = historyTick;
render = kv.Value;
break;
}
}
}
if (_history.TryGetValue(targetTick, out var target))
{
var progress = Mathf.Clamp01((1f / _enreplacedy.interpolationTicks) * (currentTick - targetTick));
_transform.position = Vector3.Lerp(render.position, target.position, progress);
_transform.rotation = Quaternion.Lerp(render.rotation, target.rotation, progress);
return;
}
}
if (_history.TryGetValue(tick, out var data))
{
_transform.position = data.position;
_transform.rotation = data.rotation;
}
}
19
Source : PlayerControls.cs
with Apache License 2.0
from dmitmel
with Apache License 2.0
from dmitmel
void FixedUpdate() {
if (Input.GetButtonDown("Show Game Guide"))
GuideManager.instance.LoadGuide(GuideManager.instance.gameGuide);
if (Input.GetButtonDown("Auto Fire")) {
if (autoFireEnabled) {
foreach (Gun gun in tank.guns)
gun.StopFiring();
}
autoFireEnabled = !autoFireEnabled;
}
if (autoFireEnabled) {
foreach (Gun gun in tank.guns)
gun.Fire();
} else {
if (Input.GetButton("Fire")) {
foreach (Gun gun in tank.guns)
gun.Fire();
} else if (Input.GetButtonUp("Fire")) {
foreach (Gun gun in tank.guns)
gun.StopFiring();
}
}
float horizontalAxis = Input.GetAxis("Horizontal");
float verticalAxis = Input.GetAxis("Vertical");
float movementSpeed = tank.stats.movementSpeed.Value;
float rotationX = 0, rotationY = 0;
switch (Settings.controlsTypeValue) {
case ControlsType.WASDMovement:
rotationX = Input.GetAxis("Mouse X") * Settings.sensetivityValue;
rotationY = Input.GetAxis("Mouse Y") * Settings.sensetivityValue;
currentVelocity = new Vector3(horizontalAxis, 0, verticalAxis);
break;
case ControlsType.WASDTilt:
rotationX = horizontalAxis * Settings.sensetivityValue;
rotationY = verticalAxis * Settings.sensetivityValue;
currentVelocity = new Vector3(0, 0, Mathf.Clamp01(currentVelocity.z + Input.GetAxis("Speed")));
break;
}
if (Input.GetButtonDown("Auto Spin")) autoSpinEnabled = !autoSpinEnabled;
if (autoSpinEnabled) {
transform.rotation *= Quaternion.Euler(0, autoSpinSpeed, 0);
} else {
if (Settings.inversedControlsValue) rotationY = -rotationY;
var xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
var yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
transform.localRotation *= yQuaternion * xQuaternion;
}
if (currentVelocity.sqrMagnitude > 1) currentVelocity.Normalize();
rigidbody.AddRelativeForce(currentVelocity * movementSpeed * accelerationMultiplier);
if (rigidbody.velocity.sqrMagnitude > movementSpeed * movementSpeed) rigidbody.velocity.Normalize();
}
19
Source : InjectionEntry.cs
with MIT License
from EtiamNullam
with MIT License
from EtiamNullam
private static float GetGasColorIntensity(float mreplaced, float maxMreplaced)
{
var minIntensity = State.ConfiguratorState.MinimumGasColorIntensity;
var intensity = mreplaced / maxMreplaced;
intensity = Mathf.Sqrt(intensity);
intensity = Mathf.Clamp01(intensity);
intensity *= 1 - minIntensity;
intensity += minIntensity;
return intensity;
}
See More Examples