mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-04-15 20:42:33 +00:00
deterministic path
This commit is contained in:
parent
e3003bb475
commit
ad97f879ee
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@ -45,6 +46,23 @@ namespace QSB.Utility
|
||||
public static void SpawnWithServerAuthority(this GameObject go) =>
|
||||
NetworkServer.Spawn(go, NetworkServer.localConnection);
|
||||
|
||||
public static string DeterministicPath(this Component component)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var transform = component.transform;
|
||||
while (transform.parent)
|
||||
{
|
||||
sb.Append(transform.GetSiblingIndex());
|
||||
transform = transform.parent;
|
||||
}
|
||||
|
||||
sb.Append(transform.name);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static IEnumerable<T> SortDeterministic<T>(this IEnumerable<T> components) where T : Component
|
||||
=> components.OrderBy(DeterministicPath);
|
||||
|
||||
#endregion
|
||||
|
||||
#region C#
|
||||
|
Loading…
x
Reference in New Issue
Block a user