System.Func.Invoke(float)

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

184 Examples 7

19 Source : Vector2Extends.cs
with MIT License
from a3geek

public static Vector2 EachFunc(this Vector2 v2, Func<float, float> func)
        {
            return new Vector2(func(v2.x), func(v2.y));
        }

19 Source : CubeLutAssetFactory.cs
with MIT License
from alelievr

static void Dump(string replacedle, Func<float, float> eval)
        {
            var sb = new StringBuilder();
            sb.AppendFormat("replacedLE \"{0}\"\n", replacedle);
            sb.AppendFormat("LUT_3D_SIZE {0}\n", kSize);
            sb.AppendFormat("DOMAIN_MIN {0} {0} {0}\n", 0f);
            sb.AppendFormat("DOMAIN_MAX {0} {0} {0}\n", 1f);

            const float kSizeMinusOne = (float)kSize - 1f;

            for (int x = 0; x < kSize; x++)
            for (int y = 0; y < kSize; y++)
            for (int z = 0; z < kSize; z++)
            {
                float ox = eval((float)x / kSizeMinusOne);
                float oy = eval((float)y / kSizeMinusOne);
                float oz = eval((float)z / kSizeMinusOne);

                // Resolve & Photoshop use BGR as default, let's make it easier for users
                sb.AppendFormat("{0} {1} {2}\n", oz, oy, ox);
            }

            var content = sb.ToString();
            var path = Path.Combine(Application.dataPath, string.Format("{0}.cube", replacedle));
            File.WriteAllText(path, content);
        }

19 Source : PhysicsRemoteFPSAgentController_partial_ExpRoom.cs
with Apache License 2.0
from allenai

public IEnumerator<float?> whichContainersDoesAvailableObjectFitIn(
            string objectName,
            Camera visibilityCheckCamera
        ) {
            Action<SimObjPhysics> activateSop = (sop) => {
                sop.gameObject.SetActive(true);
                sop.ObjectID = sop.name;
                physicsSceneManager.AddToObjectsInScene(sop);
            };

            Action<SimObjPhysics> deactivateSop = (sop) => {
                sop.gameObject.SetActive(false);
                physicsSceneManager.RemoveFromObjectsInScene(sop);
            };

            Vector3 middleOfTable = new Vector3(-0.5f, 0.9f, 0.2f);
            Vector3 rightOfTable = new Vector3(0.534f, 0.9f, 0.2f);

            Dictionary<string, float> coverNameToScale = new Dictionary<string, float>();

            if (!availableExpRoomObjectsDict.ContainsKey(objectName)) {
                errorMessage = $"Could not find object with name {objectName}";
                actionFinished(false);
                yield break;
            }

            SimObjPhysics toCover = availableExpRoomObjectsDict[objectName];

            if (toCover.GetComponent<Break>()) {
                toCover.GetComponent<Break>().Unbreakable = true;
            }

            activateSop(toCover);

            if (!PlaceObjectAtPoint(
                target: toCover,
                position: middleOfTable,
                rotation: null,
                forceKinematic: true
            )) {
                deactivateSop(toCover);
                errorMessage = $"{toCover.name} failed to place";
                actionFinished(false);
                yield break;
            }

            yield return 0f;

            Vector3 toCoverPos = toCover.transform.position;

            int numberFit = 0;
            foreach (
                SimObjPhysics cover in availableExpRoomContainersDict.OrderBy(
                        kvp => kvp.Key
                    ).Select(kvp => kvp.Value)
            ) {
                if (cover.GetComponent<Break>()) {
                    cover.GetComponent<Break>().Unbreakable = true;
                }

                cover.transform.rotation = Quaternion.Euler(180f, 0f, 0f);
                activateSop(cover);

                BoxCollider coverBbox = cover.BoundingBox.GetComponent<BoxCollider>();
                float maxScale = Mathf.Min(
                    0.5f / coverBbox.size.y,
                    0.7f / coverBbox.size.x,
                    0.7f / coverBbox.size.z,
                    1.75f
                );
                float minScale = Mathf.Min(0.5f, maxScale / 2.0f);

                float lastScale = 1.0f;
                Func<float, bool> tryScale = (scale) => {
                    emptyEnumerator(scaleObject(
                        scale: scale / lastScale,
                        target: cover,
                        scaleOverSeconds: 0f,
                        skipActionFinished: true
                    ));
                    lastScale = scale;

                    Physics.SyncTransforms();

                    if (!PlaceObjectAtPoint(
                        target: cover,
                        position: rightOfTable,
                        rotation: null,
                        forceKinematic: true,
                        includeErrorMessage: true
                    )) {
#if UNITY_EDITOR
                        Debug.Log($"{cover.name} failed to place: {errorMessage}");
#endif
                        deactivateSop(cover);
                        return false;
                    }

                    float coverY = cover.transform.position.y;
                    float toCoverHeight = toCover.BoundingBox.GetComponent<BoxCollider>().size.y;
                    for (int i = 0; i < 4; i++) {
                        cover.transform.position = new Vector3(
                            toCoverPos.x,
                            coverY + toCoverHeight * (i / 4f),
                            toCoverPos.z
                        );

                        Physics.SyncTransforms();

                        Collider coverCollidingWith = UtilityFunctions.firstColliderObjectCollidingWith(
                            go: cover.gameObject
                        );
                        if (coverCollidingWith != null) {
                            //Debug.Log($"{cover.name} colliding with {coverCollidingWith.transform.parent.name}");
                            return false;
                        }
                        if (i == 0) {
                            if (isSimObjVisible(visibilityCheckCamera, toCover, 10f).visible) {
                                return false;
                            }
                        }
                    }
                    return true;
                };

                if (tryScale(maxScale)) {
                    for (int i = 0; i <= 5; i++) {
                        float newScale = (minScale + maxScale) / 2.0f;
                        if (tryScale(newScale)) {
                            maxScale = newScale;
                        } else {
                            minScale = newScale;
                        }
                        yield return null;
                    }
#if UNITY_EDITOR
                    Debug.Log($"{toCover.name} fits under {cover.name} at {maxScale} scale");
#endif
                    coverNameToScale[cover.name] = maxScale;
                    numberFit += 1;
                }

                emptyEnumerator(scaleObject(
                    scale: 1.0f / lastScale,
                    target: cover,
                    scaleOverSeconds: 0f,
                    skipActionFinished: true
                ));

                deactivateSop(cover);
            }

#if UNITY_EDITOR
            Debug.Log(
                Newtonsoft.Json.JsonConvert.SerializeObject(
                    coverNameToScale,
                    Newtonsoft.Json.Formatting.None,
                    new Newtonsoft.Json.JsonSerializerSettings() {
                        ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                        ContractResolver = new ShouldSerializeContractResolver()
                    }
                )
            );
#endif

            deactivateSop(toCover);

            yield return 0f;

            actionFinished(true, coverNameToScale);
        }

19 Source : TetrisProblem.cs
with MIT License
from altimesh

[HybridizerIgnore]
        public void SaveImage(string fileName, Func<float, Color> GetColor)
        {
            Bitmap image = new Bitmap(_N - 1, _N - 1);
            for (int j = 0; j <= _N - 2; ++j)
            {
                for (int i = 0; i <= _N - 2; ++i)
                {
                    float temp = _inner[j * (_N - 1) + i];
                    image.SetPixel(i, j, GetColor(temp));
                }
            }

            image.Save(fileName);
        }

19 Source : Test2.cs
with MIT License
from Aminator

[ShaderMethod]
        [Shader("compute")]
        [NumThreads(32, 1, 1)]
        public void Execute(CSInput input)
        {
            DestinationBuffer[input.DispatchThreadId.X] = f(input.DispatchThreadId.X);
        }

19 Source : LoadBalancedActionPool.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

float? ILoadBalanced.ExecuteUpdate(float deltaTime, float nextInterval)
            {
                this.repeat = _action(deltaTime);
                if (!this.repeat)
                {
                    LoadBalancedActionPool.Return(this);
                }

                return null;
            }

19 Source : RepeatableAction.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

public float? ExecuteUpdate(float deltaTime, float nextInterval)
        {
            this.repeat = _action(deltaTime);
            if (this.repeat && _repereplacedions > -1)
            {
                this.repeat = (_repereplacedionCount++ < _repereplacedions);
            }

            return null;
        }

19 Source : WaveShaper.cs
with MIT License
from ar1st0crat

public float Process(float sample) => _waveShapingFunction(sample);

19 Source : MathKit.cs
with MIT License
from Avatarchik

public static float InverseInterpolate(float t, Func<float, float> interpolate)
        {
            return 1f - interpolate(1f - t);
        }

19 Source : MyMath.cs
with MIT License
from baratgabor

public static float Ease01(this float x, Easing easingType)
            => _easingMap[easingType].Invoke(x);

19 Source : Graph.cs
with MIT License
from bassmit

public float F(float x) => _func(x);

19 Source : PrecisionUtils.cs
with GNU Lesser General Public License v2.1
from BattletechModders

private static float Round(float value, Func<float, float> rounder, float precision)
        {
            return rounder(value / precision) * precision;
        }

19 Source : TransitionsTesting.cs
with MIT License
from beto-rodriguez

[TestMethod]
        public void TestMethod1()
        {
            var r = new RectangleGeometry();
            var a = (IAnimatable)r;
            var duration = TimeSpan.FromSeconds(1);
            var easing = EasingFunctions.Lineal;

            r.SetPropertiesTransitions(
                new Animation(easing, duration, int.MaxValue),
                nameof(r.Y), nameof(r.X), nameof(r.Width), nameof(r.Height));

            void DrawFrame(long time)
            {
                a.CurrentTime = time;
                a.IsValid = true;
            }

            float DoTransition(float from, float to, float start, float end, long time, Func<float, float> easing)
            {
                var p = (time - start) / (end - start);
                if (p > 1) p = 1;
                return from + easing(p) * (to - from);
            }

            var time = 50;
            DrawFrame(time);

            // transition from 50 to 100 for each property
            r.Y = 50;
            r.X = 50;
            r.Width = 50;
            r.Height = 50;
            r.CompleteTransitions(nameof(r.Y), nameof(r.X), nameof(r.Width), nameof(r.Height));

            r.Y = 100;
            r.X = 100;
            r.Width = 100;
            r.Height = 100;

            a.CurrentTime = time;
            var startTime = 50;
            time = startTime;

            while (time <= duration.TotalMilliseconds * 2 + startTime)
            {
                DrawFrame(time);

                var x = r.X;
                var y = r.Y;
                var w = r.Width;
                var h = r.Height;
                var l = Math.Truncate((time - startTime) / duration.TotalMilliseconds);
                if ((time - startTime) % duration.TotalMilliseconds == 0 && time != startTime) l--;
                var laps = (long)(l * duration.TotalMilliseconds);
                replacedert.IsTrue(x == DoTransition(50, 100, 50, 1050, time - laps, easing));
                replacedert.IsTrue(y == DoTransition(50, 100, 50, 1050, time - laps, easing));
                replacedert.IsTrue(w == DoTransition(50, 100, 50, 1050, time - laps, easing));
                replacedert.IsTrue(h == DoTransition(50, 100, 50, 1050, time - laps, easing));

                replacedert.IsTrue(!a.IsValid);
                time += 500;
            }

            // not completed yet because the duration of the animation in this case is infinite
            replacedert.IsTrue(!a.IsValid);
        }

19 Source : Exporter.Animation.cs
with MIT License
from bghgary

private Schema.AnimationSampler ExportAnimationSampler<T>(IEnumerable<AnimationCurve> curves, Func<int, T> getInTangent, Func<int, T> getValue, Func<int, T> getOutTangent, Func<float, T> evaluate, Func<IEnumerable<T>, int> exportData)
        {
            if (!this.settings.BakeAnimations && CanExportCurvesreplacedpline(curves))
            {
                var firstCurve = curves.First();

                var input = new float[firstCurve.keys.Length];
                var output = new T[firstCurve.keys.Length * 3];
                for (int keyIndex = 0; keyIndex < firstCurve.keys.Length; keyIndex++)
                {
                    input[keyIndex] = firstCurve.keys[keyIndex].time;

                    output[keyIndex * 3 + 0] = getInTangent(keyIndex);
                    output[keyIndex * 3 + 1] = getValue(keyIndex);
                    output[keyIndex * 3 + 2] = getOutTangent(keyIndex);
                }

                return new Schema.AnimationSampler
                {
                    Input = this.ExportData(input, minMax: true),
                    Interpolation = Schema.AnimationSamplerInterpolation.CUBICSPLINE,
                    Output = exportData(output),
                };
            }
            else
            {
                var input = new List<float>();
                var output = new List<T>();
                var maxTime = curves.Max(curve => curve.keys.Last().time);
                for (float time = 0; time < maxTime; time += 1.0f / 30.0f)
                {
                    input.Add(time);
                    output.Add(evaluate(time));
                }

                return new Schema.AnimationSampler
                {
                    Input = this.ExportData(input, minMax: true),
                    Interpolation = Schema.AnimationSamplerInterpolation.LINEAR,
                    Output = exportData(output),
                };
            }
        }

19 Source : Tween.cs
with MIT License
from blish-hud

private void Update(float elapsed)
		{
        	if (firstUpdate)
        	{
        		firstUpdate = false;
        		
				var i = vars.Count;
				while (i --> 0)
				{
					if (lerpers[i] != null)
						lerpers[i].Initialize(start[i], end[i], behavior);
				}
        	}
        	else
        	{
				if (this.Paused)
					return;
				
				if (Delay > 0)
				{
					Delay -= elapsed;
					if (Delay > 0)
						return;
				}
				
				if (time == 0 && timesRepeated == 0 && begin != null)
					begin();
				
				time += elapsed;
				float setTimeTo = time;
				float t = time / Duration;
				bool doComplete = false;
				
				if (time >= Duration)
				{
					if (repeatCount != 0)
					{
						setTimeTo = 0;
						Delay = repeatDelay;
						timesRepeated++;
						
						if (repeatCount > 0)
							--repeatCount;
						
						if (repeatCount < 0)
							doComplete = true;
					}
					else
					{
						time = Duration;
						t = 1;
	                    Remover.Remove(this);
	                    doComplete = true;
					}
				}
				
				if (ease != null)
					t = ease(t);
				
				int i = vars.Count;
				while (i --> 0)
				{
					if (vars[i] != null)
						vars[i].Value = lerpers[i].Interpolate(t, vars[i].Value, behavior);
				}
				
				time = setTimeTo;
				
				//	If the timer is zero here, we just restarted.
				//	If reflect mode is on, flip start to end
				if (time == 0 && (behavior & MemberLerper.Behavior.Reflect) == MemberLerper.Behavior.Reflect)
					Reverse();
				
				if (update != null)
					update();
				
				if (doComplete && complete != null)
					complete();
        	}
		}

19 Source : Ease.cs
with MIT License
from blish-hud

public static Func<float, float> ToAndFro(Func<float, float> easer)
		{
			return t => ToAndFro(easer(t));
		}

19 Source : Test.cs
with MIT License
from BLUDRAG

void Update() {
		var method = Stopwatch.StartNew();
		bool methodb = false;
		for (int i = 0; i < ITERATIONS; ++i) {
			methodb = TestMethod(f);
		}
		method.Stop();

		var regularDelegate = Stopwatch.StartNew();
		bool regularDelegateb = false;
		for (int i = 0; i < ITERATIONS; ++i) {
			regularDelegateb = RegularDelegate(f);
		}
		regularDelegate.Stop();

		var dynamicDelegate = Stopwatch.StartNew();
		bool dynamicDelegateb = false;
		for (int i = 0; i < ITERATIONS; ++i) {
			dynamicDelegateb = DynamicDelegate(f);
		}
		dynamicDelegate.Stop();

		var serializedDelegate = Stopwatch.StartNew();
		bool serializedDelegateb = false;
		for (int i = 0; i < ITERATIONS; ++i) {
			serializedDelegateb = condition.Invoke(f);
		}
		serializedDelegate.Stop();

		var serializedEvent = Stopwatch.StartNew();
		for (int i = 0; i < ITERATIONS; ++i) {
			ev.Invoke();
		}
		serializedEvent.Stop();

		UnityEngine.Debug.Log("Method: " + methodb + method.Elapsed);
		UnityEngine.Debug.Log("RegularDelegate: " + regularDelegateb + regularDelegate.Elapsed);
		UnityEngine.Debug.Log("DynamicDelegate: " + dynamicDelegateb + dynamicDelegate.Elapsed);
		UnityEngine.Debug.Log("SerializedCallback: " + serializedDelegateb + serializedDelegate.Elapsed);
		UnityEngine.Debug.Log("SerializedEvent: " + serializedEvent.Elapsed);
	}

19 Source : OctreeMath.cs
with GNU General Public License v3.0
from BudgetToaster

public static float EstimateDerivative(float x, float dx, Func<float, float> f) 
            => (f(x + dx) - f(x)) / dx;

19 Source : StrobeLightingPass.cs
with GNU General Public License v2.0
from Caeden117

public override IEnumerable<MapEvent> StrobePreplacedForLane(IEnumerable<MapEvent> original, int type,
        EventsContainer.PropMode propMode, JSONNode propID)
    {
        var generatedObjects = new List<MapEvent>();

        var startTime = original.First().Time;
        var endTime = original.Last().Time;

        var alternatingTypes = new List<int>(values);
        var typeIndex = 0;
        if (alternateColors)
        {
            for (var i = 0; i < values.Count(); i++)
                alternatingTypes.Add(InvertColors(alternatingTypes[i]));
        }

        var distanceInBeats = endTime - startTime;
        var originalDistance = distanceInBeats;
        MapEvent lastPreplaceded = null;

        while (distanceInBeats >= 0)
        {
            if (typeIndex >= alternatingTypes.Count) typeIndex = 0;

            var any = original.Where(x => x.Time <= endTime - distanceInBeats).LastOrDefault();
            if (any != lastPreplaceded && dynamic && MapEvent.IsBlueEventFromValue(any.Value) !=
                MapEvent.IsBlueEventFromValue(alternatingTypes[typeIndex]))
            {
                lastPreplaceded = any;
                for (var i = 0; i < alternatingTypes.Count; i++)
                    alternatingTypes[i] = InvertColors(alternatingTypes[i]);
            }

            var value = alternatingTypes[typeIndex];
            var progress = (originalDistance - distanceInBeats) / originalDistance;
            var newTime = (easingFunc(progress) * originalDistance) + startTime;
            var data = new MapEvent(newTime, type, value);
            if (propMode != EventsContainer.PropMode.Off)
            {
                if (value != MapEvent.LightValueBlueON && value != MapEvent.LightValueRedON &&
                    value != MapEvent.LightValueOff)
                {
                    data.Value = value < 5
                        ? MapEvent.LightValueBlueON
                        : MapEvent.LightValueRedON;
                }

                data.CustomData = new JSONObject();
                data.CustomData.Add("_lightID", propID);
            }

            generatedObjects.Add(data);
            typeIndex++;

            if (distanceInBeats > 0 && (distanceInBeats -= 1 / precision) < -0.001f)
                distanceInBeats = 0;
            else if (distanceInBeats <= 0) break;
        }

        return generatedObjects;
    }

19 Source : StrobeLaserSpeedInterpolationPass.cs
with GNU General Public License v2.0
from Caeden117

public override IEnumerable<MapEvent> StrobePreplacedForLane(IEnumerable<MapEvent> original, int type,
        EventsContainer.PropMode propMode, JSONNode propID)
    {
        var generatedObjects = new List<MapEvent>();

        var startTime = original.First().Time;
        var endTime = original.Last().Time;

        var distanceInBeats = endTime - startTime;
        var originalDistance = distanceInBeats;
        var lastPreplaceded = original.First();
        var nextEvent = original.ElementAt(1);

        var lastSpeed = GetLaserSpeedFromEvent(lastPreplaceded);
        var nextSpeed = GetLaserSpeedFromEvent(nextEvent);

        while (distanceInBeats >= 0)
        {
            var any = original.Where(x => x.Time <= endTime - distanceInBeats).LastOrDefault();
            if (lastPreplaceded != any)
            {
                lastPreplaceded = any;
                nextEvent = original.Where(x => x.Time > lastPreplaceded.Time).FirstOrDefault();
                lastSpeed = GetLaserSpeedFromEvent(lastPreplaceded);
                if (nextEvent == null) nextEvent = lastPreplaceded;
                nextSpeed = GetLaserSpeedFromEvent(nextEvent);
            }

            var newTime = originalDistance - distanceInBeats + startTime;
            var progress = Mathf.InverseLerp(lastPreplaceded.Time, nextEvent.Time, newTime);

            var decimalPreciseSpeed =
                Math.Round(Mathf.Lerp(lastSpeed, nextSpeed, easingFunc(progress)), decimalPrecision);
            // This does not support negative numbers, however I do not believe there is a reason to support them in the first place
            var roundedPreciseSpeed = (int)Math.Max(1, Math.Round(decimalPreciseSpeed, MidpointRounding.AwayFromZero));

            var data = new MapEvent(newTime, type, 1) { CustomData = new JSONObject(), Value = roundedPreciseSpeed };

            // Bit cheeky but hopefully a bit more readable
            if (Math.Abs(decimalPreciseSpeed - roundedPreciseSpeed) > 0.01f)
                data.CustomData["_preciseSpeed"] = decimalPreciseSpeed;

            if (overrideDirection)
            {
                switch (type)
                {
                    case MapEvent.EventTypeLeftLasersSpeed:
                        data.CustomData["_direction"] = Convert.ToInt32(leftRotatesClockwise);
                        break;
                    case MapEvent.EventTypeRightLasersSpeed:
                        data.CustomData["_direction"] = Convert.ToInt32(rightRotatesClockwise);
                        break;
                }
            }

            if (lockLaserRotation) data.CustomData["_lockPosition"] = true;

            generatedObjects.Add(data);
            distanceInBeats -= 1 / interval;
        }

        return generatedObjects;
    }

19 Source : StrobeStepGradientPass.cs
with GNU General Public License v2.0
from Caeden117

public override IEnumerable<MapEvent> StrobePreplacedForLane(IEnumerable<MapEvent> original, int type,
        EventsContainer.PropMode propMode, JSONNode propID)
    {
        var generatedObjects = new List<MapEvent>();

        var startTime = original.First().Time;
        var endTime = original.Last().Time;

        // Aggregate all colors points into a dictionary
        var colorPoints = new Dictionary<float, Color>();

        foreach (var e in original)
        {
            // Might as well be fancy and add support for Chroma 2.0 gradients
            if (e.LightGradient != null)
            {
                colorPoints.Add(e.Time, e.LightGradient.StartColor);
                colorPoints.Add(e.Time + e.LightGradient.Duration, e.LightGradient.EndColor);
            }
            else if (e.IsChromaEvent) // This already checks customData, so if this is true then customData exists.
            {
                colorPoints.Add(e.Time, e.CustomData["_color"]);
            }
        }

        var distanceInBeats = endTime - startTime;
        var originalDistance = distanceInBeats;

        if (colorPoints.Count < 2) return Enumerable.Empty<MapEvent>();

        var lastPoint = colorPoints.ElementAt(0);
        var nextPoint = colorPoints.ElementAt(1);

        while (distanceInBeats >= -0.01f)
        {
            var anyLast = colorPoints.Where(x => x.Key <= endTime - distanceInBeats).LastOrDefault();
            if (anyLast.Key != lastPoint.Key)
            {
                var nextPoints = colorPoints.Where(x => x.Key > endTime - distanceInBeats);

                // Don't progress if this is the last gradient
                if (nextPoints.Any())
                {
                    lastPoint = anyLast;
                    nextPoint = nextPoints.First();
                }
            }

            var progress = (originalDistance - distanceInBeats) / originalDistance;
            var newTime = (progress * originalDistance) + startTime;

            var lerp = easing(Mathf.InverseLerp(lastPoint.Key, nextPoint.Key, newTime));
            var color = Color.Lerp(lastPoint.Value, nextPoint.Value, lerp);

            var data = new MapEvent(newTime, type, value, new JSONObject());
            data.CustomData.Add("_color", color);
            if (propMode != EventsContainer.PropMode.Off)
            {
                if (value != MapEvent.LightValueBlueON && value != MapEvent.LightValueRedON &&
                    value != MapEvent.LightValueOff)
                {
                    data.Value = value < 5
                        ? MapEvent.LightValueBlueON
                        : MapEvent.LightValueRedON;
                }

                data.CustomData.Add("_lightID", propID);
            }

            generatedObjects.Add(data);

            distanceInBeats -= 1 / precision;

            if (alternateColors) value = InvertColors(value);
        }

        return generatedObjects;
    }

19 Source : InvocationContext.cs
with MIT License
from CatLib

public static T CheckAndInvokeFromFloat(float val)
        {
            if (FromFloat != null)
                return FromFloat(val);
            else
                throw new InvalidCastException(string.Format("Cannot cast System.Single to {0}", typeof(T).FullName));
        }

19 Source : NumericsUtil.cs
with MIT License
from chillersanim

public static Func<float, float> ApproximateDerivative(this Func<float, float> f, float epsilon = 0.01f)
        {
            return t =>
            {
                var a = f(t - epsilon);
                var b = f(t + epsilon);

                return (b - a) / (2f * epsilon);
            };
        }

19 Source : NumericsUtil.cs
with MIT License
from chillersanim

public static Func<float, Vector2> ApproximateDerivative(this Func<float, Vector2> f, float epsilon = 0.01f)
        {
            return t =>
            {
                var a = f(t - epsilon);
                var b = f(t + epsilon);

                return (b - a) / (2f * epsilon);
            };
        }

19 Source : NumericsUtil.cs
with MIT License
from chillersanim

public static Func<float, Vector4> ApproximateDerivative(this Func<float, Vector4> f, float epsilon = 0.01f)
        {
            return t =>
            {
                var a = f(t - epsilon);
                var b = f(t + epsilon);

                return (b - a) / (2f * epsilon);
            };
        }

19 Source : NumericsUtil.cs
with MIT License
from chillersanim

public static Func<float, Vector3> ApproximateDerivative(this Func<float, Vector3> f, float epsilon = 0.01f)
        {
            return t =>
            {
                var a = f(t - epsilon);
                var b = f(t + epsilon);

                return (b - a) / (2f * epsilon);
            };
        }

19 Source : TransformExtension.cs
with MIT License
from coding2233

public static Transform PositionX(this Transform transform, Func<float, float> xSetter)
    {
        mPos = transform.position;
        mPos.x = xSetter(mPos.x);
        transform.position = mPos;
        return transform;
    }

19 Source : TransformExtension.cs
with MIT License
from coding2233

public static Transform PositionY(this Transform transform, Func<float, float> ySetter)
    {
        mPos = transform.position;
        mPos.y = ySetter(mPos.y);
        transform.position = mPos;
        return transform;
    }

19 Source : TransformExtension.cs
with MIT License
from coding2233

public static Transform PositionZ(this Transform transform, Func<float, float> zSetter)
    {
        mPos = transform.position;
        mPos.z = zSetter(mPos.z);
        transform.position = mPos;
        return transform;
    }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float Ease(Easing easeType, float x)
        {
            return Get(easeType).Invoke(x);
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InSine(float x)
        {
            return 1 - Cos((x * PI) * 0.5f);
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float OutSine(float x)
        {
            return Sin((x * PI) * 0.5f);
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InOutSine(float x)
        {
            return (Cos(PI * x) - 1) * -0.5f;
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InCirc(float x)
        {
            return 1 - Sqrt(1 - Pow(x, 2));
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float OutCirc(float x)
        {
            return Sqrt(1 - Pow(x - 1, 2));
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InOutCirc(float x)
        {
            return x < 0.5f ? (1 - Sqrt(1 - Pow(2 * x, 2))) * 0.5f : (Sqrt(1 - Pow(-2 * x + 2, 2)) + 1) * 0.5f;
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InElastic(float x)
        {
            switch (x)
            {
                case 0:
                    return 0;
                case 1:
                    return 1;
                default:
                    return -Pow(2, 10 * x - 10) * Sin((x * 10 - 10.75f) * c4);
            }
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float OutElastic(float x)
        {
            switch (x)
            {
                case 0:
                    return 0;
                case 1:
                    return 1;
                default:
                    return -Pow(2, -10 * x) * Sin((x * 10 - 0.75f) * c4) + 1;
            }
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float InOutElastic(float x)
        {
            switch (x)
            {
                case 0:
                    return 0;
                case 1:
                    return 1;
                default:
                    return x < 0.5f 
                        ? -(Pow(2, 20 * x - 10) * Sin((20 * x - 11.125f) * c5)) * 0.5f 
                        : (Pow(2, -20 * x + 10) * Sin((20 * x - 11.125f) * c5)) * 0.5f + 1;
            }
        }

19 Source : EaseFunctions.cs
with Apache License 2.0
from coryleach

public static float Spring(float value)
        {
            return (Sin(value * PI * (0.2f + 2.5f * value * value * value)) * Pow(1f - value, 2.2f) + value) * (1f + (1f - value) * 1.2f);
        }

19 Source : TensorOpCpu.cs
with GNU General Public License v3.0
from Cr33zz

public virtual void Map(Tensor t, Func<float, float> func, Tensor result)
        {
            t.CopyToHost();
            result.CurrentLocation = Tensor.Location.Host;

            for (int i = 0; i < t.Values.Length; ++i)
                result.Values[i] = func(t.Values[i]);
        }

19 Source : TensorOpCpu.cs
with GNU General Public License v3.0
from Cr33zz

public virtual void Map(Func<float, float> func, Tensor t, Tensor result)
        {
            t.CopyToHost();
            result.CurrentLocation = Tensor.Location.Host;

            for (int i = 0; i < t.Values.Length; ++i)
                result.Values[i] = func(t.Values[i]);
        }

19 Source : TensorOpMultiCpu.cs
with GNU General Public License v3.0
from Cr33zz

public override void Map(Func<float, float> func, Tensor t, Tensor result)
        {
            t.CopyToHost();
            result.CurrentLocation = Tensor.Location.Host;

            var rangeParreplacedioner = Parreplacedioner.Create(0, result.Values.Length);
            Parallel.ForEach(rangeParreplacedioner, range =>
            {
                for (int i = range.Item1; i < range.Item2; ++i)
                    result.Values[i] = func(t.Values[i]);
            });
        }

19 Source : TweenInstance.cs
with MIT License
from crookookoo

public void interpolatePercent() {
      float progress;
      switch (smoothType) {
        case SmoothType.Linear:
          progress = curPercent;
          break;
        case SmoothType.Smooth:
          progress = Mathf.SmoothStep(0, 1, curPercent);
          break;
        case SmoothType.SmoothEnd:
          progress = 1.0f - (curPercent - 1.0f) * (curPercent - 1.0f);
          break;
        case SmoothType.SmoothStart:
          progress = curPercent * curPercent;
          break;
        default:
          progress = smoothFunction(curPercent);
          break;
      }

      for (int i = interpolatorCount; i-- != 0;) {
        IInterpolator interpolator = interpolators[i];
        if (interpolator.isValid) {
          interpolators[i].Interpolate(progress);
        } else {
          interpolators[i] = interpolators[--interpolatorCount];
        }
      }

      if (OnProgress != null) {
        OnProgress(curPercent);
      }
    }

19 Source : UiExtensions.cs
with Apache License 2.0
from cs-util-com

public static UnityAction<float> AddOnValueChangedAction(this Slider self, Func<float, bool> onValueChanged) {
            if (onValueChanged != null) {
                var oldValue = self.value;
                UnityAction<float> newListener = (newValue) => {
                    if (SameValueAsBefore(oldValue, newValue, self.minValue, self.maxValue)) { return; }
                    // Ignore event event if it was triggered through code, only fire for actual user input:
                    if (!self.ChangeWasTriggeredByUserThroughEventSystem()) { return; }
                    if (!onValueChanged(newValue)) { // Change was rejected, revert UI:
                        self.value = oldValue;
                    } else { // Change was accepted:
                        oldValue = newValue;
                        EventBus.instance.Publish(EventConsts.catUi + UiEvents.SLIDER_CHANGED, self, newValue);
                    }
                };
                self.onValueChanged.AddListener(newListener);
                return newListener;
            }
            return null;
        }

19 Source : MovementSettings.cs
with MIT License
from csinkers

public float GetDepth(float y) => _getDepth(y);

19 Source : Modify.cs
with Apache License 2.0
from CyanCode

public override float GetValue(float x, float y, float z)
		{
			return m_Modifier(m_Source.GetValue(x, y, z));
		}

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

public static IEnumerator DownloadSheet(string docsId, string sheetId, Action<string> done, GoogleDriveDownloadFormat format = GoogleDriveDownloadFormat.CSV, Func<float, bool> progressbar = null)
        {
            if (progressbar != null && progressbar(0))
            {
                done(null);
                yield break;
            }

            var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/export?format={2}&gid={1}", docsId, sheetId, Enum.GetName(typeof(GoogleDriveDownloadFormat), format).ToLower());
#if UNITY_2017_2_OR_NEWER
            var www = UnityWebRequest.Get(url);
            www.SendWebRequest();
#elif UNITY_5_5_OR_NEWER
            var www = UnityWebRequest.Get(url);
            www.Send();
#else
            var www = new WWW(url);
#endif
            while (!www.isDone)
            {
#if UNITY_5_5_OR_NEWER
                var progress = www.downloadProgress;
#else
                var progress = www.progress;
#endif
                if (progressbar != null && progressbar(progress))
                {
                    done(null);
                    yield break;
                }
                yield return null;
            }

            if (progressbar != null && progressbar(1))
            {
                done(null);
                yield break;
            }

#if UNITY_5_5_OR_NEWER
            var text = www.downloadHandler.text;
#else
            var text = www.text;
#endif

            if (text.StartsWith("<!"))
            {
                Debug.LogError("Google sheet could not be downloaded.\nURL:" + url + "\n" + text);
                done(null);
                yield break;
            }

            done(text);
        }

19 Source : TransitionModeler.cs
with MIT License
from Daimler

public MAvatarPostureValues ComputeResult(float time, MSimulationState avatarState)
        {
            //Do nothing if inactive
            if (!this.Active)
                return avatarState.Current;

            //Increment the time
            this.elapsedTime += time;

            //Estimate the blend weight -> to do use animation curves
            float blendWeight = this.WeightFunction(elapsedTime);

            //Set finished flag
            if (blendWeight >= 1)
                this.Finished = true;

            //Perform the blend and return the result
            return Blending.PerformBlend(this.Skeleton,  this.GetSourcePosture(time, avatarState), this.GetTargetPosture(time, avatarState), blendWeight, this.Mask);
        }

19 Source : TargetingBase.cs
with MIT License
from daud-io

public bool IsSafeTarget(Vector2 target)
        {
            var toTarget = target - Robot.Position;
            var angle = MathF.Atan2(toTarget.Y, toTarget.X);

            return IsSafeShot(angle);
        }

See More Examples