mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
remove some unused files/code
This commit is contained in:
parent
54144bf56a
commit
4ab78a9a7d
19 changed files with 2 additions and 998 deletions
|
@ -131,7 +131,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
|
|||
public static Vector3 GetMoveDestinationBasedOnTargetNode(PathNode targetNode)
|
||||
{
|
||||
Vector2 offset = Random.insideUnitCircle * targetNode.PathWidth / 2f * 0.9f;
|
||||
return targetNode.Position + offset.ToVector3XZ();
|
||||
return targetNode.Position + offset.ToVec3XZ();
|
||||
}
|
||||
|
||||
public static void FindClosestWalkableNode(PathMovementData pathMovementData, Vector3 position, float radius = 200f)
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
transformData = new TransformDataStruct(focusPos);
|
||||
else
|
||||
transformData = new TransformDataStruct(
|
||||
focusPos.position + Random.insideUnitCircle.ToVector3XZ() * 15f,
|
||||
focusPos.position + Random.insideUnitCircle.ToVec3XZ() * 15f,
|
||||
Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace System.Collections.Generic
|
||||
{
|
||||
public static class ListEx
|
||||
{
|
||||
public static void RemoveRangeWrapped<T>(this List<T> list, int index, int count)
|
||||
{
|
||||
int itemCount = list.Count;
|
||||
|
||||
if (count == 0 || itemCount == 0) return;
|
||||
|
||||
if (count >= itemCount)
|
||||
{
|
||||
list.Clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int removeIndex = index;
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
removeIndex += count;
|
||||
count = -count;
|
||||
}
|
||||
|
||||
removeIndex = removeIndex.Mod(itemCount);
|
||||
int backCount = count - (itemCount - removeIndex);
|
||||
|
||||
if (backCount <= 0)
|
||||
{
|
||||
list.RemoveRange(removeIndex, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.RemoveRange(removeIndex, count - backCount);
|
||||
list.RemoveRange(0, backCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetOffsetIndex<T>(this List<T> list, int index, int offset)
|
||||
{
|
||||
// wrap around the offsetted index
|
||||
return (index + offset).Mod(list.Count);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 189c40774a2f860438db988b236ecfd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 9750
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,159 +0,0 @@
|
|||
namespace UnityEngine
|
||||
{
|
||||
public static class MathExtension
|
||||
{
|
||||
public static float SnapToCenter(this float val, float snapValue)
|
||||
{
|
||||
if (snapValue == 0) return val;
|
||||
|
||||
return Mathf.Round((val / snapValue) + 0.5f) * snapValue - 0.5f;
|
||||
}
|
||||
|
||||
public static float SnapToEdge(this float val, float snapValue)
|
||||
{
|
||||
if (snapValue == 0) return val;
|
||||
|
||||
return Mathf.Round(val / snapValue) * snapValue;
|
||||
}
|
||||
|
||||
public static Vector3 SnapToCenter(this Vector2 val, float snapValue)
|
||||
{
|
||||
return new Vector2(val.x.SnapToCenter(snapValue), val.y.SnapToCenter(snapValue));
|
||||
}
|
||||
|
||||
public static Vector3 SnapToEdge(this Vector2 val, float snapValue)
|
||||
{
|
||||
return new Vector2(val.x.SnapToEdge(snapValue), val.y.SnapToEdge(snapValue));
|
||||
}
|
||||
|
||||
public static Vector3 SnapToCenter(this Vector3 val, float snapValue)
|
||||
{
|
||||
return new Vector3(val.x.SnapToCenter(snapValue), val.y.SnapToCenter(snapValue), val.z.SnapToCenter(snapValue));
|
||||
}
|
||||
|
||||
public static Vector3 SnapToEdge(this Vector3 val, float snapValue)
|
||||
{
|
||||
return new Vector3(val.x.SnapToEdge(snapValue), val.y.SnapToEdge(snapValue), val.z.SnapToEdge(snapValue));
|
||||
}
|
||||
|
||||
public static Vector3 ToVector3XZ(this Vector2 val)
|
||||
{
|
||||
return new Vector3(val.x, 0.0f, val.y);
|
||||
}
|
||||
|
||||
public static float ClosestPointDistance(this Ray val, Vector3 point)
|
||||
{
|
||||
return Vector3.Dot(point - val.origin, val.direction);
|
||||
}
|
||||
|
||||
public static Vector3 ClosestPoint(this Ray val, Vector3 point)
|
||||
{
|
||||
return val.GetPoint(val.ClosestPointDistance(point));
|
||||
}
|
||||
|
||||
public static float ClosestRayPointDistance(this Ray val, Ray ray)
|
||||
{
|
||||
Vector3 v0 = val.origin;
|
||||
Vector3 v1 = val.direction;
|
||||
Vector3 v2 = ray.origin;
|
||||
Vector3 v3 = ray.direction;
|
||||
Vector3 v4 = v0 - v2;
|
||||
|
||||
float d0 = 0.0f;
|
||||
float d1 = 0.0f;
|
||||
|
||||
float dv4v3 = Vector3.Dot(v4, v3);
|
||||
float dv3v1 = Vector3.Dot(v3, v1);
|
||||
float dv3v3 = Vector3.Dot(v3, v3);
|
||||
float dv4v1 = Vector3.Dot(v4, v1);
|
||||
float dv1v1 = Vector3.Dot(v1, v1);
|
||||
|
||||
float denom = dv1v1 * dv3v3 - dv3v1 * dv3v1;
|
||||
|
||||
if (Mathf.Abs(denom) > Mathf.Epsilon)
|
||||
{
|
||||
float numer = dv4v3 * dv3v1 - dv4v1 * dv3v3;
|
||||
d0 = numer / denom;
|
||||
}
|
||||
else
|
||||
{
|
||||
d0 = 0.0f;
|
||||
}
|
||||
|
||||
d1 = (dv4v3 + d0 * dv3v1) / dv3v3;
|
||||
|
||||
if (d1 >= 0.0f)
|
||||
{
|
||||
return d0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d1 = 0.0f;
|
||||
|
||||
return val.ClosestPointDistance(ray.origin);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 ClosestRayPoint(this Ray val, Ray ray)
|
||||
{
|
||||
return val.GetPoint(val.ClosestRayPointDistance(ray));
|
||||
}
|
||||
|
||||
public static int Mod(this int val, int mod)
|
||||
{
|
||||
int r = val % mod;
|
||||
|
||||
return r < 0 ? val + mod : r;
|
||||
}
|
||||
|
||||
public static bool PlaneTest(this Ray ray, Vector3 planeCenter, Quaternion planeRot, Vector2 planeSize, out Vector3 hitPosition, float gridSize = 0.0f, bool edge = true)
|
||||
{
|
||||
Plane plane = new Plane(planeRot * Vector3.up, planeCenter);
|
||||
|
||||
hitPosition = Vector3.zero;
|
||||
float hitDistance = 0.0f;
|
||||
|
||||
if (!plane.Raycast(ray, out hitDistance))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
hitPosition = ray.origin + ray.direction * hitDistance;
|
||||
|
||||
Vector3 hitOffset = hitPosition - planeCenter;
|
||||
|
||||
float distanceLf = Vector3.Dot(hitOffset, planeRot * Vector3.left);
|
||||
float distanceUp = Vector3.Dot(hitOffset, planeRot * Vector3.forward);
|
||||
|
||||
if (gridSize > 0.0f)
|
||||
{
|
||||
if (edge)
|
||||
{
|
||||
distanceLf = distanceLf.SnapToEdge(gridSize);
|
||||
distanceUp = distanceUp.SnapToEdge(gridSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
distanceLf = distanceLf.SnapToCenter(gridSize);
|
||||
distanceUp = distanceUp.SnapToCenter(gridSize);
|
||||
}
|
||||
}
|
||||
|
||||
hitPosition = planeCenter;
|
||||
hitPosition += (planeRot * Vector3.left) * distanceLf;
|
||||
hitPosition += (planeRot * Vector3.forward) * distanceUp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static float NormalizeAngle(this float ang)
|
||||
{
|
||||
return ang - Mathf.Floor((ang + 180f) / 360f) * 360f;
|
||||
}
|
||||
|
||||
public static float AngleDiff(this float ang, float other)
|
||||
{
|
||||
return (other - ang).NormalizeAngle();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 287aac3d791d8b245816760000716a6e
|
||||
timeCreated: 1427296668
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,374 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
//using Facepunch.ConCommands;
|
||||
//using Facepunch.Networking;
|
||||
using UnityEngine;
|
||||
using ThreadState = System.Threading.ThreadState;
|
||||
|
||||
namespace Facepunch.Utilities
|
||||
{
|
||||
public interface IGateKeeper : IDisposable
|
||||
{
|
||||
object Owner { get; }
|
||||
String Name { get; }
|
||||
int Counter { get; }
|
||||
|
||||
IDisposable Sample();
|
||||
}
|
||||
|
||||
public class PerformanceSampler : SingletonComponent<PerformanceSampler>
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
|
||||
/// <remarks>
|
||||
/// http://stackoverflow.com/questions/285031/how-to-get-non-current-threads-stacktrace
|
||||
/// </remarks>
|
||||
private static StackTrace GetStackTrace(Thread targetThread, out Exception error)
|
||||
{
|
||||
var suspend = targetThread.ThreadState != ThreadState.Suspended;
|
||||
error = null;
|
||||
|
||||
StackTrace stackTrace = null;
|
||||
|
||||
Exception ex = null;
|
||||
|
||||
if (suspend)
|
||||
{
|
||||
var ready = new ManualResetEvent(false);
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
// Backstop to release thread in case of deadlock:
|
||||
ready.Set();
|
||||
Thread.Sleep(200);
|
||||
try
|
||||
{
|
||||
targetThread.Resume();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ex = e;
|
||||
}
|
||||
}).Start();
|
||||
|
||||
ready.WaitOne();
|
||||
targetThread.Suspend();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
stackTrace = new StackTrace(targetThread, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error = e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (suspend)
|
||||
{
|
||||
try
|
||||
{
|
||||
targetThread.Resume();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error = error ?? e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error = error ?? ex;
|
||||
|
||||
return stackTrace;
|
||||
}
|
||||
|
||||
#pragma warning restore 0618
|
||||
|
||||
/* [ConCommand(Domain.Shared, "system", "status")]
|
||||
private static String SystemStatusCommand(ConCommandArgs args)
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
writer.WriteLine("Uptime: {0:F1} minutes", Instance.Uptime.TotalMinutes);
|
||||
writer.WriteLine("Processor time: {0:F1}%", Instance.ProcessorTimePercent);
|
||||
writer.WriteLine("Total memory: {0:F1} KB", Instance.TotalMemory / 1024d);
|
||||
writer.WriteLine("Avg GC period: {0:F2} s", Instance.AverageGarbageCollectionPeriod);
|
||||
writer.WriteLine("Network status: {0}", Server.Instance.NetStatus);
|
||||
writer.WriteLine("Network thread status: {0}", Server.Instance.Net.NetThread.ThreadState);
|
||||
writer.WriteLine("Main thread state: {0}", Instance.MainThreadState);
|
||||
|
||||
if (!(Instance.SinceLastUpdate.TotalSeconds > 2d * Instance.SamplePeriod)) return writer.ToString();
|
||||
|
||||
writer.WriteLine("Main thread has been hanging for {0:F1} minutes!", Instance.SinceLastUpdate.TotalMinutes);
|
||||
|
||||
return writer.ToString();
|
||||
}
|
||||
|
||||
[ConCommand(Domain.Shared, "system", "gate-keepers")]
|
||||
private static String SystemGateKeepersCommand(ConCommandArgs args)
|
||||
{
|
||||
var writer = new StringWriter();
|
||||
|
||||
foreach (var gateKeeper in GateKeepers) {
|
||||
writer.WriteLine("Owner: {0}, Name: {1}, Count: {2}", gateKeeper.Owner, gateKeeper.Name, gateKeeper.Counter);
|
||||
}
|
||||
|
||||
return writer.ToString();
|
||||
}
|
||||
*/
|
||||
|
||||
private class GateKeeper : IGateKeeper
|
||||
{
|
||||
private class Sampler : IDisposable
|
||||
{
|
||||
private readonly GateKeeper _keeper;
|
||||
|
||||
public Sampler(GateKeeper keeper)
|
||||
{
|
||||
_keeper = keeper;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
--_keeper.Counter;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Sampler _sampler;
|
||||
|
||||
public object Owner { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public int Counter { get; private set; }
|
||||
|
||||
public GateKeeper(object owner, String name)
|
||||
{
|
||||
_sampler = new Sampler(this);
|
||||
|
||||
Owner = owner;
|
||||
Name = name;
|
||||
Counter = 0;
|
||||
}
|
||||
|
||||
public IDisposable Sample()
|
||||
{
|
||||
++Counter;
|
||||
return _sampler;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_sGateKeepers.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly List<GateKeeper> _sGateKeepers = new List<GateKeeper>();
|
||||
|
||||
public static IEnumerable<IGateKeeper> GateKeepers { get { return _sGateKeepers.Cast<IGateKeeper>(); } }
|
||||
|
||||
public static IGateKeeper CreateGatekeeper(object owner, String name)
|
||||
{
|
||||
var keeper = new GateKeeper(owner, name);
|
||||
_sGateKeepers.Add(keeper);
|
||||
return keeper;
|
||||
}
|
||||
|
||||
private readonly DateTime _startTime;
|
||||
|
||||
private DateTime _lastUpdate;
|
||||
private TimeSpan _lastProcessorTime;
|
||||
private DateTime _lastGcPass;
|
||||
private int _lastGcPasses;
|
||||
|
||||
private Thread _mainThread;
|
||||
private Thread _watcherThread;
|
||||
|
||||
private bool _stopWatching;
|
||||
|
||||
private readonly AutoResetEvent _sampleWait;
|
||||
private readonly ManualResetEvent _stopWait;
|
||||
|
||||
private readonly Queue<double> _gcPeriods = new Queue<double>();
|
||||
|
||||
private readonly Stopwatch _timer = new Stopwatch();
|
||||
|
||||
public TimeSpan Uptime
|
||||
{
|
||||
get { return DateTime.UtcNow - _startTime; }
|
||||
}
|
||||
|
||||
public ThreadState MainThreadState
|
||||
{
|
||||
get { return _mainThread == null ? ThreadState.Unstarted : _mainThread.ThreadState; }
|
||||
}
|
||||
|
||||
public TimeSpan SinceLastUpdate
|
||||
{
|
||||
get { return DateTime.UtcNow - _lastUpdate; }
|
||||
}
|
||||
|
||||
public double ProcessorTimePercent { get; private set; }
|
||||
|
||||
public double AverageGarbageCollectionPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gcPeriods.Count == 0
|
||||
? float.PositiveInfinity
|
||||
: (_gcPeriods.Sum() + (DateTime.UtcNow - _lastGcPass).TotalSeconds)
|
||||
/ (_gcPeriods.Count + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public long TotalMemory { get; private set; }
|
||||
|
||||
[Range(1f, 60f)]
|
||||
public float SamplePeriod = 2f;
|
||||
|
||||
[Range(1, 200)]
|
||||
public int GarbageCollectionSamples = 10;
|
||||
|
||||
public PerformanceSampler()
|
||||
{
|
||||
_startTime = _lastGcPass = DateTime.UtcNow;
|
||||
|
||||
_sampleWait = new AutoResetEvent(false);
|
||||
_stopWait = new ManualResetEvent(true);
|
||||
|
||||
Sample(false);
|
||||
}
|
||||
|
||||
private static void SampleFailed()
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat("!!! PerformanceSampler has failed to sample (time: {0}) !!!", DateTime.UtcNow);
|
||||
// UnityEngine.Debug.LogFormat("HangNotifyUrl: {0}", NetConfig.HangNotifyUrl);
|
||||
|
||||
/*
|
||||
if (String.IsNullOrEmpty(NetConfig.HangNotifyUrl)) return;
|
||||
|
||||
using (var client = new WebClient()) {
|
||||
client.UploadString(NetConfig.HangNotifyUrl, "POST", new JObject {
|
||||
{"status", "hanging"},
|
||||
{"time", DateTime.UtcNow.ToBinary()},
|
||||
{"last_state", SystemStatusCommand(null)},
|
||||
{"port", NetConfig.Port}
|
||||
}.ToString());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void WatcherEntry()
|
||||
{
|
||||
_stopWait.Reset();
|
||||
|
||||
while (!_stopWatching)
|
||||
{
|
||||
if (_sampleWait.WaitOne(TimeSpan.FromSeconds(SamplePeriod * 2d + 10d))) continue;
|
||||
if (_stopWatching) return;
|
||||
SampleFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
_stopWait.Set();
|
||||
}
|
||||
|
||||
private void Sample(bool watch)
|
||||
{
|
||||
if (watch && _watcherThread == null)
|
||||
{
|
||||
_watcherThread = new Thread(WatcherEntry);
|
||||
_watcherThread.Start();
|
||||
}
|
||||
|
||||
if (_mainThread == null) _mainThread = Thread.CurrentThread;
|
||||
|
||||
_lastUpdate = DateTime.UtcNow;
|
||||
_sampleWait.Set();
|
||||
|
||||
var diff = _timer.Elapsed.TotalSeconds;
|
||||
|
||||
var proc = Process.GetCurrentProcess();
|
||||
|
||||
var processorTime = proc.TotalProcessorTime;
|
||||
var gcPasses = GC.CollectionCount(0);
|
||||
var gcPassDiff = gcPasses - _lastGcPasses;
|
||||
|
||||
_lastGcPasses = gcPasses;
|
||||
|
||||
if (gcPassDiff > 0)
|
||||
{
|
||||
var gcTimeDiff = _lastUpdate - _lastGcPass;
|
||||
|
||||
if (gcPassDiff == 1)
|
||||
{
|
||||
_gcPeriods.Enqueue(gcTimeDiff.TotalSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
var avg = diff / (gcPassDiff - 1) + (gcTimeDiff.TotalSeconds - diff);
|
||||
for (var i = 0; i < gcPassDiff; ++i)
|
||||
{
|
||||
_gcPeriods.Enqueue(avg);
|
||||
}
|
||||
}
|
||||
|
||||
_lastGcPass = _lastUpdate;
|
||||
|
||||
while (_gcPeriods.Count > GarbageCollectionSamples)
|
||||
{
|
||||
_gcPeriods.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
TotalMemory = GC.GetTotalMemory(false);
|
||||
|
||||
var processorTimeDiff = processorTime.Subtract(_lastProcessorTime);
|
||||
|
||||
ProcessorTimePercent = (float)((processorTimeDiff.TotalSeconds * 100d / Environment.ProcessorCount) / diff);
|
||||
|
||||
_lastProcessorTime = processorTime;
|
||||
|
||||
_timer.Reset();
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public StackTrace GetMainThreadStackTrace(out Exception ex)
|
||||
{
|
||||
if (_mainThread.ThreadState == ThreadState.Stopped)
|
||||
{
|
||||
ex = new Exception("Thread stopped");
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetStackTrace(_mainThread, out ex);
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
private void Update()
|
||||
{
|
||||
if (!(_timer.Elapsed.TotalSeconds > SamplePeriod)) return;
|
||||
|
||||
Sample(true);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
UnityEngine.Debug.Log("Destroying PerformanceSampler");
|
||||
|
||||
_stopWatching = true;
|
||||
_sampleWait.Set();
|
||||
|
||||
if (_watcherThread != null && !_stopWait.WaitOne(1000))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning("Timeout while stopping watcher thread!");
|
||||
_watcherThread.Abort();
|
||||
}
|
||||
|
||||
_watcherThread = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a98e98d51707b164eb99d6aa73952dfc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 8800
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,25 +0,0 @@
|
|||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityEngine
|
||||
{
|
||||
public static class RectTransformEx
|
||||
{
|
||||
private static readonly Vector3[] _sCorners = new Vector3[4];
|
||||
|
||||
public static Vector2 GetWorldSize(this RectTransform trans)
|
||||
{
|
||||
trans.GetWorldCorners(_sCorners);
|
||||
return new Vector2(_sCorners.Max(x => x.x) - _sCorners.Min(x => x.x), _sCorners.Max(x => x.y) - _sCorners.Min(x => x.y));
|
||||
}
|
||||
|
||||
public static float GetPreferredTextHeight(this RectTransform trans, Text text)
|
||||
{
|
||||
if (text == null) return 0;
|
||||
|
||||
var settings = text.GetGenerationSettings(new Vector2(trans.rect.size.x, 0.0f));
|
||||
|
||||
return text.cachedTextGeneratorForLayout.GetPreferredHeight(text.text, settings) / text.pixelsPerUnit;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 524199494ffd4ff45acb452bf109b95a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 11000
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,43 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Reflection
|
||||
{
|
||||
public static class ReflectionEx
|
||||
{
|
||||
public static bool Matches(this MethodInfo method, MethodInfo delegateInfo)
|
||||
{
|
||||
if (!delegateInfo.ReturnType.IsAssignableFrom(method.ReturnType)) return false;
|
||||
|
||||
var mParams = method.GetParameters();
|
||||
var dParams = delegateInfo.GetParameters();
|
||||
|
||||
if (mParams.Length != dParams.Length) return false;
|
||||
|
||||
for (var i = 0; i < mParams.Length; ++i)
|
||||
{
|
||||
if (!dParams[i].ParameterType.IsAssignableFrom(mParams[i].ParameterType)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HasAttribute<TAttribute>(this ICustomAttributeProvider obj, bool inherit)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return obj.GetCustomAttributes(typeof(TAttribute), inherit).Any();
|
||||
}
|
||||
|
||||
public static TAttribute GetAttribute<TAttribute>(this ICustomAttributeProvider obj, bool inherit)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return (TAttribute)obj.GetCustomAttributes(typeof(TAttribute), inherit).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this ICustomAttributeProvider obj, bool inherit)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return obj.GetCustomAttributes(typeof(TAttribute), inherit).Cast<TAttribute>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 226e18327cacf9e499983b493038a46d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 6500
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,35 +0,0 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace UnityEngine
|
||||
{
|
||||
public abstract class SingletonComponent<TComponent> : MonoBehaviour
|
||||
where TComponent : SingletonComponent<TComponent>
|
||||
{
|
||||
private static TComponent _sInstance;
|
||||
|
||||
public static TComponent Instance
|
||||
{
|
||||
get { return _sInstance ?? (_sInstance = FindObjectOfType<TComponent>()); }
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
private void Awake()
|
||||
{
|
||||
if (FindObjectsOfType<TComponent>().Any(x => x != this && x.isActiveAndEnabled))
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
}
|
||||
|
||||
_sInstance = (TComponent)this;
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
OnAwake();
|
||||
}
|
||||
|
||||
protected virtual void OnAwake()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ce94c97eec14504599707f5bafd37bd
|
||||
timeCreated: 1427296668
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,28 +0,0 @@
|
|||
#if STEAM
|
||||
|
||||
using Steamworks;
|
||||
|
||||
namespace Facepunch.Steam
|
||||
{
|
||||
public static class SteamEx
|
||||
{
|
||||
public static string Format(this CSteamID steamID)
|
||||
{
|
||||
if (steamID.GetEAccountType() == EAccountType.k_EAccountTypeInvalid ||
|
||||
steamID.GetEAccountType() == EAccountType.k_EAccountTypeIndividual) {
|
||||
uint accountID = steamID.GetAccountID().m_AccountID;
|
||||
|
||||
if (steamID.GetEUniverse() <= EUniverse.k_EUniversePublic) {
|
||||
return string.Format("STEAM_0:{0}:{1}", accountID & 1, accountID >> 1);
|
||||
} else {
|
||||
return string.Format("STEAM_{2}:{0}:{1}", accountID & 1, accountID >> 1,
|
||||
(int) steamID.GetEUniverse());
|
||||
}
|
||||
} else {
|
||||
return steamID.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e9e8f28de69d7b4b911f327eef3c58f
|
||||
timeCreated: 1427296668
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,62 +0,0 @@
|
|||
namespace System.IO
|
||||
{
|
||||
public static class StreamEx
|
||||
{
|
||||
public static void Clear(this Stream stream)
|
||||
{
|
||||
stream.Reset();
|
||||
stream.SetLength(0);
|
||||
}
|
||||
|
||||
public static void Reset(this Stream stream)
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
public static Stream ClearWriteReset(this Stream stream, Action<Stream> write)
|
||||
{
|
||||
stream.Clear();
|
||||
write(stream);
|
||||
stream.Reset();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static Stream ClearWriteReset(this Stream stream, byte[] contents)
|
||||
{
|
||||
stream.Clear();
|
||||
stream.Write(contents, 0, contents.Length);
|
||||
stream.Reset();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
private const int DefaultCopyBufferSize = 2048;
|
||||
|
||||
public static void CopyTo(this Stream from, Stream dest, byte[] buffer = null)
|
||||
{
|
||||
buffer = buffer ?? new byte[DefaultCopyBufferSize];
|
||||
var bufferSize = buffer.Length;
|
||||
|
||||
int read;
|
||||
while ((read = from.Read(buffer, 0, bufferSize)) > 0)
|
||||
{
|
||||
dest.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyTo(this Stream from, Stream dest, int length, byte[] buffer = null)
|
||||
{
|
||||
buffer = buffer ?? new byte[DefaultCopyBufferSize];
|
||||
var bufferSize = buffer.Length;
|
||||
|
||||
int toRead, read, total = 0;
|
||||
while ((toRead = Math.Min(length - total, bufferSize)) > 0
|
||||
&& (read = from.Read(buffer, 0, toRead)) > 0)
|
||||
{
|
||||
dest.Write(buffer, 0, read);
|
||||
total += read;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2baba2a845843584696d7762a9b2ba3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 10500
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -18,97 +18,6 @@ namespace UnityEngine
|
|||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// Get all of the children in this transform, recursively
|
||||
//
|
||||
public static List<Transform> GetAllChildren(this Transform transform)
|
||||
{
|
||||
var list = new List<Transform>();
|
||||
transform.AddAllChildren(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
//
|
||||
// Add all of the children in this transform to this list
|
||||
//
|
||||
public static void AddAllChildren(this Transform transform, List<Transform> list)
|
||||
{
|
||||
list.Add(transform);
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
transform.GetChild(i).AddAllChildren(list);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Return all children with the specified tag
|
||||
//
|
||||
public static Transform[] GetChildrenWithTag(this Transform transform, string strTag)
|
||||
{
|
||||
var children = GetAllChildren(transform);
|
||||
return children.Where(x => x.CompareTag(strTag)).ToArray();
|
||||
}
|
||||
|
||||
//
|
||||
// Set local position and rotation to 0
|
||||
//
|
||||
public static void Identity(this GameObject go)
|
||||
{
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
go.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
//
|
||||
// Create an empty child
|
||||
//
|
||||
public static GameObject CreateChild(this GameObject go)
|
||||
{
|
||||
var child = new GameObject();
|
||||
child.transform.parent = go.transform;
|
||||
child.Identity();
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
//
|
||||
// Create an empty child
|
||||
//
|
||||
public static GameObject CreateChild(this GameObject go, string name)
|
||||
{
|
||||
var child = new GameObject(name);
|
||||
child.transform.parent = go.transform;
|
||||
child.Identity();
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a prefab as a child of this game object
|
||||
//
|
||||
public static GameObject InstantiateChild(this GameObject go, GameObject prefab)
|
||||
{
|
||||
var child = GameObject.Instantiate(prefab) as GameObject;
|
||||
child.transform.parent = go.transform;
|
||||
child.Identity();
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a prefab as a child of this game object
|
||||
//
|
||||
public static GameObject InstantiateChild(this GameObject go, GameObject prefab, string name)
|
||||
{
|
||||
var child = InstantiateChild(go, prefab);
|
||||
child.name = name;
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
//
|
||||
// Change the layer of every object on this mother fucker
|
||||
//
|
||||
public static void SetLayerRecursive(this GameObject go, int Layer)
|
||||
{
|
||||
go.layer = Layer;
|
||||
|
@ -119,9 +28,6 @@ namespace UnityEngine
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Change the layer of every object on this mother fucker
|
||||
//
|
||||
public static void SetLayerRecursive(this GameObject go, string layer)
|
||||
{
|
||||
var layerint = LayerMask.NameToLayer(layer);
|
||||
|
@ -133,42 +39,5 @@ namespace UnityEngine
|
|||
|
||||
go.SetLayerRecursive(layerint);
|
||||
}
|
||||
|
||||
//
|
||||
// Invoke in x seconds, but only if we're not already invoking
|
||||
//
|
||||
public static void InvokeAtomic(this MonoBehaviour mb, string strName, float fDelay)
|
||||
{
|
||||
UnityEngine.Profiling.Profiler.BeginSample("InvokeAtomic");
|
||||
|
||||
if (!mb.IsInvoking(strName))
|
||||
{
|
||||
mb.Invoke(strName, fDelay);
|
||||
}
|
||||
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
}
|
||||
|
||||
//
|
||||
// Returns a Bounds object of this object and all of its children's renderers (apart from particle systems)
|
||||
//
|
||||
public static Bounds WorkoutRenderBounds(this Transform tx)
|
||||
{
|
||||
Bounds b = new Bounds(Vector3.zero, Vector3.zero);
|
||||
|
||||
var renderers = tx.GetComponentsInChildren<Renderer>();
|
||||
foreach (var r in renderers)
|
||||
{
|
||||
//if (r is ParticleRenderer) continue; // no longer available in newer versions of Unity
|
||||
if (r is ParticleSystemRenderer) continue;
|
||||
|
||||
if (b.center == Vector3.zero)
|
||||
b = r.bounds;
|
||||
else
|
||||
b.Encapsulate(r.bounds);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue