mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 08:38:45 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
namespace SRF
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
public static class SRFFloatExtensions
|
||||
{
|
||||
public static float Sqr(this float f)
|
||||
{
|
||||
return f*f;
|
||||
}
|
||||
|
||||
public static float SqrRt(this float f)
|
||||
{
|
||||
return Mathf.Sqrt(f);
|
||||
}
|
||||
|
||||
public static bool ApproxZero(this float f)
|
||||
{
|
||||
return Mathf.Approximately(0, f);
|
||||
}
|
||||
|
||||
public static bool Approx(this float f, float f2)
|
||||
{
|
||||
return Mathf.Approximately(f, f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb221a6020786a841a6f7f1ea19a7eb7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,100 @@
|
||||
namespace SRF
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
public static class SRFGameObjectExtensions
|
||||
{
|
||||
public static T GetIComponent<T>(this GameObject t) where T : class
|
||||
{
|
||||
return t.GetComponent(typeof (T)) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the component T, or add it to the GameObject if none exists
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static T GetComponentOrAdd<T>(this GameObject obj) where T : Component
|
||||
{
|
||||
var t = obj.GetComponent<T>();
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
t = obj.AddComponent<T>();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removed component of type T if it exists on the GameObject
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="obj"></param>
|
||||
public static void RemoveComponentIfExists<T>(this GameObject obj) where T : Component
|
||||
{
|
||||
var t = obj.GetComponent<T>();
|
||||
|
||||
if (t != null)
|
||||
{
|
||||
Object.Destroy(t);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removed components of type T if it exists on the GameObject
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="obj"></param>
|
||||
public static void RemoveComponentsIfExists<T>(this GameObject obj) where T : Component
|
||||
{
|
||||
var t = obj.GetComponents<T>();
|
||||
|
||||
for (var i = 0; i < t.Length; i++)
|
||||
{
|
||||
Object.Destroy(t[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set enabled property MonoBehaviour of type T if it exists
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="enable"></param>
|
||||
/// <returns>True if the component exists</returns>
|
||||
public static bool EnableComponentIfExists<T>(this GameObject obj, bool enable = true) where T : MonoBehaviour
|
||||
{
|
||||
var t = obj.GetComponent<T>();
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
t.enabled = enable;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the layer of a gameobject and all child objects
|
||||
/// </summary>
|
||||
/// <param name="o"></param>
|
||||
/// <param name="layer"></param>
|
||||
public static void SetLayerRecursive(this GameObject o, int layer)
|
||||
{
|
||||
SetLayerInternal(o.transform, layer);
|
||||
}
|
||||
|
||||
private static void SetLayerInternal(Transform t, int layer)
|
||||
{
|
||||
t.gameObject.layer = layer;
|
||||
|
||||
foreach (Transform o in t)
|
||||
{
|
||||
SetLayerInternal(o, layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57a08f4d800e4384fac80b0ecf63a7a0
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace SRF
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class SRFIListExtensions
|
||||
{
|
||||
public static T Random<T>(this IList<T> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
throw new IndexOutOfRangeException("List needs at least one entry to call Random()");
|
||||
}
|
||||
|
||||
if (list.Count == 1)
|
||||
{
|
||||
return list[0];
|
||||
}
|
||||
|
||||
return list[UnityEngine.Random.Range(0, list.Count)];
|
||||
}
|
||||
|
||||
public static T RandomOrDefault<T>(this IList<T> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return list.Random();
|
||||
}
|
||||
|
||||
public static T PopLast<T>(this IList<T> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var t = list[list.Count - 1];
|
||||
|
||||
list.RemoveAt(list.Count - 1);
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c196b9d1bba9e9e44939cf8776545577
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
#if NETFX_CORE
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SRF
|
||||
{
|
||||
|
||||
public static class NetFxExtensions
|
||||
{
|
||||
|
||||
|
||||
public static bool IsAssignableFrom(this Type @this, Type t)
|
||||
{
|
||||
|
||||
return @this.GetTypeInfo().IsAssignableFrom(t.GetTypeInfo());
|
||||
|
||||
}
|
||||
|
||||
public static bool IsInstanceOfType(this Type @this, object obj)
|
||||
{
|
||||
|
||||
return @this.IsAssignableFrom(obj.GetType());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f503b1a2564101f4f96417c97debaaf5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace SRF
|
||||
{
|
||||
public static class SRFStringExtensions
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[JetBrains.Annotations.StringFormatMethod("formatString")]
|
||||
#endif
|
||||
public static string Fmt(this string formatString, params object[] args)
|
||||
{
|
||||
return string.Format(formatString, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71e45638ff7335744a6554752b778f39
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,91 @@
|
||||
namespace SRF
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class SRFTransformExtensions
|
||||
{
|
||||
public static IEnumerable<Transform> GetChildren(this Transform t)
|
||||
{
|
||||
var i = 0;
|
||||
|
||||
while (i < t.childCount)
|
||||
{
|
||||
yield return t.GetChild(i);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset all local values on a transform to identity
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
public static void ResetLocal(this Transform t)
|
||||
{
|
||||
t.localPosition = Vector3.zero;
|
||||
t.localRotation = Quaternion.identity;
|
||||
t.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty child object of this transform
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static GameObject CreateChild(this Transform t, string name)
|
||||
{
|
||||
var go = new GameObject(name);
|
||||
go.transform.parent = t;
|
||||
go.transform.ResetLocal();
|
||||
go.gameObject.layer = t.gameObject.layer;
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the parent of this transform, but maintain the localScale, localPosition, localRotation values.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="parent"></param>
|
||||
public static void SetParentMaintainLocals(this Transform t, Transform parent)
|
||||
{
|
||||
t.SetParent(parent, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy local position,rotation,scale from other transform
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="from"></param>
|
||||
public static void SetLocals(this Transform t, Transform from)
|
||||
{
|
||||
t.localPosition = from.localPosition;
|
||||
t.localRotation = from.localRotation;
|
||||
t.localScale = from.localScale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set position/rotation to from. Scale is unchanged
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="from"></param>
|
||||
public static void Match(this Transform t, Transform from)
|
||||
{
|
||||
t.position = from.position;
|
||||
t.rotation = from.rotation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy all child game objects
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
public static void DestroyChildren(this Transform t)
|
||||
{
|
||||
foreach (var child in t)
|
||||
{
|
||||
Object.Destroy(((Transform) child).gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 891f8206d8bca304fbbf298c6a37648e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user