public void FindAndApplySeparatorSlots(System.Func <string, bool> slotNamePredicate, bool clearExistingSeparators = true, bool updateStringArray = false) { if (slotNamePredicate == null) { return; } if (!valid) { return; } if (clearExistingSeparators) { separatorSlots.Clear(); } var slots = skeleton.slots; foreach (var slot in slots) { if (slotNamePredicate.Invoke(slot.data.name)) { separatorSlots.Add(slot); } } if (updateStringArray) { var detectedSeparatorNames = new List <string>(); foreach (var slot in skeleton.slots) { string slotName = slot.data.name; if (slotNamePredicate.Invoke(slotName)) { detectedSeparatorNames.Add(slotName); } } if (!clearExistingSeparators) { string[] originalNames = this.separatorSlotNames; foreach (string originalName in originalNames) { detectedSeparatorNames.Add(originalName); } } this.separatorSlotNames = detectedSeparatorNames.ToArray(); } }
public static Path FindPath(StatePaintBot paintBot, MapCoordinate start, System.Func <MapCoordinate, bool> condition) { if (condition.Invoke(start)) { return(new Path(Action.Stay, start, ImmutableList.Create <MapCoordinate>())); } HashSet <MapCoordinate> otherColouredCoordinates = paintBot.Map.CharacterInfos .Where(ci => ci.Id != paintBot.PlayerId) .SelectMany(ci => ci.ColouredPositions.Select(paintBot.MapUtils.GetCoordinateFrom)) .ToHashSet(); HashSet <MapCoordinate> leaderColouredCoordinates = paintBot.Map.CharacterInfos .Where(ci => ci.Id != paintBot.PlayerId && ci.Points >= paintBot.PlayerInfo.Points) .SelectMany(ci => ci.ColouredPositions.Select(paintBot.MapUtils.GetCoordinateFrom)) .ToHashSet(); ISet <MapCoordinate> visited = new HashSet <MapCoordinate>(); SimplePriorityQueue <(Path, float), float> toTest = new SimplePriorityQueue <(Path, float), float>(); toTest.Enqueue((new Path(Action.Stay, start, ImmutableList.Create <MapCoordinate>()), 0.0f), 0.0f); while (toTest.Count > 0) { var((firstStep, from, coordinates), fromSteps) = toTest.Dequeue(); bool wasInRangeOfOther = IsInRangeOfOther(paintBot, from); foreach (Action direction in directions.OrderBy(_ => paintBot.Random.NextDouble())) { MapCoordinate to = from.MoveIn(direction); if (!visited.Contains(to) && !paintBot.Disallowed.Contains(to) && paintBot.MapUtils.IsMovementPossibleTo(to) && !IsTooCloseToOther(paintBot, to) && (wasInRangeOfOther || !IsInRangeOfOther(paintBot, to))) { float cost = 1.0f - paintBot.CalculatePointsAt(to) / 8.0f + 0.125f; Path path = new Path(firstStep != Action.Stay ? firstStep : direction, to, coordinates.Add(to)); if (condition.Invoke(to)) { return(path); } visited.Add(to); toTest.Enqueue((path, fromSteps + cost), fromSteps + cost); } } } return(null); }
private string GetPartLocation(Transform t) { var sb = new StringBuilder(); sb.Insert(0, t.name); System.Func <Transform, Transform> repeater = (T) => { if (T.parent != null) { sb.Insert(0, $"{T.parent.name}/"); return(T.parent); } return(null); }; var parent = t; while (parent != null) { parent = repeater.Invoke(parent); } return(sb.ToString()); }
/// <summary> /// Applies a passed function to every member of the IList. Passed in function changes the item itself. /// </summary> /// <param name="function">Function with a single Item argument and with an Item return type.</param> public static void DoOnAll <I>(this IList <I> target, System.Func <I, I> function) { for (int i = 0; i < target.Count; i++) { target[i] = function.Invoke(target[i]); } }
public static int GetRandomIndex <T>(ref List <int> thresholds, List <T> list, System.Func <T, int> callback) { if (thresholds == null) { thresholds = new List <int>(list.Count); } else { thresholds.Clear(); } var maxRate = 0; foreach (var key in list) { maxRate += callback.Invoke(key); thresholds.Add(maxRate); } var rate = Random.Range(0, maxRate); var index = 0; for (; index < thresholds.Count; ++index) { if (rate < thresholds[index]) { break; } } return(index); }
/// Creates a (or reuses a previously created) Screenshot instance private static T WithInstance <T>(bool cache, System.Func <Screenshot, T> func) { Screenshot screenshot = null; GameObject entity = null; if (cache) { screenshot = cachedInstance; if (screenshot != null && !screenshot.isActiveAndEnabled) { screenshot = null; } } if (screenshot == null) { // create and entity to hold our screenshot component entity = new GameObject("Screenshot Instance"); screenshot = entity.AddComponent <Screenshot>(); if (cache) { cachedInstance = screenshot; } } var result = func.Invoke(screenshot); if (!cache) { Destroy(entity); // cleanup } return(result); }
public static void Main(string[] args) { string a = supplier.Invoke(); consumer.Invoke("a"); string b = function.Invoke("b"); }
private static Transform[] GetChildBy(Transform parent, System.Func <Transform, bool> comp) { List <Transform> returnContainer = new List <Transform>(); LinkedList <Transform> queue = new LinkedList <Transform>(); queue.AddLast(parent); while (queue.Count > 0) { var current = queue.First.Value; queue.RemoveFirst(); for (int i = 0; i < current.childCount; i++) { var child = current.GetChild(i); if (comp.Invoke(child)) { returnContainer.Add(child); } if (child.childCount > 0) { queue.AddLast(child); } } } return(returnContainer.ToArray()); }
static StackObject *Invoke_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 4); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @arg3 = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Int32 @arg2 = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 3); System.Int32 @arg1 = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 4); System.Func <System.Int32, System.Int32, System.Int32, System.Boolean> instance_of_this_method = (System.Func <System.Int32, System.Int32, System.Int32, System.Boolean>) typeof(System.Func <System.Int32, System.Int32, System.Int32, System.Boolean>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 8); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Invoke(@arg1, @arg2, @arg3); __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method ? 1 : 0; return(__ret + 1); }
public List <SpriteRenderer> Display() { int[] arr = new int[9]; List <PosXY> dPosXY = new List <PosXY>() { new PosXY(-1, -1), new PosXY(0, -1), new PosXY(1, -1), new PosXY(-1, 0), new PosXY(0, 0), new PosXY(1, 0), new PosXY(-1, 1), new PosXY(0, 1), new PosXY(1, 1) }; Tile tile = block.Tile; for (int i = 0; i < dPosXY.Count; i++) { PosXY dp = dPosXY[i] + tile.PosXY; Tile tempTile = tile.Board.GetTile(dp.x, dp.y); if (OnCheckType?.Invoke(tempTile) ?? false) { arr[i] = 1; } else { arr[i] = 0; } } return(SetupBorder(arr)); }
public T Spawn <T, TState>(TState state, System.Func <TState, T> constructor, System.Action <T> destructor = null) where T : class { if (Pools.isActive == false) { var instance = constructor.Invoke(state); PoolInternalBaseThread.CallOnSpawn(instance, null); return(instance); } var type = typeof(T); if (this.pool.TryGetValue(type, out var pool) == true) { return((T)pool.Spawn()); } pool = new PoolInternalThread <T, TState>(type, state, constructor, destructor); if (this.pool.TryAdd(type, pool) == true) { return((T)pool.Spawn()); } if (this.pool.TryGetValue(type, out pool) == true) { return((T)pool.Spawn()); } throw new System.Exception("Spawn failed"); }
protected internal override void CopyScriptableObjects(System.Func <ScriptableObject, ScriptableObject> replaceSerializableObject) { connection = replaceSerializableObject.Invoke(connection) as NodeOutput; // Multiple connections // for (int conCnt = 0; conCnt < connections.Count; conCnt++) // connections[conCnt] = replaceSerializableObject.Invoke (connections[conCnt]) as NodeOutput; }
public static void Assert(bool assertion, System.Func <string> errorMessage, Object context = null) { if (!assertion) { Error(errorMessage.Invoke(), context); } }
private void SetAllQuadsColor(System.Func <int, int, int, Color, Color> func) { var voxels = Data.Voxels[CurrentModelIndex]; int len = ContainerTF.childCount; for (int i = 0; i < len; i++) { var voxelTF = ContainerTF.GetChild(i); int vLen = voxelTF.childCount; var pos = voxelTF.localPosition; int x = Mathf.Clamp(Mathf.RoundToInt(pos.x), 0, ModelSize.x - 1); int y = Mathf.Clamp(Mathf.RoundToInt(pos.y), 0, ModelSize.y - 1); int z = Mathf.Clamp(Mathf.RoundToInt(pos.z), 0, ModelSize.z - 1); var color = func.Invoke(x, y, z, Data.GetColorFromPalette(voxels[x, y, z])); // Color bool alpha = color.a < 0.5f; color.a = 1f; for (int j = 0; j < vLen; j++) { var quadTF = voxelTF.GetChild(j); if (!quadTF.gameObject.activeSelf) { continue; } var dir = GetQuadDirection(quadTF); SetQuadToAlpha(quadTF, alpha); var mat = quadTF.GetComponent <MeshRenderer>().sharedMaterial; mat.SetColor(COLOR_SHADER_ID, GetVoxelTintColor(color, dir)); } } }
private void ExecuteError(int errcode, string errmessage) { try { System.Diagnostics.Debug.WriteLine("GeoLocation.ExecuteError"); System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> _func = _funcError as System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>; Jint.Native.Function.ScriptFunctionInstance JintScript = _func.Target as Jint.Native.Function.ScriptFunctionInstance; Jint.Engine _JintEngine = JintScript.Engine; JsValue A = new JsValue(1); JsValue[] B = new Jint.Native.JsValue[1]; Jint.Native.Json.JsonParser _jsp = new Jint.Native.Json.JsonParser(_JintEngine); String FormatString = "{{\"code\":{0}, \"message\":\"{1}\"}}"; String Error = String.Format(FormatString, errcode, errmessage); B[0] = _jsp.Parse(Error); _func.Invoke(A, B); } catch (Exception exp) { System.Diagnostics.Debug.WriteLine("Exception" + exp.Message); } }
private void ExecuteSuccess(Geoposition _pos) { try { System.Diagnostics.Debug.WriteLine("GeoLocation.ExecuteSuccess"); System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> _func = _funcSuccess as System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>; Jint.Native.Function.ScriptFunctionInstance JintScript = _func.Target as Jint.Native.Function.ScriptFunctionInstance; Jint.Engine _JintEngine = JintScript.Engine; JsValue A = new JsValue(1); JsValue[] B = new JsValue[1]; Jint.Native.Json.JsonParser _jsp = new Jint.Native.Json.JsonParser(_JintEngine); String FormatString = "{{\"coords\":{{\"latitude\":{0}, \"longitude\":{1}}}}}"; String Coordinates = String.Format(FormatString, _pos.Coordinate.Latitude, _pos.Coordinate.Longitude); B[0] = _jsp.Parse(Coordinates); _func.Invoke(A, B); } catch (Jint.Runtime.JavaScriptException exc) { System.Diagnostics.Debug.WriteLine("JavaScriptException" + exc.Message + " " + exc.LineNumber); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception" + e.Message); ExecuteError(e.HResult, e.Message); } }
public IAsyncResult <T1> Cast <T1>(System.Func <T, T1> payloadMapper) { var to = new AsyncResult <T1>(this.Error); to.Resolve(payloadMapper.Invoke(this.Payload)); return(to); }
public void Ready() { try { if (!_Pebble.EventListeners.ContainsKey("ready")) { return; } var jsfunction = _Pebble.EventListeners["ready"]; System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> _func = jsfunction as System.Func <Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue>; Jint.Native.JsValue A = new JsValue(1); Jint.Native.JsValue[] B = new Jint.Native.JsValue[1]; Jint.Native.Json.JsonParser _jsp = new Jint.Native.Json.JsonParser(_JintEngine); B[0] = _jsp.Parse("{}"); Jint.Native.JsValue C = _func.Invoke(A, B); } catch (Jint.Runtime.JavaScriptException exp) { String Exception = String.Format("{0}" + Environment.NewLine + "Line: {1}" + Environment.NewLine + "Source: {2}", exp.Message, exp.LineNumber, _JavascriptLines[exp.LineNumber - 1]); throw new System.Exception(Exception); } catch (Exception exp) { throw exp; } }
/// <summary> /// Process every items from this list and returns an array of the results. /// </summary> /// <param name="input">The list to process</param> /// <param name="conversion">The function that will convert this list's elements</param> /// <typeparam name="I">The source list's element type</typeparam> /// <typeparam name="O">The destination array's element type</typeparam> /// <returns></returns> public static O[] Map<I, O>(this List<I> input, System.Func<I, O> conversion) { O[] output = new O[input.Count]; for (int i=0; i<input.Count; i++) output[i] = conversion.Invoke(input[i]); return output; }
static StackObject *Invoke_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 4); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int16 @arg3 = (short)ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Single @arg2 = *(float *)&ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 3); System.Int32 @arg1 = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 4); System.Func <System.Int32, System.Single, System.Int16, System.Double> instance_of_this_method = (System.Func <System.Int32, System.Single, System.Int16, System.Double>) typeof(System.Func <System.Int32, System.Single, System.Int16, System.Double>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Invoke(@arg1, @arg2, @arg3); __ret->ObjectType = ObjectTypes.Double; *(double *)&__ret->Value = result_of_this_method; return(__ret + 1); }
public static T FindReferenceChildren <T>(GameObject root, System.Func <T, bool> callback = null) { var result = default(T); if (root != null) { var list = ListPool <T> .Get(); root.GetComponentsInChildren <T>(true, list); if (list.Count > 0) { if (callback != null) { for (int i = 0; i < list.Count; ++i) { if (callback.Invoke(list[i]) == true) { result = list[i]; break; } } } else { result = list[0]; } } ListPool <T> .Release(list); } return(result); }
/// <summary> /// Graphs a function on screen /// Warning: Produces GC allocs due to the lambda function. /// </summary> /// <param name="graphRect">Rect on screen</param> /// <param name="unitRect">A rect that defines a size of a unit of graph compared to pixels. /// E.g. a 0,0,1,1 unitRect will have it's lower left corner at 0,0 with unit size of 1 pixel. </param> /// <param name="func">A function that takes an 'x' and returns a 'y'</param> public static void Graph(Rect graphRect, Rect unitRect, System.Func <float, float> func) { if (!Drawer.Exists) { return; } float prev = 0; for (int i = 0; i < graphRect.width; i++) { float input = -unitRect.x / unitRect.width + (i / unitRect.width); // z + float v0 = unitRect.y + func.Invoke(input) * unitRect.height; v0 = Mathf.Clamp(v0, 0, graphRect.height); int screeny1 = (int)(graphRect.y + v0); int screeny2 = (int)(graphRect.y + prev); Line( (int)graphRect.x + i, screeny1, (int)graphRect.x + i + 1, screeny2); prev = v0; } }
public void GetReward(string surfacingId, ShowResult showResult, System.Func <AdsData> callAdsData) { switch (showResult) { case ShowResult.Finished: Debug.Log($"Get Reward"); GetReward(); break; case ShowResult.Skipped: Debug.Log($"Skip Reward"); GetReward(); break; case ShowResult.Failed: Debug.LogWarning("The ad did not finish due to an error."); break; default: break; } void GetReward() { AdsDetail _adsDetai = callAdsData.Invoke().SetAdsDetail(surfacingId); Debug.Log($"_currencyDetail: {_adsDetai.currencyReward.eCurrency} --- {_adsDetai.currencyReward.unit} --- {AdsController.presentEAdsReward}"); AdsController.callBackPresentAdsBtn?.Invoke(_adsDetai); } }
public override Assembly Resolve(System.Reflection.MetadataLoadContext context, AssemblyName assemblyName) { Debug.Assert(assemblyName != null); Assembly assembly = func.Invoke(context, assemblyName); return(assembly); }
public static System.ValueTuple <TimeSpan, GenericCollections.List <T> > MeasureTime <T>(System.Func <GenericCollections.IEnumerable <T> > action) { Stopwatch stopwatch = Stopwatch.StartNew(); var result = action.Invoke().ToList(); stopwatch.Stop(); return(System.ValueTuple.Create(stopwatch.Elapsed, result)); }
private static IEnumerator Waiter_INTERNAL(System.Func <bool> waitFor, System.Action callback) { while (waitFor.Invoke() == false) { yield return(null); } callback.Invoke(); }
public bool MoveNext() { if (m_Predicate == null) { return(false); } return(m_Predicate.Invoke()); }
public void OnTriggerEnter(Collider other) { if (_checkTrigger.Invoke(other.gameObject)) { _callBack.Invoke(); Destroy(this.gameObject); } }
/// <summary> /// Threadsafe Invocation of <see cref="System.Action">delegate code</see> returning a value. /// </summary> /// <typeparam name="T">System.Type: The System.Type of the return value.</typeparam> /// <param name="value">The <see cref="System.Windows.Application">Application</see> Current instance.</param> /// <param name="action">System.Func(T): The <see cref="System.Action">delegate code</see>(<see cref="System.Func{TResult}">Func<![CDATA[<T>]]></see>) to execute and return.</param> /// <returns>T: The value returned from the delegate as T.</returns> public static T Invoke <T>(this System.Windows.Application value, System.Func <T> action) { if (value == null || value.Dispatcher == null) { return(action.Invoke()); } return(value.Dispatcher.Invoke <T>(action)); }
bool IsCombatOver() { if (onResultJudge != null) { return(onResultJudge.Invoke() != 0); } return(false); }