UnityEngine.Mathf.Sin(float)

Here are the examples of the csharp api UnityEngine.Mathf.Sin(float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

168 Examples 7

19 Source : Bloom.cs
with Apache License 2.0
from activey

public void OnRenderImage (RenderTexture source, RenderTexture destination)
        {
            if (CheckResources()==false)
            {
                Graphics.Blit (source, destination);
                return;
            }

            // screen blend is not supported when HDR is enabled (will cap values)

            doHdr = false;
            if (hdr == HDRBloomMode.Auto)
                doHdr = source.format == RenderTextureFormat.ARGBHalf && GetComponent<Camera>().hdr;
            else {
                doHdr = hdr == HDRBloomMode.On;
            }

            doHdr = doHdr && supportHDRTextures;

            BloomScreenBlendMode realBlendMode = screenBlendMode;
            if (doHdr)
                realBlendMode = BloomScreenBlendMode.Add;

            var rtFormat= (doHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.Default;
            var rtW2= source.width/2;
            var rtH2= source.height/2;
            var rtW4= source.width/4;
            var rtH4= source.height/4;

            float widthOverHeight = (1.0f * source.width) / (1.0f * source.height);
            float oneOverBaseSize = 1.0f / 512.0f;

            // downsample
            RenderTexture quarterRezColor = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
            RenderTexture halfRezColorDown = RenderTexture.GetTemporary (rtW2, rtH2, 0, rtFormat);
            if (quality > BloomQuality.Cheap) {
                Graphics.Blit (source, halfRezColorDown, screenBlend, 2);
                RenderTexture rtDown4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
                Graphics.Blit (halfRezColorDown, rtDown4, screenBlend, 2);
                Graphics.Blit (rtDown4, quarterRezColor, screenBlend, 6);
                RenderTexture.ReleaseTemporary(rtDown4);
            }
            else {
                Graphics.Blit (source, halfRezColorDown);
                Graphics.Blit (halfRezColorDown, quarterRezColor, screenBlend, 6);
            }
            RenderTexture.ReleaseTemporary (halfRezColorDown);

            // cut colors (thresholding)
            RenderTexture secondQuarterRezColor = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
            BrightFilter (bloomThreshold * bloomThresholdColor, quarterRezColor, secondQuarterRezColor);

            // blurring

            if (bloomBlurIterations < 1) bloomBlurIterations = 1;
            else if (bloomBlurIterations > 10) bloomBlurIterations = 10;

            for (int iter = 0; iter < bloomBlurIterations; iter++)
			{
                float spreadForPreplaced = (1.0f + (iter * 0.25f)) * sepBlurSpread;

                // vertical blur
                RenderTexture blur4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
                blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (0.0f, spreadForPreplaced * oneOverBaseSize, 0.0f, 0.0f));
                Graphics.Blit (secondQuarterRezColor, blur4, blurAndFlaresMaterial, 4);
                RenderTexture.ReleaseTemporary(secondQuarterRezColor);
                secondQuarterRezColor = blur4;

                // horizontal blur
                blur4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);
                blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 ((spreadForPreplaced / widthOverHeight) * oneOverBaseSize, 0.0f, 0.0f, 0.0f));
                Graphics.Blit (secondQuarterRezColor, blur4, blurAndFlaresMaterial, 4);
                RenderTexture.ReleaseTemporary (secondQuarterRezColor);
                secondQuarterRezColor = blur4;

                if (quality > BloomQuality.Cheap)
				{
                    if (iter == 0)
                    {
                        Graphics.SetRenderTarget(quarterRezColor);
                        GL.Clear(false, true, Color.black); // Clear to avoid RT restore
                        Graphics.Blit (secondQuarterRezColor, quarterRezColor);
                    }
                    else
                    {
                        quarterRezColor.MarkRestoreExpected(); // using max blending, RT restore expected
                        Graphics.Blit (secondQuarterRezColor, quarterRezColor, screenBlend, 10);
                    }
                }
            }

            if (quality > BloomQuality.Cheap)
            {
                Graphics.SetRenderTarget(secondQuarterRezColor);
                GL.Clear(false, true, Color.black); // Clear to avoid RT restore
                Graphics.Blit (quarterRezColor, secondQuarterRezColor, screenBlend, 6);
            }

            // lens flares: ghosting, anamorphic or both (ghosted anamorphic flares)

            if (lensflareIntensity > Mathf.Epsilon)
			{

                RenderTexture rtFlares4 = RenderTexture.GetTemporary (rtW4, rtH4, 0, rtFormat);

                if (lensflareMode == 0)
				{
                    // ghosting only

                    BrightFilter (lensflareThreshold, secondQuarterRezColor, rtFlares4);

                    if (quality > BloomQuality.Cheap)
					{
                        // smooth a little
                        blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (0.0f, (1.5f) / (1.0f * quarterRezColor.height), 0.0f, 0.0f));
                        Graphics.SetRenderTarget(quarterRezColor);
                        GL.Clear(false, true, Color.black); // Clear to avoid RT restore
                        Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 4);

                        blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 ((1.5f) / (1.0f * quarterRezColor.width), 0.0f, 0.0f, 0.0f));
                        Graphics.SetRenderTarget(rtFlares4);
                        GL.Clear(false, true, Color.black); // Clear to avoid RT restore
                        Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 4);
                    }

                    // no ugly edges!
                    Vignette (0.975f, rtFlares4, rtFlares4);
                    BlendFlares (rtFlares4, secondQuarterRezColor);
                }
                else
				{

                    //Vignette (0.975ff, rtFlares4, rtFlares4);
                    //DrawBorder(rtFlares4, screenBlend, 8);

                    float flareXRot = 1.0f * Mathf.Cos(flareRotation);
                    float flareyRot = 1.0f * Mathf.Sin(flareRotation);

                    float stretchWidth = (hollyStretchWidth * 1.0f / widthOverHeight) * oneOverBaseSize;

                    blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (flareXRot, flareyRot, 0.0f, 0.0f));
                    blurAndFlaresMaterial.SetVector ("_Threshhold", new Vector4 (lensflareThreshold, 1.0f, 0.0f, 0.0f));
                    blurAndFlaresMaterial.SetVector ("_TintColor", new Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * flareColorA.a * lensflareIntensity);
                    blurAndFlaresMaterial.SetFloat ("_Saturation", lensFlareSaturation);

                    // "pre and cut"
                    quarterRezColor.DiscardContents();
                    Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 2);
                    // "post"
                    rtFlares4.DiscardContents();
                    Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 3);

                    blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (flareXRot * stretchWidth, flareyRot * stretchWidth, 0.0f, 0.0f));
                    // stretch 1st
                    blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth);
                    quarterRezColor.DiscardContents();
                    Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 1);
                    // stretch 2nd
                    blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth * 2.0f);
                    rtFlares4.DiscardContents();
                    Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 1);
                    // stretch 3rd
                    blurAndFlaresMaterial.SetFloat ("_StretchWidth", hollyStretchWidth * 4.0f);
                    quarterRezColor.DiscardContents();
                    Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 1);

                    // additional blur preplacedes
                    for (int iter = 0; iter < hollywoodFlareBlurIterations; iter++)
					{
                        stretchWidth = (hollyStretchWidth * 2.0f / widthOverHeight) * oneOverBaseSize;

                        blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (stretchWidth * flareXRot, stretchWidth * flareyRot, 0.0f, 0.0f));
                        rtFlares4.DiscardContents();
                        Graphics.Blit (quarterRezColor, rtFlares4, blurAndFlaresMaterial, 4);

                        blurAndFlaresMaterial.SetVector ("_Offsets", new Vector4 (stretchWidth * flareXRot, stretchWidth * flareyRot, 0.0f, 0.0f));
                        quarterRezColor.DiscardContents();
                        Graphics.Blit (rtFlares4, quarterRezColor, blurAndFlaresMaterial, 4);
                    }

                    if (lensflareMode == (LensFlareStyle) 1)
                        // anamorphic lens flares
                        AddTo (1.0f, quarterRezColor, secondQuarterRezColor);
                    else
					{
                        // "combined" lens flares

                        Vignette (1.0f, quarterRezColor, rtFlares4);
                        BlendFlares (rtFlares4, quarterRezColor);
                        AddTo (1.0f, quarterRezColor, secondQuarterRezColor);
                    }
                }
                RenderTexture.ReleaseTemporary (rtFlares4);
            }

            int blendPreplaced = (int) realBlendMode;
            //if (Mathf.Abs(chromaticBloom) < Mathf.Epsilon)
            //	blendPreplaced += 4;

            screenBlend.SetFloat ("_Intensity", bloomIntensity);
            screenBlend.SetTexture ("_ColorBuffer", source);

            if (quality > BloomQuality.Cheap)
			{
                RenderTexture halfRezColorUp = RenderTexture.GetTemporary (rtW2, rtH2, 0, rtFormat);
                Graphics.Blit (secondQuarterRezColor, halfRezColorUp);
                Graphics.Blit (halfRezColorUp, destination, screenBlend, blendPreplaced);
                RenderTexture.ReleaseTemporary (halfRezColorUp);
            }
            else
                Graphics.Blit (secondQuarterRezColor, destination, screenBlend, blendPreplaced);

            RenderTexture.ReleaseTemporary (quarterRezColor);
            RenderTexture.ReleaseTemporary (secondQuarterRezColor);
        }

19 Source : PostEffectsHelper.cs
with Apache License 2.0
from activey

static void DrawLowLevelPlaneAlignedWithCamera (
            float dist ,
            RenderTexture source, RenderTexture dest ,
            Material material ,
            Camera cameraForProjectionMatrix )
        {
            // Make the destination texture the target for all rendering
            RenderTexture.active = dest;
            // replacedign the source texture to a property from a shader
            material.SetTexture("_MainTex", source);
            bool  invertY = true; // source.texelSize.y < 0.0f;
            // Set up the simple Matrix
            GL.PushMatrix();
            GL.LoadIdenreplacedy();
            GL.LoadProjectionMatrix(cameraForProjectionMatrix.projectionMatrix);

            float fovYHalfRad = cameraForProjectionMatrix.fieldOfView * 0.5f * Mathf.Deg2Rad;
            float cotangent = Mathf.Cos(fovYHalfRad) / Mathf.Sin(fovYHalfRad);
            float asp = cameraForProjectionMatrix.aspect;

            float x1 = asp/-cotangent;
            float x2 = asp/cotangent;
            float y1 = 1.0f/-cotangent;
            float y2 = 1.0f/cotangent;

            float sc = 1.0f; // magic constant (for now)

            x1 *= dist * sc;
            x2 *= dist * sc;
            y1 *= dist * sc;
            y2 *= dist * sc;

            float z1 = -dist;

            for (int i = 0; i < material.preplacedCount; i++)
            {
                material.SetPreplaced(i);

                GL.Begin(GL.QUADS);
                float y1_; float y2_;
                if (invertY)
                {
                    y1_ = 1.0f; y2_ = 0.0f;
                }
                else
                {
                    y1_ = 0.0f; y2_ = 1.0f;
                }
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, z1);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, z1);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, z1);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, z1);
                GL.End();
            }

            GL.PopMatrix();
        }

19 Source : EdgeComponent.cs
with Apache License 2.0
from activey

private void InitializeEdgeComponent()
		{
			LineRenderer line = GetVisualComponent ().GetComponent<LineRenderer> ();
			line.name = "Edge_" + graphEdge.GetId ();

			float angle = UnityEngine.Random.Range (0, 360);
		
			float xRotation = Mathf.Cos (Mathf.Deg2Rad * angle) * 100;
			float yRotation = Mathf.Sin (Mathf.Deg2Rad * angle) * 100;
			float zRotation = Mathf.Cos (Mathf.Deg2Rad * angle) * 100;
			GetVisualComponent().transform.Rotate(new Vector3 (xRotation, yRotation, zRotation));
		}

19 Source : Bullet.cs
with GNU General Public License v3.0
from aelariane

private void GetSpiral(Vector3 masterposition, Vector3 masterrotation)
    {
        float num = 30f;
        float num2 = 0.5f;
        float num3 = 0.05f + (float)this.spiralcount * 0.03f;
        float num5;
        if (this.spiralcount < 5)
        {
            float num4 = Vector2.Distance(new Vector2(masterposition.x, masterposition.z), new Vector2(baseGT.position.x, baseGT.position.z));
            num5 = num4;
        }
        else
        {
            num5 = 1.2f + (float)(60 - this.spiralcount) * 0.1f;
        }
        num2 -= (float)this.spiralcount * 0.06f;
        float num6 = num5 / num;
        float num7 = num3 / num;
        float num8 = num7 * 2f * 3.14159274f;
        num2 *= 6.28318548f;
        this.spiralNodes = new List<Vector3>();
        int num9 = 1;
        while ((float)num9 <= num)
        {
            float num10 = (float)num9 * num6 * (1f + 0.05f * (float)num9);
            float f = (float)num9 * num8 + num2 + 1.2566371f + masterrotation.y * 0.0173f;
            float x = Mathf.Cos(f) * num10;
            float z = -Mathf.Sin(f) * num10;
            this.spiralNodes.Add(new Vector3(x, 0f, z));
            num9++;
        }
    }

19 Source : UISprite.cs
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 : UITweener.cs
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 : DV_Emitter.cs
with MIT License
from alchemz

private void CreateDataPoint(float rightAscension, float declination, Color color)
    {
        var dataPosition = new Vector3(Mathf.Sin(rightAscension * Mathf.PI * 2) * Mathf.Cos(declination * Mathf.PI), Mathf.Sin(declination * Mathf.PI), Mathf.Cos(rightAscension * Mathf.PI * 2) * Mathf.Cos(declination * Mathf.PI));
        system.Emit(new ParticleSystem.EmitParams() { position = dataPosition, startColor = color }, 1);
    }

19 Source : Graph_3D.cs
with MIT License
from alchemz

private static float Sine(Vector3 p, float t)
    {
        return 0.50f +
            0.25f * Mathf.Sin(4 * Mathf.PI * p.x + 4 * t) * Mathf.Sin(2 * Mathf.PI * p.z + t) +
            0.10f * Mathf.Cos(3 * Mathf.PI * p.x + 5 * t) * Mathf.Cos(5 * Mathf.PI * p.z + 3 * t) +
            0.15f * Mathf.Sin(Mathf.PI * p.x + 0.6f * t);
    }

19 Source : Graph_3D.cs
with MIT License
from alchemz

private static float Ripple(Vector3 p, float t)
    {
        p.x -= 0.5f;
        p.z -= 0.5f;
        float squareRadius = p.x * p.x + p.z * p.z;
        return 0.5f + Mathf.Sin(15f * Mathf.PI * squareRadius - 2f * t) / (2f + 100f * squareRadius);
    }

19 Source : connectLine.cs
with MIT License
from alchemz

void Update()
    {

        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        var t = Time.time;
        for (int i = 0; i < lengthOfLineRenderer; i++)
        {
            lineRenderer.SetPosition(i, new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f));
        }
    }

19 Source : DataSphere.cs
with MIT License
from alchemz

public void CreateDataPoint(float yaw, float pitch)
	{
		var dataPosition = new Vector3 (Mathf.Sin (yaw * Mathf.PI) * Mathf.Cos (pitch * Mathf.PI), 
			                   	Mathf.Sin (pitch * Mathf.PI),
			                        Mathf.Cos (yaw * Mathf.PI) * Mathf.Cos (pitch * Mathf.PI));
		system.Emit (new ParticleSystem.EmitParams () {
			position = dataPosition,
			startColor = new Color((1+dataPosition.x)*0.5f,(1+dataPosition.y)*0.5f,(1+dataPosition.z)*0.5f)
		}, 1);
	}

19 Source : LPJointPrismatic.cs
with MIT License
from BelkinAndrey

private void RotateTranslation()
    {
        float cos = Mathf.Cos(transform.rotation.eulerAngles.z*Mathf.Deg2Rad);
        float sin = Mathf.Sin(transform.rotation.eulerAngles.z*Mathf.Deg2Rad);

        Translation = new Vector2(
            Translation.x*cos - Translation.y*sin
            , Translation.x * sin + Translation.y * cos
            );     
    }

19 Source : LPShapeTools.cs
with MIT License
from BelkinAndrey

public static List<Vector3> makePolyPoints(int sides,float r)
	{		
		List<Vector3> PointsList = new List<Vector3>();
		if (sides < 3) 
		{
			Debug.LogError("You tried to make a polygon shape with less than 3 sides, making one with 3 instead");
			sides = 3;
		}
		if (sides > 8) 
		{
			Debug.LogError("You tried to make a polygon shape with more than 8 sides, making one with 8 instead.");
			sides = 8;
		}
		for (int i = 0; i < sides; i++)
		{
			PointsList.Add (new Vector3(r * Mathf.Cos(2 * Mathf.PI * (float)i / (float)sides), r * Mathf.Sin(2 * Mathf.PI * (float)i / (float)sides)));
    	}
    	return PointsList;
    }

19 Source : LPShapeTools.cs
with MIT License
from BelkinAndrey

public static List<Vector3> RotatePoints(List<Vector3> PointsList,float Angle,Vector3 tran)
    {
		for (int i = 0; i < PointsList.Count; i++)
		{
			PointsList[i] -= tran;
			PointsList[i] = new Vector3
				(
				 (PointsList[i].x*Mathf.Cos(Angle*Mathf.Deg2Rad)) - (PointsList[i].y*Mathf.Sin(Angle*Mathf.Deg2Rad))
				,(PointsList[i].x*Mathf.Sin(Angle*Mathf.Deg2Rad)) + (PointsList[i].y*Mathf.Cos(Angle*Mathf.Deg2Rad))
				);	
			PointsList[i] += tran;
		}
		return PointsList;
    }

19 Source : Widget.cs
with MIT License
from ByronMayne

private void FlashUpdate()
        {
            float lerpTime = m_FlashUntil - Time.realtimeSinceStartup;
            lerpTime = Mathf.Sin(lerpTime * 20f);
            lerpTime += 1f;
            lerpTime /= 2f;
            m_BackgroundColor = Color.Lerp(Color.white, m_FlashColor, lerpTime);
            m_ScriptableForge.Repaint();
            if (m_FlashUntil < Time.realtimeSinceStartup)
            {
                EditorApplication.update -= FlashUpdate;
                m_BackgroundColor = Color.white;
            }
        }

19 Source : ColorFlash.cs
with MIT License
from ByronMayne

protected override Color GetValue()
        {

            float sinLerp = Mathf.Sin(lerpPosition * 2f);
            sinLerp += 1;
            sinLerp /= 2.0f;
            return Color.Lerp(Color.white, value, sinLerp);
        }

19 Source : Functions.cs
with GNU General Public License v2.0
from CheepYT

public static Vector2 PositionFromDistance(float distance, float angle, Vector2 init)
        {
            var dist = distance;

            var x = dist * Mathf.Cos(angle / (180 / (float)Math.PI));
            var y = dist * Mathf.Sin(angle / (180 / (float)Math.PI));
            var newPosition = init;
            newPosition.x += x;
            newPosition.y += y;
            return newPosition;
        }

19 Source : UIShiny.cs
with GNU General Public License v3.0
from Cytoid

public override void ModifyMesh(VertexHelper vh)
		{
			if (!isActiveAndEnabled)
				return;

			bool isText = isTMPro || graphic is Text;
			float normalizedIndex = ptex.GetNormalizedIndex(this);

			// rect.
			Rect rect = m_EffectArea.GetEffectArea (vh, rectTransform.rect);

			// rotation.
			float rad = m_Rotation * Mathf.Deg2Rad;
			Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));
			dir.x *= rect.height / rect.width;
			dir = dir.normalized;

			// Calculate vertex position.
			UIVertex vertex = default(UIVertex);
			Vector2 nomalizedPos;
			Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y);	// Get local matrix.
			for (int i = 0; i < vh.currentVertCount; i++)
			{
				vh.PopulateUIVertex(ref vertex, i);
				m_EffectArea.GetNormalizedFactor (i, localMatrix, vertex.position, isText, out nomalizedPos);

				vertex.uv0 = new Vector2 (
					Packer.ToFloat (vertex.uv0.x, vertex.uv0.y),
					Packer.ToFloat (nomalizedPos.y, normalizedIndex)
				);

				vh.SetUIVertex(vertex, i);
			}
		}

19 Source : UIGradient.cs
with GNU General Public License v3.0
from Cytoid

public override void ModifyMesh(VertexHelper vh)
		{
			if (!IsActive())
				return;

			// Gradient space.
			Rect rect = default(Rect);
			UIVertex vertex = default(UIVertex);
			if (m_GradientStyle == GradientStyle.Rect)
			{
				// RectTransform.
				rect = graphic.rectTransform.rect;
			}
			else if (m_GradientStyle == GradientStyle.Split)
			{
				// Each characters.
				rect.Set(0, 0, 1, 1);
			}
			else if (m_GradientStyle == GradientStyle.Fit)
			{
				// Fit to contents.
				rect.xMin = rect.yMin = float.MaxValue;
				rect.xMax = rect.yMax = float.MinValue;
				for (int i = 0; i < vh.currentVertCount; i++)
				{
					vh.PopulateUIVertex(ref vertex, i);
					rect.xMin = Mathf.Min(rect.xMin, vertex.position.x);
					rect.yMin = Mathf.Min(rect.yMin, vertex.position.y);
					rect.xMax = Mathf.Max(rect.xMax, vertex.position.x);
					rect.yMax = Mathf.Max(rect.yMax, vertex.position.y);
				}
			}

			// Gradient rotation.
			float rad = rotation * Mathf.Deg2Rad;
			Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));
			if (!m_IgnoreAspectRatio && Direction.Angle <= m_Direction)
			{
				dir.x *= rect.height / rect.width;
				dir = dir.normalized;
			}

			// Calculate vertex color.
			Color color;
			Vector2 nomalizedPos;
			Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y);	// Get local matrix.
			for (int i = 0; i < vh.currentVertCount; i++)
			{
				vh.PopulateUIVertex(ref vertex, i);

				// Normalize vertex position by local matrix.
				if (m_GradientStyle == GradientStyle.Split)
				{
					// Each characters.
					nomalizedPos = localMatrix * s_SplitedCharacterPosition[i % 4] + offset2;
				}
				else
				{
					nomalizedPos = localMatrix * vertex.position + offset2;
				}

				// Interpolate vertex color.
				if (direction == Direction.Diagonal)
				{
					color = Color.LerpUnclamped(
						Color.LerpUnclamped(m_Color1, m_Color2, nomalizedPos.x),
						Color.LerpUnclamped(m_Color3, m_Color4, nomalizedPos.x),
						nomalizedPos.y);
				}
				else
				{
					color = Color.LerpUnclamped(m_Color2, m_Color1, nomalizedPos.y);
				}

				// Correct color.
				vertex.color *= (m_ColorSpace == ColorSpace.Gamma) ? color.gamma
					: (m_ColorSpace == ColorSpace.Linear) ? color.linear
					: color;

				vh.SetUIVertex(vertex, i);
			}
		}

19 Source : LeanCircuit.cs
with GNU General Public License v3.0
from Cytoid

private void AddPoint(Vector3 a, float radius, Color color)
		{
			var index = positions.Count;
			var count = 36;
			var step  = Mathf.PI * 2.0f / count;

			for (var i = 0; i < count; i++)
			{
				var angle = i * step;

				positions.Add(a + new Vector3(Mathf.Sin(angle) * radius, 0.0f, Mathf.Cos(angle) * radius));

				colors.Add(color);

				normals.Add(Vector3.up);

				coords.Add(new Vector2(0.5f, 0.5f));
			}

			for (var i = 2; i < count; i++)
			{
				indices.Add(index    );
				indices.Add(index + i - 1);
				indices.Add(index + i);
			}
		}

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseInOutElastic(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (value == 0) return start;

        if ((value /= d * 0.5f) == 2) return start + end;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p / 4;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        if (value < 1)
            return -0.5f * (a * Mathf.Pow(2, 10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) +
                   start;
        return a * Mathf.Pow(2, -10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) * 0.5f + end +
               start;
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseOutElasticD(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p * 0.25f;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        return (a * Mathf.PI * d * Mathf.Pow(2f, 1f - 10f * value) *
                Mathf.Cos((2f * Mathf.PI * (d * value - s)) / p)) / p - 5f * NATURAL_LOG_OF_2 * a *
               Mathf.Pow(2f, 1f - 10f * value) * Mathf.Sin((2f * Mathf.PI * (d * value - s)) / p);
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseInOutElasticD(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p / 4;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        if (value < 1)
        {
            value -= 1;

            return -5f * NATURAL_LOG_OF_2 * a * Mathf.Pow(2f, 10f * value) *
                   Mathf.Sin(2 * Mathf.PI * (d * value - 2f) / p) -
                   a * Mathf.PI * d * Mathf.Pow(2f, 10f * value) * Mathf.Cos(2 * Mathf.PI * (d * value - s) / p) / p;
        }

        value -= 1;

        return a * Mathf.PI * d * Mathf.Cos(2f * Mathf.PI * (d * value - s) / p) / (p * Mathf.Pow(2f, 10f * value)) -
               5f * NATURAL_LOG_OF_2 * a * Mathf.Sin(2f * Mathf.PI * (d * value - s) / p) /
               (Mathf.Pow(2f, 10f * value));
    }

19 Source : Easings.cs
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 : Easings.cs
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 : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseInSineD(float start, float end, float value)
    {
        return (end - start) * 0.5f * Mathf.PI * Mathf.Sin(0.5f * Mathf.PI * value);
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseInElastic(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (value == 0) return start;

        if ((value /= d) == 1) return start + end;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p / 4;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        return -(a * Mathf.Pow(2, 10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) + start;
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseOutElastic(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (value == 0) return start;

        if ((value /= d) == 1) return start + end;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p * 0.25f;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        return (a * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) + end + start);
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseOutSine(float start, float end, float value)
    {
        end -= start;
        return end * Mathf.Sin(value * (Mathf.PI * 0.5f)) + start;
    }

19 Source : Easings.cs
with GNU General Public License v3.0
from Cytoid

public static float EaseInElasticD(float start, float end, float value)
    {
        end -= start;

        float d = 1f;
        float p = d * .3f;
        float s;
        float a = 0;

        if (a == 0f || a < Mathf.Abs(end))
        {
            a = end;
            s = p / 4;
        }
        else
        {
            s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
        }

        float c = 2 * Mathf.PI;

        // From an online derivative calculator, kinda hoping it is right.
        return ((-a) * d * c * Mathf.Cos((c * (d * (value - 1f) - s)) / p)) / p -
               5f * NATURAL_LOG_OF_2 * a * Mathf.Sin((c * (d * (value - 1f) - s)) / p) *
               Mathf.Pow(2f, 10f * (value - 1f) + 1f);
    }

19 Source : GradientMeshEffect.cs
with GNU General Public License v3.0
from Cytoid

public static Vector2 RotationDir(float angle)
    {
        var angleRad = angle * Mathf.Deg2Rad;
        var cos = Mathf.Cos(angleRad);
        var sin = Mathf.Sin(angleRad);
        return new Vector2(cos, sin);
    }

19 Source : LineDrawer.cs
with MIT License
from dag10

protected bool Draw_Circle(Vector3 center, Vector3 normal, Color color, float radius = 0.25f, float lineWidth = DefaultLineWidth)
    {
        bool returnValue = false;
        float theta = 0;
        float radPerPoint = (2.0f * Mathf.PI) / (float)PointsOnCircle;
        Quaternion q = Quaternion.FromToRotation(Vector3.up, normal);
        Vector3 start = q * new Vector3(Mathf.Cos(theta) * radius, 0.0f, Mathf.Sin(theta) * radius) + center;

        for (int i = 1; i <= PointsOnCircle; i++)
        {
            theta = (i % PointsOnCircle) * radPerPoint;

            Vector3 end = q * new Vector3(Mathf.Cos(theta) * radius, 0.0f, Mathf.Sin(theta) * radius) + center;
            returnValue |= Draw_Line(start, end, color, color, lineWidth);

            start = end;
        }

        return returnValue;
    }

19 Source : LineDrawer.cs
with MIT License
from dag10

protected bool Draw_Circle_Partial(Vector3 center, Vector3 normal, Color color, float radius = 0.25f, float lineWidth = DefaultLineWidth, float circleAngleArc = 360.0f)
    {
        bool returnValue = false;
        float theta = 0;
        float radPerPoint = (circleAngleArc * Mathf.Deg2Rad * 0.5f) / (float)PointsOnCircle;
        Quaternion q = Quaternion.FromToRotation(Vector3.up, normal);
        Vector3 start0 = q * new Vector3(Mathf.Cos(theta) * radius, 0.0f, Mathf.Sin(theta) * radius) + center;
        Vector3 start1 = q * new Vector3(Mathf.Cos(theta) * -radius, 0.0f, Mathf.Sin(theta) * -radius) + center;

        int maxPointCount = (circleAngleArc < 360.0f) ? (PointsOnCircle - 1) : PointsOnCircle;
        for (int i = 1; i <= maxPointCount; i++)
        {
            theta = (i % PointsOnCircle) * radPerPoint;

            Vector3 end0 = q * new Vector3(Mathf.Cos(theta) * radius, 0.0f, Mathf.Sin(theta) * radius) + center;
            Vector3 end1 = q * new Vector3(Mathf.Cos(theta) * -radius, 0.0f, Mathf.Sin(theta) * -radius) + center;
            returnValue |= Draw_Line(start0, end0, color, color, lineWidth);
            returnValue |= Draw_Line(start1, end1, color, color, lineWidth);

            start0 = end0;
            start1 = end1;
        }

        return returnValue;
    }

19 Source : SteamVR_Frustum.cs
with MIT License
from dag10

public void UpdateModel()
	{
		fovLeft = Mathf.Clamp(fovLeft, 1, 89);
		fovRight = Mathf.Clamp(fovRight, 1, 89);
		fovTop = Mathf.Clamp(fovTop, 1, 89);
		fovBottom = Mathf.Clamp(fovBottom, 1, 89);
		farZ = Mathf.Max(farZ, nearZ + 0.01f);
		nearZ = Mathf.Clamp(nearZ, 0.01f, farZ - 0.01f);

		var lsin = Mathf.Sin(-fovLeft * Mathf.Deg2Rad);
		var rsin = Mathf.Sin(fovRight * Mathf.Deg2Rad);
		var tsin = Mathf.Sin(fovTop * Mathf.Deg2Rad);
		var bsin = Mathf.Sin(-fovBottom * Mathf.Deg2Rad);

		var lcos = Mathf.Cos(-fovLeft * Mathf.Deg2Rad);
		var rcos = Mathf.Cos(fovRight * Mathf.Deg2Rad);
		var tcos = Mathf.Cos(fovTop * Mathf.Deg2Rad);
		var bcos = Mathf.Cos(-fovBottom * Mathf.Deg2Rad);

		var corners = new Vector3[] {
			new Vector3(lsin * nearZ / lcos, tsin * nearZ / tcos, nearZ), //tln
			new Vector3(rsin * nearZ / rcos, tsin * nearZ / tcos, nearZ), //trn
			new Vector3(rsin * nearZ / rcos, bsin * nearZ / bcos, nearZ), //brn
			new Vector3(lsin * nearZ / lcos, bsin * nearZ / bcos, nearZ), //bln
			new Vector3(lsin * farZ  / lcos, tsin * farZ  / tcos, farZ ), //tlf
			new Vector3(rsin * farZ  / rcos, tsin * farZ  / tcos, farZ ), //trf
			new Vector3(rsin * farZ  / rcos, bsin * farZ  / bcos, farZ ), //brf
			new Vector3(lsin * farZ  / lcos, bsin * farZ  / bcos, farZ ), //blf
		};

		var triangles = new int[] {
		//	0, 1, 2, 0, 2, 3, // near
		//	0, 2, 1, 0, 3, 2, // near
		//	4, 5, 6, 4, 6, 7, // far
		//	4, 6, 5, 4, 7, 6, // far
			0, 4, 7, 0, 7, 3, // left
			0, 7, 4, 0, 3, 7, // left
			1, 5, 6, 1, 6, 2, // right
			1, 6, 5, 1, 2, 6, // right
			0, 4, 5, 0, 5, 1, // top
			0, 5, 4, 0, 1, 5, // top
			2, 3, 7, 2, 7, 6, // bottom
			2, 7, 3, 2, 6, 7, // bottom
		};

		int j = 0;
		var vertices = new Vector3[triangles.Length];
		var normals = new Vector3[triangles.Length];
		for (int i = 0; i < triangles.Length / 3; i++)
		{
			var a = corners[triangles[i * 3 + 0]];
			var b = corners[triangles[i * 3 + 1]];
			var c = corners[triangles[i * 3 + 2]];
			var n = Vector3.Cross(b - a, c - a).normalized;
			normals[i * 3 + 0] = n;
			normals[i * 3 + 1] = n;
			normals[i * 3 + 2] = n;
			vertices[i * 3 + 0] = a;
			vertices[i * 3 + 1] = b;
			vertices[i * 3 + 2] = c;
			triangles[i * 3 + 0] = j++;
			triangles[i * 3 + 1] = j++;
			triangles[i * 3 + 2] = j++;
		}

		var mesh = new Mesh();
		mesh.vertices = vertices;
		mesh.normals = normals;
		mesh.triangles = triangles;

		GetComponent<MeshFilter>().mesh = mesh;
	}

19 Source : SteamVR_Utils.cs
with MIT License
from dag10

public static Quaternion Slerp(Quaternion A, Quaternion B, float t)
	{
		var cosom = Mathf.Clamp(A.x * B.x + A.y * B.y + A.z * B.z + A.w * B.w, -1.0f, 1.0f);
		if (cosom < 0.0f)
		{
			B = new Quaternion(-B.x, -B.y, -B.z, -B.w);
			cosom = -cosom;
		}

		float sclp, sclq;
		if ((1.0f - cosom) > 0.0001f)
		{
			var omega = Mathf.Acos(cosom);
			var sinom = Mathf.Sin(omega);
			sclp = Mathf.Sin((1.0f - t) * omega) / sinom;
			sclq = Mathf.Sin(t * omega) / sinom;
		}
		else
		{
			// "from" and "to" very close, so do linear interp
			sclp = 1.0f - t;
			sclq = t;
		}

		return new Quaternion(
			sclp * A.x + sclq * B.x,
			sclp * A.y + sclq * B.y,
			sclp * A.z + sclq * B.z,
			sclp * A.w + sclq * B.w);
	}

19 Source : ObectSpawner.cs
with MIT License
from Daimler

private static float GetRandomGaussian(float mu = 0, float sigma = 1)
    {
        var u1 = Random.value;
        var u2 = Random.value;

        var rand_std_normal = Mathf.Sqrt(-2.0f * Mathf.Log(u1)) *
                            Mathf.Sin(2.0f * Mathf.PI * u2);

        var rand_normal = mu + sigma * rand_std_normal;

        return rand_normal;
    }

19 Source : FlyGraphicsHook.cs
with GNU General Public License v3.0
from Garrakx

private static void Fly_Update(On.Fly.orig_Update orig, Fly self, bool eu)
        {
            orig(self, eu);

            if (customColor == null)
            {
                return;
            }

            if (!self.dead)
            {
                FlyFields.GetField(self).flickeringFac = 1f;
                FlyFields.GetField(self).flickerDuration = Mathf.Lerp(10f, 30f, UnityEngine.Random.value);
                if (UnityEngine.Random.value < 0.1f)
                {
                    FlyFields.GetField(self).flicker = Mathf.Max(FlyFields.GetField(self).flicker, UnityEngine.Random.value);
                }
            }

            if (FlyFields.GetField(self).light != null)
            {
                if (FlyFields.GetField(self).light.slatedForDeletetion || self.room.Darkness(self.mainBodyChunk.pos) == 0f || self.dead || self.Stunned)
                {
                    FlyFields.GetField(self).light = null;
                }
                else
                {
                    FlyFields.GetField(self).sin += 1f / Mathf.Lerp(20f, 80f, UnityEngine.Random.value);
                    float sin = FlyFields.GetField(self).sin;
                    FlyFields.GetField(self).light.stayAlive = true;
                    FlyFields.GetField(self).light.setPos = new UnityEngine.Vector2?(self.bodyChunks[0].pos);
                    FlyFields.GetField(self).light.setRad = new float?(60f + 20f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
                    FlyFields.GetField(self).light.setAlpha = new float?(0.55f - 0.1f * UnityEngine.Mathf.Sin(sin * 3.14159274f * 2f));
                    // float customColorHue = customColor == null ? 0.6f : CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white).hue;
                    HSLColor color = CRExtras.RGB2HSL(customColor ?? UnityEngine.Color.white);
                    FlyFields.GetField(self).light.color = RWCustom.Custom.HSL2RGB(color.hue, color.saturation, color.lightness - 0.2f * FlyFields.GetField(self).flicker);
                }
            }
            else if (self.room.Darkness(self.bodyChunks[0].pos) > 0f && !self.dead)
            {
                Mod.CustomWorldMod.Log($"Creating light for [{self.abstractCreature.creatureTemplate}-{self.abstractPhysicalObject.ID.number}]", 
                    false, CustomWorldMod.DebugLevel.FULL);

                FlyFields.GetField(self).light = new LightSource(self.bodyChunks[0].pos, false, UnityEngine.Color.yellow, self);
                FlyFields.GetField(self).light.requireUpKeep = true;
                self.room.AddObject(FlyFields.GetField(self).light);
            }
        }

19 Source : Spinner.cs
with MIT License
from github-for-unity

public float Rotate(float currentTime)
        {
            var deltaTime = currentTime - lastTime;
            currentRotation += deltaTime * speed * ((Mathf.Sin(currentTime * 1.2f)) + 2);
            currentRotation = Mathf.Repeat(currentRotation, 360f);
            lastTime = currentTime;
            return currentRotation;
        }

19 Source : AudioHumEffect.cs
with MIT License
from GlaireDaggers

void OnAudioFilterRead(float[] data, int channels)
	{
		float increment = HumCycle * Mathf.PI / sampleRate;
		for (int i = 0; i < data.Length; i += channels)
		{
			phase += increment;

			float val = Mathf.Sin(phase);
			if (val >= 0f) val = 1f;
			else val = -1f;

			val *= HumAmount;

			float noise = (float)((rand.NextDouble() * 2.0) - 1.0);
			noise *= NoiseAmount;

			for (int c = 0; c < channels; c++)
			{
				data[i + c] += val + noise;
			}

			if (phase > 2 * Mathf.PI) phase = 0f;
		}
	}

19 Source : GeoSkylinesExport.cs
with MIT License
from gonzikcz

public void ExportZones()
        {
            if (!confloaded)
                return;

            string columns = "Id,Boundary,Zone";
            //var a_type = typeof(ZoneBlock);
            //var properties = a_type.GetProperties();
            //foreach (var prop in properties)
            //{
            //    columns += string.Format(",{0}", prop.Name);
            //}

            List<string> txtLines = new List<string>
                {
                    columns
                };

            var zm = ZoneManager.instance;
            string debugMsg = "";
            for (int i = 0; i < zm.m_blocks.m_buffer.Length; i++)
            {
                var zoneBlock = zm.m_blocks.m_buffer[i];
                var pos = zoneBlock.m_position;
                if (pos == Vector3.zero)
                    continue;

                if (!WithinExportCoords(pos))
                    continue;

                Dictionary<ItemClreplaced.Zone, ushort> zones_count = new Dictionary<ItemClreplaced.Zone, ushort>();
                //int num = (int)((zoneBlock.m_flags & 65280u) >> 8);
                for (int z = 0; z < zoneBlock.RowCount; z++)
                    for (int x = 0; x < 4; x++)
                    {
                        var zone = zoneBlock.GetZone(x, z);
                        if (!zones_count.ContainsKey(zone))
                            zones_count.Add(zone, 0);
                        zones_count[zone] += 1;
                    }

                ItemClreplaced.Zone zoneMax = ItemClreplaced.Zone.Unzoned;
                ushort zoneMax_cnt = 0;
                foreach (KeyValuePair<ItemClreplaced.Zone, ushort> a_zoneCount in zones_count)
                {
                    if (a_zoneCount.Value > zoneMax_cnt)
                    {
                        zoneMax_cnt = a_zoneCount.Value;
                        zoneMax = a_zoneCount.Key;
                    }
                }

                int width = 4;
                int length = zoneBlock.RowCount;

                Vector3 a = new Vector3(Mathf.Cos(zoneBlock.m_angle), 0f, Mathf.Sin(zoneBlock.m_angle)) * 8f;
                Vector3 a2 = new Vector3(a.z, 0f, -a.x);
                Vector3 startEndcorner = pos - (float)width * 0.5f * a - (float)length * 0.5f * a2;
                Vector3[] corners = new Vector3[]
                {
                        startEndcorner,
                        pos + (float)width * 0.5f * a - (float)length * 0.5f * a2,
                        pos + (float)width * 0.5f * a + (float)length * 0.5f * a2,
                        pos - (float)width * 0.5f * a + (float)length * 0.5f * a2,
                        startEndcorner
                };

                LatLng[] cornersLL = new LatLng[corners.Length];
                for (int j = 0; j < corners.Length; j++)
                {
                    LatLng a_cornerLL = GamePosition2LatLng(corners[j]);
                    cornersLL[j] = a_cornerLL;
                }

                var boundaryWkt = CreateWkt(cornersLL);

                string rowTxt = string.Format("{0},{1},{2}", i, boundaryWkt, zoneMax);

                txtLines.Add(rowTxt);
            }

            StreamWriter outputFile = new StreamWriter("Files/zones_cs.csv", false, new UTF8Encoding(true));
            foreach (var lineTxt in txtLines)
            {
                outputFile.WriteLine(lineTxt);
            }
            outputFile.Close();

            panel.SetMessage("GeoSkylines", "Zones export completed. ", false);

            //Debug.Log(debugMsg);
        }

19 Source : GeoSkylinesExport.cs
with MIT License
from gonzikcz

public string ExportBuilding(Building a_bldg, ref System.Reflection.PropertyInfo[] properties)
        {
            LatLng centroidLL = GamePosition2LatLng(a_bldg.m_position);

            var centroidWkt = CreateWkt(new LatLng[] { centroidLL });

            // creating a boundary (courtesy of Cimtographer)
            int width = a_bldg.Width;
            int length = a_bldg.Length;

            Vector3 a = new Vector3(Mathf.Cos(a_bldg.m_angle), 0f, Mathf.Sin(a_bldg.m_angle)) * 8f;
            Vector3 a2 = new Vector3(a.z, 0f, -a.x);
            Vector3 startEndcorner = a_bldg.m_position - (float)width * 0.5f * a - (float)length * 0.5f * a2;
            Vector3[] corners = new Vector3[]
            {
                        startEndcorner,
                        a_bldg.m_position + (float)width * 0.5f * a - (float)length * 0.5f * a2,
                        a_bldg.m_position + (float)width * 0.5f * a + (float)length * 0.5f * a2,
                        a_bldg.m_position - (float)width * 0.5f * a + (float)length * 0.5f * a2,
                        startEndcorner
            };

            LatLng[] cornersLL = new LatLng[corners.Length];
            for (int i = 0; i < corners.Length; i++)
            {
                LatLng a_cornerLL = GamePosition2LatLng(corners[i]);
                cornersLL[i] = a_cornerLL;
            }

            var boundaryWkt = CreateWkt(cornersLL);

            string rowTxt = string.Format("{0},{1},{2}", a_bldg.m_buildIndex, centroidWkt, boundaryWkt);
            foreach (var prop in properties)
            {
                var prop_val = prop.GetValue(a_bldg, null);
                if (prop_val is null)
                    continue;
                if (prop_val.ToString().Contains(","))
                    prop_val = "\"" + prop_val.ToString() + "\"";
                rowTxt += string.Format(",{0}", prop_val);
            }
            rowTxt += string.Format(",{0},{1}", a_bldg.Info.m_clreplaced.m_service, a_bldg.Info.m_clreplaced.m_subService);
            return rowTxt;
        }

19 Source : PickableSpawnerExample.cs
with GNU General Public License v3.0
from grygus

private Vector3 GetNextPosition()
    {
        var position = Vector3.zero;
        var distance = _lastSpawnDistance + _spawnDistance;
        if (distance > _maxDistance)
            distance = 0;
        _lastSpawnDistance = distance;
        switch (_eSpawner)
        {
            case ESpawnerType.Line:
                position = Vector3.forward * distance;
                break;
            case ESpawnerType.Circle:
                var ratio = distance / (_circleRadius * Mathf.PI * 2);
                var x = _circleRadius * Mathf.Cos(Mathf.PI * 2 * ratio);
                var y = _circleRadius * Mathf.Sin(Mathf.PI * 2 * ratio);
                position = new Vector3(x,0,y);
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
        return position;
    }

19 Source : GvrPostRender.cs
with MIT License
from harshitjuneja

private void DrawSettingsButton() {
    GL.PushMatrix();
    GL.LoadOrtho();
    GL.MultMatrix(xfm);
    GL.Begin(GL.TRIANGLE_STRIP);
    for (int i = 0, n = Angles.Length * 6; i <= n; i++) {
      float theta = (i / Angles.Length) * kAnglePerGearSection + Angles[i % Angles.Length];
      float angle = (90 - theta) * Mathf.Deg2Rad;
      float x = Mathf.Cos(angle);
      float y = Mathf.Sin(angle);
      float mod = Mathf.PingPong(theta, kAnglePerGearSection / 2);
      float lerp = (mod - kOuterRimEndAngle) / (kInnerRimBeginAngle - kOuterRimEndAngle);
      float r = Mathf.Lerp(kOuterRadius, kMiddleRadius, lerp);
      GL.Vertex3(kInnerRadius * x, kInnerRadius * y, 0);
      GL.Vertex3(r * x, r * y, 0);
    }
    GL.End();
    GL.PopMatrix();
  }

19 Source : GvrAudio.cs
with MIT License
from harshitjuneja

public static Vector2[] Generate2dPolarPattern (float alpha, float order, int resolution) {
    Vector2[] points = new Vector2[resolution];
    float interval = 2.0f * Mathf.PI / resolution;
    for (int i = 0; i < resolution; ++i) {
      float theta = i * interval;
      // Magnitude |r| for |theta| in radians.
      float r = Mathf.Pow(Mathf.Abs((1 - alpha) + alpha * Mathf.Cos(theta)), order);
      points[i] = new Vector2(r * Mathf.Sin(theta), r * Mathf.Cos(theta));
    }
    return points;
  }

19 Source : GvrReticlePointer.cs
with MIT License
from harshitjuneja

private void CreateReticleVertices() {
    Mesh mesh = new Mesh();
    gameObject.AddComponent<MeshFilter>();
    GetComponent<MeshFilter>().mesh = mesh;

    int segments_count = reticleSegments;
    int vertex_count = (segments_count+1)*2;

    #region Vertices

    Vector3[] vertices = new Vector3[vertex_count];

    const float kTwoPi = Mathf.PI * 2.0f;
    int vi = 0;
    for (int si = 0; si <= segments_count; ++si) {
      // Add two vertices for every circle segment: one at the beginning of the
      // prism, and one at the end of the prism.
      float angle = (float)si / (float)(segments_count) * kTwoPi;

      float x = Mathf.Sin(angle);
      float y = Mathf.Cos(angle);

      vertices[vi++] = new Vector3(x, y, 0.0f); // Outer vertex.
      vertices[vi++] = new Vector3(x, y, 1.0f); // Inner vertex.
    }
    #endregion

    #region Triangles
    int indices_count = (segments_count+1)*3*2;
    int[] indices = new int[indices_count];

    int vert = 0;
    int idx = 0;
    for (int si = 0; si < segments_count; ++si) {
      indices[idx++] = vert+1;
      indices[idx++] = vert;
      indices[idx++] = vert+2;

      indices[idx++] = vert+1;
      indices[idx++] = vert+2;
      indices[idx++] = vert+3;

      vert += 2;
    }
    #endregion

    mesh.vertices = vertices;
    mesh.triangles = indices;
    mesh.RecalculateBounds();
#if !UNITY_5_5_OR_NEWER
    // Optimize() is deprecated as of Unity 5.5.0p1.
    mesh.Optimize();
#endif  // !UNITY_5_5_OR_NEWER
  }

19 Source : EnemyBattonBoneScript.cs
with MIT License
from HDNua

protected override void Update()
    {
        base.Update();

        // 사용할 변수를 선언합니다.
        Vector2 relativePos = _StageManager.GetCurrentPlayerPosition() - transform.position;
        float angle = Mathf.Atan2(relativePos.y, relativePos.x);
        float distortion = UnityEngine.Random.Range(_amp_min, _amp_max)
            * Mathf.Sin(_ang_freq * _time);

        // 개체의 속도를 변경합니다.
        float vx = _movingSpeed * Mathf.Cos(angle);
        float vy = _movingSpeed * Mathf.Sin(angle) + distortion;
        _rigidbody.velocity = new Vector2(vx, vy);

        // 플레이어를 쫓아갑니다.
        if (relativePos.x < 0 && FacingRight)
            Flip();
        else if (relativePos.x > 0 && !FacingRight)
            Flip();

        // 업데이트의 끝입니다.
        _time += Time.deltaTime;
    }

19 Source : EnemyBossScript.cs
with MIT License
from HDNua

bool UpdateLanding()
    {
        RaycastHit2D rayB = Physics2D.Raycast(groundCheckBack.position, Vector2.down, groundCheckRadius, _whatIsGround);
        RaycastHit2D rayF = Physics2D.Raycast(groundCheckFront.position, Vector2.down, groundCheckRadius, _whatIsGround);

        Debug.DrawRay(groundCheckBack.position, Vector2.down, Color.red);
        Debug.DrawRay(groundCheckFront.position, Vector2.down, Color.red);

        if (Handy.DebugPoint) // PlayerController.UpdateLanding
        {
            Handy.Log("PlayerController.UpdateLanding");
        }

        if (OnGround())
        {
            // 절차:
            // 1. 캐릭터에서 수직으로 내린 직선에 맞는 경사면의 법선 벡터를 구한다.
            // 2. 법선 벡터와 이동 방향 벡터가 이루는 각도가 예각이면 내려오는 것
            //    법선 벡터와 이동 방향 벡터가 이루는 각도가 둔각이면 올라가는 것
            /// Handy.Log("OnGround()");
            
            // 앞 부분 Ray와 뒤 부분 Ray의 경사각이 다른 경우
            if (rayB.normal.normalized != rayF.normal.normalized)
            {
                bool isTouchingSlopeFromB = rayB.normal.x == 0;
                /// Transform pos = isTouchingSlopeFromB ? groundCheckBack : groundCheckFront;
                RaycastHit2D ray = isTouchingSlopeFromB ? rayB : rayF;

                Vector2 from = FacingRight ? Vector2.right : Vector2.left;
                float rayAngle = Vector2.Angle(from, ray.normal);
                float rayAngleRad = Mathf.Deg2Rad * rayAngle;

                float sx = _movingSpeed * Mathf.Cos(rayAngleRad);
                float sy = _movingSpeed * Mathf.Sin(rayAngleRad);
                float vx = FacingRight ? sx : -sx;

                if (Jumping || Flying)
                {
                }
                // 예각이라면 내려갑니다.
                else if (rayAngle < 90)
                {
                    float vy = -sy;
                    _Velocity = new Vector2(vx, vy);
                }
                // 둔각이라면 올라갑니다.
                else if (rayAngle > 90)
                {
                    float vy = sy;
                    _Velocity = new Vector2(vx, vy);
                }
                // 90도라면
                else
                {
                }
            }
            else
            {
            }

            Landed = true;
        }
        else if (rayB || rayF)
        {
            // 가장 가까운 거리에 적중한 Ray를 탐색합니다.
            RaycastHit2D ray;
            if (rayB && !rayF)
            {
                ray = rayB;
            }
            else if (!rayB && rayF)
            {
                ray = rayF;
            }
            else
            {
                ray = rayB.distance < rayF.distance ? rayB : rayF;
            }

            /// Vector3 pos = transform.position;
            /// pos.y -= difY;
            
            // 지형과 Y 좌표의 차이가 작으면 추락을 중지합니다.
            float difY = ray.distance / transform.localScale.y;
            if (Mathf.Abs(difY) < _jumpDecSize)
            {
                // transform.position = pos;
                float vy = _Velocity.y > 0 ? _Velocity.y : 0;
                _Velocity = new Vector2(_Velocity.x, vy);
                Landed = true;
            }
            else
            {
                Landed = false;
            }
        }
        else if (Jumping || Falling || Flying)
        {
            Landed = false;
        }
        else
        {
            Landed = false;
        }
        return Landed;
    }

19 Source : SineWaveExample.cs
with MIT License
from Interactml

public float CreateSine(int timeIndex, float frequency, float sampleRate)
    {
        return Mathf.Sin(2 * Mathf.PI * timeIndex * frequency / sampleRate);
    }

19 Source : Engine.cs
with MIT License
from iperov

void m_Camera_setView ( CameraView cv )
    {
        switch ( cv )
        {
            case CameraView.view1:
            {
                float V_fov = m_Camera.fieldOfView;
                float target_camera_bottom_Y = -(float)m_WheelModel.rim_d;// - 0.20f;
                float V_dist = Mathf.Tan ( V_fov*Mathf.Deg2Rad / 2.0f ) * target_camera_bottom_Y;
                float cam_angle = -45 * Mathf.Deg2Rad;

                m_Camera.transform.position =
                m_WheelModel.get_hub_pos().toVector3() - new Vector3( Mathf.Cos( cam_angle ) * (float) m_WheelModel.rim_d / 2, -Mathf.Sin( cam_angle ) * (float) m_WheelModel.rim_d / 2, 0 )
                    + new Vector3( 0, 0, 0.05f );

                m_Camera.transform.rotation = Quaternion.Euler( 45 / 2, 90, 0 );
                break;
            }

            case CameraView.view2:
            {
                m_Camera.transform.position =
               m_WheelModel.get_hub_pos().toVector3() + new Vector3( -0.040f, -(float) m_WheelModel.rim_d / 2 - m_rim_profile_height * 1.5f, m_rim_profile_width );

                m_Camera.transform.rotation = Quaternion.Euler( 0, 90, 0 );
                break;
            }
        }

    }

19 Source : BlendShapes.cs
with MIT License
from IxxyXR

void Update()
    {
        if (!initialized) Rebuild();
        for (var i = 0; i < Morphs.Count; i++)
        {
            var item = Morphs[i];
            var x = Time.time * item.frequency;
            //var val = Mathf.SmoothStep(-0.5f, 0.5f, Mathf.Sin(x)) * 2 - 1;
            //var val = Mathf.Pow(Mathf.Abs(Mathf.Cos(x)), 1f / 2f) * Mathf.Sign(Mathf.Cos(x));
            //var val = 1 - Mathf.Pow(25, -1 * Mathf.Sin(x)) / 25f;
            var val = (Mathf.Sin(x) + 1f) / 2f;
            // var val = Mathf.PerlinNoise(x, i * .5f);
            // var val = blends[i];
            var blendFrame = i + 1;  // The first frame is the same as the base mesh
            
            polymorphSkinnedMeshRenderer.SetBlendShapeWeight(blendFrame, Mathf.Lerp(0, 100, val));
        }
    }

See More Examples