Evaluate() private method

private Evaluate ( float time ) : float
time float
return float
コード例 #1
0
ファイル: ZTools.cs プロジェクト: Zulban/viroid
    public static float evaluateProbabilityCurve(AnimationCurve curve, int sliceCount)
    {
        /*
        allows you to use animationCurves as probability curves.

        uses domain 0-1
        any range

        slices the domain into sliceCount pieces. the odds of returning the x value from a slice
        is linearly proportional to the y value on the curve
        */
        float total = 0;
        float stepSize = 1 / (float)sliceCount;
        for (float x=0; x<=1; x+=stepSize) {
            total += curve.Evaluate (x);
        }

        float rand = ((float)Random.Range (0, total * 1000)) / 1000;
        for (float x=0; x<=1; x+=stepSize) {
            float y = curve.Evaluate (x);
            if (y > 0)
                rand -= y;

            if (rand < 0)
                return x;
        }

        Debug.Log ("warning: evaluateProbabilityCurve never evaluated. returning 1");
        return 1f;
    }
コード例 #2
0
	IEnumerator StoneMove(AnimationCurve curve, float delay = 0 )
	{
		if (ismoving)
			yield break;
		ismoving = true;
		float timer = 0;
		Vector3 stoneOriPosition = stone.transform.position;
		Vector3 shadowOriPosition = shadow.transform.position;
		while(true)
		{
			if (timer > delay)
			{
				stone.transform.position = stoneOriPosition + new Vector3(0,curve.Evaluate((timer-delay)/(glowTime + glowDuration)),0);
				shadow.transform.position = shadowOriPosition - new Vector3(0,curve.Evaluate((timer-delay)/(glowTime + glowDuration)),0);
			}

			if (timer > glowTime + glowDuration + delay)
				break;

			timer += Time.deltaTime;
			yield return null;
		}
		ismoving = false;
		yield break;

	}
コード例 #3
0
    /*! \cond PRIVATE */

    /*! @name Internal Public
     *  Don't use them unless you know what you're doing!
     */
    //@{

    void getEvaluatedValues(float percent, ref float radius, ref float zz)
    {
        switch (RadiusModifier)
        {
        case ModifierMode.Absolute:
            radius = RadiusModifierCurve.Evaluate(percent);
            break;

        case ModifierMode.Relative:
            radius = Radius * RadiusModifierCurve.Evaluate(percent);
            break;

        default:
            radius = Radius;
            break;
        }

        switch (ZModifier)
        {
        case ModifierMode.Absolute:
            zz = ZModifierCurve.Evaluate(percent);
            break;

        case ModifierMode.Relative:
            zz = Z * ZModifierCurve.Evaluate(percent);
            break;

        default:
            zz = Z;
            break;
        }
    }
コード例 #4
0
ファイル: CurveCollider2D.cs プロジェクト: Boxxxx/clicker
 Vector2[] GetSamplePoints(AnimationCurve curve, Vector2 offset) {
     if (curve.length == 0) {
         return new Vector2[] { offset, offset };
     }
     else {
         var ret = new List<Vector2>();
         float maxTime = GetMaxTime(curve);
         for (var t = 0f; t < maxTime; t += sampleInterval) {
             ret.Add(new Vector2(t, curve.Evaluate(t)) + offset);
         }
         ret.Add(new Vector2(maxTime, curve.Evaluate(maxTime)) + offset);
         return ret.ToArray();
     }
 }
コード例 #5
0
	public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
		AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);

		int width = heightMap.GetLength (0);
		int height = heightMap.GetLength (1);
		float topLeftX = (width - 1) / -2f;
		float topLeftZ = (height - 1) / 2f;

		int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;
		int verticesPerLine = (width - 1) / meshSimplificationIncrement + 1;

		MeshData meshData = new MeshData (verticesPerLine, verticesPerLine);
		int vertexIndex = 0;

		for (int y = 0; y < height; y += meshSimplificationIncrement) {
			for (int x = 0; x < width; x += meshSimplificationIncrement) {
				meshData.vertices [vertexIndex] = new Vector3 (topLeftX + x, heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier, topLeftZ - y);
				meshData.uvs [vertexIndex] = new Vector2 (x / (float)width, y / (float)height);

				if (x < width - 1 && y < height - 1) {
					meshData.AddTriangle (vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
					meshData.AddTriangle (vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
				}

				vertexIndex++;
			}
		}

		return meshData;

	}
コード例 #6
0
    void Start()
    {
        _texture = new Texture2D(Width, Height, TextureFormat.ARGB32, false);
        _texture.Apply(false, false);

        if (_movieCapture)
        {
            _movieCapture.SetSourceTexture(_texture);
        }

        _pixels = new Color32[Width*Height];
        _palette = new Color32[PaletteSize];

        Keyframe[] keysR = { new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(1f, 0f) };
        Keyframe[] keysG = { new Keyframe(0f, 1f), new Keyframe(0.5f, 0f), new Keyframe(1f, 1f) };
        Keyframe[] keysB = { new Keyframe(0f, 1f), new Keyframe(0.75f, 0f), new Keyframe(1f, 0f) };
        AnimationCurve curveR = new AnimationCurve(keysR);
        AnimationCurve curveG = new AnimationCurve(keysG);
        AnimationCurve curveB = new AnimationCurve(keysB);
        for (int i = 0; i < PaletteSize; i++)
        {
            float r = curveR.Evaluate((float)i / (float)PaletteSize);
            float g = curveG.Evaluate((float)i / (float)PaletteSize);
            float b = curveB.Evaluate((float)i / (float)PaletteSize);
            _palette[i] = new Color32((byte)(r * 255.0f), (byte)(g * 255.0f), (byte)(b * 255.0f), (byte)(b * 255.0f));
        }
    }
コード例 #7
0
	public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
		AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);

		int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;

		int borderedSize = heightMap.GetLength (0);
		int meshSize = borderedSize - 2*meshSimplificationIncrement;
		int meshSizeUnsimplified = borderedSize - 2;

		float topLeftX = (meshSizeUnsimplified - 1) / -2f;
		float topLeftZ = (meshSizeUnsimplified - 1) / 2f;


		int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;

		MeshData meshData = new MeshData (verticesPerLine);

		int[,] vertexIndicesMap = new int[borderedSize,borderedSize];
		int meshVertexIndex = 0;
		int borderVertexIndex = -1;

		for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
			for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
				bool isBorderVertex = y == 0 || y == borderedSize - 1 || x == 0 || x == borderedSize - 1;

				if (isBorderVertex) {
					vertexIndicesMap [x, y] = borderVertexIndex;
					borderVertexIndex--;
				} else {
					vertexIndicesMap [x, y] = meshVertexIndex;
					meshVertexIndex++;
				}
			}
		}

		for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
			for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
				int vertexIndex = vertexIndicesMap [x, y];
				Vector2 percent = new Vector2 ((x-meshSimplificationIncrement) / (float)meshSize, (y-meshSimplificationIncrement) / (float)meshSize);
				float height = heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier;
				Vector3 vertexPosition = new Vector3 (topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);

				meshData.AddVertex (vertexPosition, percent, vertexIndex);

				if (x < borderedSize - 1 && y < borderedSize - 1) {
					int a = vertexIndicesMap [x, y];
					int b = vertexIndicesMap [x + meshSimplificationIncrement, y];
					int c = vertexIndicesMap [x, y + meshSimplificationIncrement];
					int d = vertexIndicesMap [x + meshSimplificationIncrement, y + meshSimplificationIncrement];
					meshData.AddTriangle (a,d,c);
					meshData.AddTriangle (d,a,b);
				}

				vertexIndex++;
			}
		}

		return meshData;

	}
コード例 #8
0
        public static IEnumerator CurveDissolve(Material mat, AnimationCurve dissolveCurve, float time, float curveStartPercentage, float speed)
        {
            float elapsedTime = curveStartPercentage;

            while (elapsedTime <= 1f && elapsedTime >= 0f) {
                if (mat.HasProperty(dissolveAmountID)) {
                    mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(elapsedTime)));
                }
                elapsedTime += Time.deltaTime/time * speed;
                yield return null;
            }

            if (mat.HasProperty(dissolveAmountID)) {
                mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(Mathf.Clamp01(elapsedTime))));
            }
        }
コード例 #9
0
ファイル: BezierCurve.cs プロジェクト: Rarau/racing_game
    /// <summary>
    /// Helper function to generate the profile shape to be extruded according to the given curve and parameters.
    /// </summary>
    /// <param name="profile"></param>
    /// <param name="numDivsProfile"></param>
    /// <param name="width"></param>
    /// <param name="verticalScale"></param>
    /// <param name="profileShape"></param>
    public static void GenerateProfileShape(AnimationCurve profile, int numDivsProfile, float width, float verticalScale, Shape profileShape, bool collider = false)
    {
        Vector2[] points = new Vector2[numDivsProfile + 1];
        float[] uCoords = new float[numDivsProfile + 1];
        Vector2[] normals = new Vector2[numDivsProfile + 1];

        for(int i = 0; i < numDivsProfile + 1; ++i)
        {
            points[i].x = (float)i * (width / numDivsProfile);
            points[i].y = -profile.Evaluate(1.0f - Mathf.InverseLerp(0.0f, width, points[i].x)) * verticalScale;

            normals[i].x = 0.0f;
            normals[i].y = 1.0f;

            uCoords[i] = Mathf.InverseLerp(0.0f, width, points[i].x);
            points[i].x -= width * 0.5f;

        }

        int[] lines = new int[points.Length * 2 - 2];
        int k = 0;
        for (int i = 0; i < points.Length - 1; i++)
        {
            lines[k] = i;
            lines[k + 1] = i + 1;
            k += 2;
        }

        profileShape.points = points;
        profileShape.normals = normals;
        profileShape.uCoords = uCoords;
        profileShape.lines = lines;
    }
コード例 #10
0
    UnityEngine.Vector3 getScale(float tf)
    {
        switch (ScaleModifier)
        {
        case MeshScaleModifier.ControlPoint:
            return(Spline.InterpolateScale(tf));

        case MeshScaleModifier.UserValue:
            return(Spline.InterpolateUserValue(tf, ScaleModifierUserValueSlot));

        case MeshScaleModifier.Delegate:
            return((OnGetScale != null) ? OnGetScale(this, tf) : UnityEngine.Vector3.one);

        case MeshScaleModifier.AnimationCurve:
            UnityEngine.Vector3 v = UnityEngine.Vector3.one;
            if (ScaleModifierCurve != null)
            {
                return(v * ScaleModifierCurve.Evaluate(tf));
            }
            else
            {
                return(v);
            }

        default:
            return(UnityEngine.Vector3.one);
        }
    }
コード例 #11
0
 static public int Evaluate(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l);
         System.Single a1;
         checkType(l, 2, out a1);
         var ret = self.Evaluate(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #12
0
 public float GetValueFromCurveAtPosition(AnimationCurve curve, float xPosition)
 {
     float xPos = xPosition + seed;
     xPos = xPos % curve[curve.length - 1].time;
     var result = curve.Evaluate(xPos);
     result += Random.Range(-worldJitterAmount, worldJitterAmount);
     result = Mathf.Clamp01(result);
     return result;
 }
コード例 #13
0
ファイル: InterstageFadeUI.cs プロジェクト: aviktorov/ld33
    private IEnumerator DoAnimate(AnimationCurve curve)
    {
        var image = GetComponentInChildren<Image>();
        var duration = curve[curve.length - 1].time;

        for (var t = 0f; t <= duration; t += Mathf.Max(0.001f, Time.deltaTime)) {
            image.color = image.color.WithA(curve.Evaluate(t));
            yield return null;
        }
    }
コード例 #14
0
ファイル: InterstageFade.cs プロジェクト: almyu/ld33
    private IEnumerator DoAnimate(AnimationCurve curve)
    {
        var renderer = GetComponent<SpriteRenderer>();
        var duration = curve[curve.length - 1].time;

        for (var t = 0f; t <= duration; t += Mathf.Max(0.001f, Time.deltaTime)) {
            renderer.color = renderer.color.WithA(curve.Evaluate(t));
            yield return null;
        }
    }
コード例 #15
0
 public static PositionRotation Interpolate(PositionRotation start, PositionRotation end, float progress, AnimationCurve curve)
 {
     var diff = (end.Position - start.Position);
     var curveProgress = curve.Evaluate(progress);
     var pos = new Vector3(
             start.Position.x + diff.x * curveProgress,
             start.Position.y + diff.y * curveProgress,
             start.Position.z + diff.z * curveProgress
             );
     var rot = Quaternion.RotateTowards(start.Rotation, end.Rotation, Quaternion.Angle(start.Rotation, end.Rotation) * curveProgress);
     return new PositionRotation(pos, rot);
 }
コード例 #16
0
ファイル: FlyingCoin.cs プロジェクト: minh3d/Fish
 IEnumerator _Coro_FlyProcess(AnimationCurve scaleCurve, float useTime, Vector3 flyLocalDirect)
 {
     float curTime = 0F;
     while (curTime < useTime)
     {
         transform.localPosition += flyLocalDirect * FlySpeed * Time.deltaTime;
         curTime += Time.deltaTime;
         float scale = scaleCurve.Evaluate(curTime / useTime);
         transform.localScale = new Vector3(scale, scale, 1F);
         yield return 0;
     }
 }
コード例 #17
0
ファイル: DamageText.cs プロジェクト: Kundara/project1
		IEnumerator Move(Vector3 pos1, Vector3 pos2, AnimationCurve ac, float time) {
			float timer = 0.0f;
			pos2 += Random.insideUnitSphere * scatter;

			while (timer <= time) {
				transform.position = Vector3.Lerp (pos1, pos2, ac.Evaluate(timer/time));
				timer += Time.deltaTime;
				yield return null;
			}


		}
コード例 #18
0
ファイル: NgAtlas.cs プロジェクト: seonwifi/bongbong
 public static Color[] ConvertAlphaTexture(Color[] srcColors, bool bEnableAlphaChannel, AnimationCurve curveAlphaWeight, float redWeight, float greenWeight, float blueWeight)
 {
     for (int c = 0; c < srcColors.Length; c++)
     {
         if (bEnableAlphaChannel)
         {
             if (curveAlphaWeight != null)
                 srcColors[c].a = curveAlphaWeight.Evaluate(srcColors[c].grayscale);
             else srcColors[c].a = srcColors[c].grayscale;
         } else srcColors[c].a = 1;
     }
     return srcColors;
 }
コード例 #19
0
		/// <summary>
		/// uses an AnimationCurve for easing. the curve should have a start time of 0. The end time can be anything since
		/// it will be scaled but it is usually easiest to just use the 0 - 1 time range.
		/// </summary>
		/// <returns>The curve ease.</returns>
		/// <param name="curve">Curve.</param>
		public static Func<float,float,float> AnimationCurveEase( AnimationCurve curve )
		{
			// we need the curves totaly duration so we can scale it to the actual tweens duration
			var curveDuration = curve.keys[curve.length - 1].time;

			Func<float,float,float> func = ( t, d ) =>
			{
				var timeScaler = curveDuration / d;
				return curve.Evaluate( timeScaler * t );
			};

			return func;
		}
コード例 #20
0
 static public int Evaluate(IntPtr l)
 {
     try {
         UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l);
         System.Single a1;
         checkType(l, 2, out a1);
         var ret = self.Evaluate(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #21
0
ファイル: SpringManager.cs プロジェクト: maruton/Sample_Fade
		private void UpdateParameter (string fieldName, float baseValue, AnimationCurve curve)
		{
			var start = curve.keys [0].time;
			var end = curve.keys [curve.length - 1].time;
			//var step	= (end - start) / (springBones.Length - 1);
		
			var prop = springBones [0].GetType ().GetField (fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
		
			for (int i = 0; i < springBones.Length; i++) {
				//Kobayashi
				if (!springBones [i].isUseEachBoneForceSettings) {
					var scale = curve.Evaluate (start + (end - start) * i / (springBones.Length - 1));
					prop.SetValue (springBones [i], baseValue * scale);
				}
			}
		}
コード例 #22
0
 static int Evaluate(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve));
         float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
         float o    = obj.Evaluate(arg0);
         LuaDLL.lua_pushnumber(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #23
0
    public Vector3 GetValueByTimeRatio(float ratio)
    {
        switch (type)
        {
        case FlexibleEditType.Uniform:
            return(uniformValue);

        case FlexibleEditType.RangeTween:
            return(new Vector3(rangeX.Evaluate(ratio), rangeY.Evaluate(ratio), rangeZ.Evaluate(ratio)));

        case FlexibleEditType.RangeRandom:
            return(new Vector3(rangeX.random, rangeY.random, rangeZ.random));

        case FlexibleEditType.Curve:
            return(new Vector3(curveX.Evaluate(ratio), curveY.Evaluate(ratio), curveZ.Evaluate(ratio)));
        }
        return(uniformValue);
    }
コード例 #24
0
        /// <summary>
        /// 高さマップを生成する
        /// </summary>
        /// <param name="gen">生成したリアプノフ</param>
        /// <param name="curve">色曲線</param>
        /// <returns>高さマップ</returns>
        public static Texture2D CreateHeightMap(LyapunovGenerator gen, AnimationCurve curve)
        {
            Texture2D tex = new Texture2D((int)gen.XLength, (int)gen.YLength);
            float diff = 1f / (gen.MaxValue - gen.MinValue);
            Color[] color = new Color[gen.XLength * gen.YLength];

            for (int i = 0; i < (int)gen.XLength; i++)
            {
                for (int j = 0; j < (int)gen.YLength; j++)
                {
                    float val = curve.Evaluate(gen.Result[i, j] * diff);
                    color[i * gen.XLength + j] = new Color(val, val, val, 1);
                }
            }
            tex.SetPixels(color);
            tex.Apply();
            return tex;
        }
コード例 #25
0
    public override void Spawn()
    {
        base.Spawn();

        _renderer.sprite = Sprites[Random.Range(0, Sprites.Length)];
        RecalculateSizeBySprite();

        _collider.size = Size;

        HP = Size.magnitude;

        _currentMovementPattern = XMovements[Random.Range(0, XMovements.Length)];
        _eval = Random.Range(0, _currentMovementPattern.keys[_currentMovementPattern.length-1].time);
        transform.position = new Vector3(_currentMovementPattern.Evaluate(_eval) * CameraController.Bounds.x * 0.66f, transform.position.y, transform.position.z);

        nextShot = Time.time + FireRate * 2;
        _targetHeight = Random.Range(NormalHeight.x, NormalHeight.y) * CameraController.Bounds.y;
    }
コード例 #26
0
    private IEnumerator FadeToGoal(float goal, float seconds = 0.25f, AnimationCurve filter = null)
    {
        float startValue = m_audioLoop.volume;
        float diff = goal - startValue;
        float startTime = Time.time;
        float percent = 0.0f; // What percentage of the way through the fade are we.

        while(percent < 1.0f) {
          percent = Mathf.Clamp01((Time.time - startTime) / seconds);
          float filtered = percent;
          if ( filter != null ) { filtered = filter.Evaluate(filtered); }
          float newVolume = startValue + (filtered * diff);
          m_audioLoop.volume = newVolume;
          yield return 0;
        }

        yield break;
    }
コード例 #27
0
    IEnumerator _Shake(AnimationCurve curve)
    {
        Vector3 startPos = transform.position;

        float duration = curve.lastTime();

        yield return StartCoroutine(pTween.RealtimeTo(duration, 0f, duration, t =>
        {
            float magnitude = (curve.Evaluate(t) / 360f) * Camera.main.orthographicSize;

            Vector3 randPos = new Vector3(Random.Range(-magnitude, magnitude), 0, Random.Range(-magnitude, magnitude));

            transform.position = startPos + randPos;

            t += shakeStayTime / Time.timeScale;
        }));

        transform.position = startPos;
    }
コード例 #28
0
        public void TestStepAnimationCurveNode(float time)
        {
            var animCurve = new UnityEngine.AnimationCurve();

            animCurve.AddKey(new UnityEngine.Keyframe(0, 0, Mathf.Infinity, Mathf.Infinity));
            animCurve.AddKey(new UnityEngine.Keyframe(0.5f, 1, Mathf.Infinity, Mathf.Infinity));
            animCurve.AddKey(new UnityEngine.Keyframe(1, 1, Mathf.Infinity, Mathf.Infinity));
            var expected = animCurve.Evaluate(time);

            var dotsCurve = animCurve.ToDotsAnimationCurve();

            var curveNode = CreateNode <EvaluateCurveNode>();

            Set.SendMessage(curveNode, EvaluateCurveNode.SimulationPorts.AnimationCurve, dotsCurve);
            Set.SetData(curveNode, EvaluateCurveNode.KernelPorts.Time, time);

            var output = CreateGraphValue(curveNode, EvaluateCurveNode.KernelPorts.Output);

            Set.Update(default);
コード例 #29
0
ファイル: LeanAudio.cs プロジェクト: minhdu/mmo-client
	private static float[] createAudioWave( AnimationCurve volume, AnimationCurve frequency, LeanAudioOptions options ){
		float time = volume[ volume.length - 1 ].time;
		List<float> list = new List<float>();
		generatedWaveDistances = new List<float>();
		// float[] vibratoValues = new float[ vibrato.Length ];
		float passed = 0f;
		for(int i = 0; i < PROCESSING_ITERATIONS_MAX; i++){
			float f = frequency.Evaluate(passed);
			if(f<MIN_FREQEUNCY_PERIOD)
				f = MIN_FREQEUNCY_PERIOD;
			float height = volume.Evaluate(passed + 0.5f*f);
			if(options.vibrato!=null){
				for(int j=0; j<options.vibrato.Length; j++){
					float peakMulti = Mathf.Abs( Mathf.Sin( 1.5708f + passed * (1f/options.vibrato[j][0]) * Mathf.PI ) );
					float diff = (1f-options.vibrato[j][1]);
					peakMulti = options.vibrato[j][1] + diff*peakMulti;
					height *= peakMulti;
				}	
			}
			// Debug.Log("i:"+i+" f:"+f+" passed:"+passed+" height:"+height+" time:"+time);
			if(passed + 0.5f*f>=time)
				break;

			generatedWaveDistances.Add( f );
			passed += f;

			list.Add( passed );
			list.Add( i%2==0 ? -height : height );
			if(i>=PROCESSING_ITERATIONS_MAX-1){
				Debug.LogError("LeanAudio has reached it's processing cap. To avoid this error increase the number of iterations ex: LeanAudio.PROCESSING_ITERATIONS_MAX = "+(PROCESSING_ITERATIONS_MAX*2));
			}
		}

		float[] wave = new float[ list.Count ];
		for(int i = 0; i < wave.Length; i++){
			wave[i] = list[i];
		}
		return wave;
	}
コード例 #30
0
    public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail)
    {
        AnimationCurve heightCurve = new AnimationCurve(_heightCurve.keys);

        int width = heightMap.GetLength(0);
        int height = heightMap.GetLength(1);
        float topLeftX = (width - 1) / -2f;
        float topLeftZ = (height - 1) / 2f;

        int meshSimplificationIncrement = levelOfDetail==0 ? 1 : levelOfDetail * 2; //Pour n'afficher qu'un certain nombre de vertices
        int verticesPerLine = (width - 1) / meshSimplificationIncrement + 1;

        MeshData meshData = new MeshData(verticesPerLine, verticesPerLine);
        int vertexIndex = 0;

        for(int y=0;y<height;y+= meshSimplificationIncrement)
        {
            for(int x=0;x<width;x+= meshSimplificationIncrement)
            {
                meshData.vertices[vertexIndex] = new Vector3(topLeftX + x, heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier - heightMultiplier*0.01f, topLeftZ - y);
                meshData.uvs[vertexIndex] = new Vector2(x / (float)width, y/(float)height);

                if(x<width-1 && y < height-1)
                {
                    //On ajoute 2 triangles de façon a créer une face carrée
                    // /!\ Sens Indirect
                    meshData.AddTriangle(vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
                    meshData.AddTriangle(vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);

                }

                vertexIndex++;
            }
        }

        return meshData;

    }
コード例 #31
0
ファイル: LeanAudio.cs プロジェクト: 4026/worldgen
    public static AudioClip generateAudioFromCurve( AnimationCurve curve, int frequencyRate = 44100 )
    {
        float curveTime = curve[ curve.length - 1 ].time;
        float time = curveTime;
        float[] audioArr = new float[ (int)(frequencyRate*time) ];

        // Debug.Log("curveTime:"+curveTime+" AudioSettings.outputSampleRate:"+AudioSettings.outputSampleRate);
        for(int i = 0; i < audioArr.Length; i++){
            float pt = (float)i / (float)frequencyRate;
            audioArr[i] = curve.Evaluate( pt );
            // Debug.Log("pt:"+pt+" i:"+i+" val:"+audioArr[i]+" len:"+audioArr.Length);
        }

        int lengthSamples = audioArr.Length;//(int)( (float)frequencyRate * curveTime );
        #if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
        bool is3dSound = false;
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, is3dSound, false);
        #else
        AudioClip audioClip = AudioClip.Create("Generated Audio", lengthSamples, 1, frequencyRate, false);
        #endif
        audioClip.SetData(audioArr, 0);

        return audioClip;
    }
コード例 #32
0
ファイル: AdvGame.cs プロジェクト: mcbodge/eidolon
        /**
         * <summary>Interpolates a float over time, according to various interpolation methods.</summary>
         * <param name = "startT">The starting time</param>
         * <param name = "deltaT">The time difference</param>
         * <param name = "moveMethod">The method of interpolation (Linear, Smooth, Curved, EaseIn, EaseOut, Curved)</param>
         * <param name = "timeCurve">The AnimationCurve to interpolate against, if the moveMethod = MoveMethod.Curved</param>
         * <returns>The interpolated float</returns>
         */
        public static float Interpolate(float startT, float deltaT, MoveMethod moveMethod, AnimationCurve timeCurve = null)
        {
            if (moveMethod == MoveMethod.Curved)
            {
                moveMethod = MoveMethod.Smooth;
            }

            else if (moveMethod == MoveMethod.Smooth)
            {
                return -0.5f * (Mathf.Cos (Mathf.PI * (Time.time - startT) / deltaT) - 1f);
            }
            else if (moveMethod == MoveMethod.EaseIn)
            {
                return 1f - Mathf.Cos ((Time.time - startT) / deltaT * (Mathf.PI / 2));
            }
            else if (moveMethod == MoveMethod.EaseOut)
            {
                return Mathf.Sin ((Time.time - startT) / deltaT * (Mathf.PI / 2));
            }
            else if (moveMethod == MoveMethod.CustomCurve)
            {
                if (timeCurve == null || timeCurve.length == 0)
                {
                    return 1f;
                }
                float startTime = timeCurve [0].time;
                float endTime = timeCurve [timeCurve.length - 1].time;

                return timeCurve.Evaluate ((endTime - startTime) * (Time.time - startT) / deltaT + startTime);
            }

            return ((Time.time - startT) / deltaT);
        }
コード例 #33
0
ファイル: AdvSRBUtils.cs プロジェクト: kujuman/ksp-ksf-advSRB
        public static float CalcMassFlow(float time, AnimationCurve massFlow)
        {
            float f;
                f = massFlow.Evaluate(time);

                //if (!HighLogic.LoadedSceneIsEditor)
                //{
                //    if (thrustVariation > .0001f)
                //        f = f * (1 + CalcMassFlux());
                //}

                if (f > 0)
                    return f;
                else
                    return 0;
        }
コード例 #34
0
 public static float getCurveValue(AnimationCurve _curve, float _t)
 {
     return _curve.Evaluate(_t);
 }
コード例 #35
0
 public float Evaluate(float step)
 {
     return(animationCurve.Evaluate(step));
 }
コード例 #36
0
ファイル: MathHelpers.cs プロジェクト: jceipek/UnityBase
 public static float ScaleInputBySymmetricCurve(float input, AnimationCurve curve)
 {
     return curve.Evaluate(Mathf.Abs(input)) * Mathf.Sign(input);
 }
コード例 #37
0
ファイル: MathHelpers.cs プロジェクト: jceipek/UnityBase
 public static float ScaleInputByAsymmetricCurve(float input, AnimationCurve curve)
 {
     return curve.Evaluate(input);
 }
コード例 #38
0
ファイル: ChpAnimation.cs プロジェクト: fengqk/Art
//	public static AnimationCurve CreateCurveByPairedData( float[] pairedDatas)
//	{
//		D.Assert( pairedDatas.Length % 2 == 0, "check pairedData Count");
//		
//	}
	

	public static AnimationCurve SpeedCurve( AnimationCurve curve, float interval = 0.1f){
		D.Assert(interval > 0);
		float sTime = curve.keys[0].time;
		float eTime = curve.keys[curve.keys.Length-1].time;
		List<Keyframe> ks = new List<Keyframe>();
		
		float time = sTime;
		float nextTime = sTime + interval;
		while ( nextTime < eTime){
			float sp = (curve.Evaluate(time + interval) - curve.Evaluate(time))/interval;
			ks.Add(new Keyframe(time, sp));
			time = nextTime;
			nextTime += interval;
		}
		D.Assert(eTime > time);
		ks.Add( new Keyframe( eTime, (curve.Evaluate( eTime) - curve.Evaluate(time)) /(eTime - time) ) );
		
		return ChpAnimation.CreateCurve( ks.ToArray() );
		
	}