框架上传

This commit is contained in:
2025-03-31 11:16:52 +08:00
parent 7197b4c0d0
commit ffcdddbd2a
429 changed files with 19115 additions and 1579 deletions

View File

@@ -0,0 +1,230 @@
using Stary.Evo;
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Object", 0)]
[APIDescriptionCN("针对 UnityEngine.Object 提供的链式扩展")]
[APIDescriptionEN("The chain extension provided by UnityEngine.Object")]
[APIExampleCode(@"
var gameObject = new GameObject();
//
gameObject.Instantiate()
.Name(""ExtensionExample"")
.DestroySelf();
//
gameObject.Instantiate()
.DestroySelfGracefully();
//
gameObject.Instantiate()
.DestroySelfAfterDelay(1.0f);
//
gameObject.Instantiate()
.DestroySelfAfterDelayGracefully(1.0f);
//
gameObject
.Self(selfObj => Debug.Log(selfObj.name))
.Name(""TestObj"")
.Self(selfObj => Debug.Log(selfObj.name))
.Name(""ExtensionExample"")
.DontDestroyOnLoad();
")]
#endif
public static class UnityEngineObjectExtension
{
#if UNITY_EDITOR
// v1 No.37
[MethodAPI]
[APIDescriptionCN("Object.Instantiate(Object) 的简单链式封装")]
[APIDescriptionEN("Object.Instantiate(Object) extension")]
[APIExampleCode(@"
prefab.Instantiate();
")]
#endif
public static T Instantiate<T>(this T selfObj) where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate(selfObj);
}
#if UNITY_EDITOR
// v1 No.38
[MethodAPI]
[APIDescriptionCN("Object.Instantiate(Object,Vector3,Quaternion) 的简单链式封装")]
[APIDescriptionEN("Object.Instantiate(Object,Vector3,Quaternion) extension")]
[APIExampleCode(@"
prefab.Instantiate(Vector3.zero,Quaternion.identity);
")]
#endif
public static T Instantiate<T>(this T selfObj, Vector3 position, Quaternion rotation)
where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate(selfObj, position, rotation);
}
#if UNITY_EDITOR
// v1 No.39
[MethodAPI]
[APIDescriptionCN("Object.Instantiate(Object,Vector3,Quaternion,Transform parent) 的简单链式封装")]
[APIDescriptionEN("Object.Instantiate(Object,Vector3,Quaternion,Transform parent) extension")]
[APIExampleCode(@"
prefab.Instantiate(Vector3.zero,Quaternion.identity,transformRoot);
")]
#endif
public static T Instantiate<T>(
this T selfObj,
Vector3 position,
Quaternion rotation,
Transform parent)
where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate(selfObj, position, rotation, parent);
}
#if UNITY_EDITOR
// v1 No.40
[MethodAPI]
[APIDescriptionCN("Object.Instantiate(Transform parent,bool worldPositionStays) 的简单链式封装")]
[APIDescriptionEN("Object.Instantiate(Transform parent,bool worldPositionStays) extension")]
[APIExampleCode(@"
prefab.Instantiate(transformRoot,true);
")]
#endif
public static T InstantiateWithParent<T>(this T selfObj, Transform parent, bool worldPositionStays)
where T : UnityEngine.Object
{
return (T)UnityEngine.Object.Instantiate((UnityEngine.Object)selfObj, parent, worldPositionStays);
}
public static T InstantiateWithParent<T>(this T selfObj, Component parent, bool worldPositionStays)
where T : UnityEngine.Object
{
return (T)UnityEngine.Object.Instantiate((UnityEngine.Object)selfObj, parent.transform, worldPositionStays);
}
#if UNITY_EDITOR
// v1 No.41
[MethodAPI]
[APIDescriptionCN("Object.Instantiate(Transform parent) 的简单链式封装")]
[APIDescriptionEN("Object.Instantiate(Transform parent) extension")]
[APIExampleCode(@"
prefab.Instantiate(transformRoot);
")]
#endif
public static T InstantiateWithParent<T>(this T selfObj, Transform parent) where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate(selfObj, parent, false);
}
public static T InstantiateWithParent<T>(this T selfObj, Component parent) where T : UnityEngine.Object
{
return UnityEngine.Object.Instantiate(selfObj, parent.transform, false);
}
#if UNITY_EDITOR
// v1 No.42
[MethodAPI]
[APIDescriptionCN("设置名字")]
[APIDescriptionEN("set Object's name")]
[APIExampleCode(@"
scriptableObject.Name(""LevelData"");
Debug.Log(scriptableObject.name);
// LevelData
")]
#endif
public static T Name<T>(this T selfObj, string name) where T : UnityEngine.Object
{
selfObj.name = name;
return selfObj;
}
#if UNITY_EDITOR
// v1 No.43
[MethodAPI]
[APIDescriptionCN("Object.Destroy(Object) 简单链式封装")]
[APIDescriptionEN("Object.Destroy(Object) extension")]
[APIExampleCode(@"
new GameObject().DestroySelf()
")]
#endif
public static void DestroySelf<T>(this T selfObj) where T : UnityEngine.Object
{
UnityEngine.Object.Destroy(selfObj);
}
#if UNITY_EDITOR
// v1 No.44
[MethodAPI]
[APIDescriptionCN("Object.Destroy(Object) 简单链式封装")]
[APIDescriptionEN("Object.Destroy(Object) extension")]
[APIExampleCode(@"
GameObject gameObj = null;
gameObj.DestroySelfGracefully();
// not throw null exception
// 这样写不会报异常(但是不好调试)
")]
#endif
public static T DestroySelfGracefully<T>(this T selfObj) where T : UnityEngine.Object
{
if (selfObj)
{
UnityEngine.Object.Destroy(selfObj);
}
return selfObj;
}
#if UNITY_EDITOR
// v1 No.45
[MethodAPI]
[APIDescriptionCN("Object.Destroy(Object,float) 简单链式封装")]
[APIDescriptionEN("Object.Destroy(Object,float) extension")]
[APIExampleCode(@"
new GameObject().DestroySelfAfterDelay(5);
")]
#endif
public static T DestroySelfAfterDelay<T>(this T selfObj, float afterDelay) where T : UnityEngine.Object
{
UnityEngine.Object.Destroy(selfObj, afterDelay);
return selfObj;
}
#if UNITY_EDITOR
// v1 No.46
[MethodAPI]
[APIDescriptionCN("Object.Destroy(Object,float) 简单链式封装")]
[APIDescriptionEN("Object.Destroy(Object,float) extension")]
[APIExampleCode(@"
GameObject gameObj = null;
gameObj.DestroySelfAfterDelayGracefully(5);
// not throw exception
// 不会报异常
")]
#endif
public static T DestroySelfAfterDelayGracefully<T>(this T selfObj, float delay) where T : UnityEngine.Object
{
if (selfObj)
{
UnityEngine.Object.Destroy(selfObj, delay);
}
return selfObj;
}
#if UNITY_EDITOR
// v1 No.47
[MethodAPI]
[APIDescriptionCN("Object.DontDestroyOnLoad 简单链式封装")]
[APIDescriptionEN("Object.DontDestroyOnLoad extension")]
[APIExampleCode(@"
new GameObject().DontDestroyOnLoad();
")]
#endif
public static T DontDestroyOnLoad<T>(this T selfObj) where T : UnityEngine.Object
{
UnityEngine.Object.DontDestroyOnLoad(selfObj);
return selfObj;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f82c097d6fc40e3ba52585f53920178
timeCreated: 1647487579

View File

@@ -0,0 +1,334 @@
using System;
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.GameObject", 1)]
[APIDescriptionCN("针对 UnityEngine.GameObject 提供的链式扩展")]
[APIDescriptionEN("The chain extension provided by UnityEngine.Object.")]
[APIExampleCode(@"
var gameObject = new GameObject();
var transform = gameObject.transform;
var selfScript = gameObject.AddComponent<MonoBehaviour>();
var boxCollider = gameObject.AddComponent<BoxCollider>();
//
gameObject.Show(); // gameObject.SetActive(true)
selfScript.Show(); // this.gameObject.SetActive(true)
boxCollider.Show(); // boxCollider.gameObject.SetActive(true)
gameObject.transform.Show(); // transform.gameObject.SetActive(true)
//
gameObject.Hide(); // gameObject.SetActive(false)
selfScript.Hide(); // this.gameObject.SetActive(false)
boxCollider.Hide(); // boxCollider.gameObject.SetActive(false)
transform.Hide(); // transform.gameObject.SetActive(false)
//
selfScript.DestroyGameObj();
boxCollider.DestroyGameObj();
]transform.DestroyGameObj();
//
selfScript.DestroyGameObjGracefully();
boxCollider.DestroyGameObjGracefully();
transform.DestroyGameObjGracefully();
//
selfScript.DestroyGameObjAfterDelay(1.0f);
boxCollider.DestroyGameObjAfterDelay(1.0f);
transform.DestroyGameObjAfterDelay(1.0f);
//
selfScript.DestroyGameObjAfterDelayGracefully(1.0f);
boxCollider.DestroyGameObjAfterDelayGracefully(1.0f);
transform.DestroyGameObjAfterDelayGracefully(1.0f);
//
gameObject.Layer(0);
selfScript.Layer(0);
boxCollider.Layer(0);
transform.Layer(0);
//
gameObject.Layer(""Default"");
selfScript.Layer(""Default"");
boxCollider.Layer(""Default"");
transform.Layer(""Default"");
")]
#endif
public static class UnityEngineGameObjectExtension
{
#if UNITY_EDITOR
// v1 No.48
[MethodAPI]
[APIDescriptionCN("gameObject.SetActive(true)")]
[APIDescriptionEN("gameObject.SetActive(true)")]
[APIExampleCode(@"
new GameObject().Show();
")]
#endif
public static GameObject Show(this GameObject selfObj)
{
selfObj.SetActive(true);
return selfObj;
}
#if UNITY_EDITOR
// v1 No.49
[MethodAPI]
[APIDescriptionCN("script.gameObject.SetActive(true)")]
[APIDescriptionEN("script.gameObject.SetActive(true)")]
[APIExampleCode(@"
GetComponent<MyScript>().Show();
")]
#endif
public static T Show<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Show();
return selfComponent;
}
#if UNITY_EDITOR
// v1 No.50
[MethodAPI]
[APIDescriptionCN("gameObject.SetActive(false)")]
[APIDescriptionEN("gameObject.SetActive(false)")]
[APIExampleCode(@"
gameObject.Hide();
")]
#endif
public static GameObject Hide(this GameObject selfObj)
{
selfObj.SetActive(false);
return selfObj;
}
#if UNITY_EDITOR
// v1 No.51
[MethodAPI]
[APIDescriptionCN("myScript.gameObject.SetActive(false)")]
[APIDescriptionEN("myScript.gameObject.SetActive(false)")]
[APIExampleCode(@"
GetComponent<MyScript>().Hide();
")]
#endif
public static T Hide<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Hide();
return selfComponent;
}
#if UNITY_EDITOR
// v1 No.52
[MethodAPI]
[APIDescriptionCN("Destroy(myScript.gameObject)")]
[APIDescriptionEN("Destroy(myScript.gameObject)")]
[APIExampleCode(@"
myScript.DestroyGameObj();
")]
#endif
public static void DestroyGameObj<T>(this T selfBehaviour) where T : Component
{
selfBehaviour.gameObject.DestroySelf();
}
#if UNITY_EDITOR
// v1 No.53
[MethodAPI]
[APIDescriptionCN("if (myScript) Destroy(myScript.gameObject)")]
[APIDescriptionEN("if (myScript) Destroy(myScript.gameObject)")]
[APIExampleCode(@"
myScript.DestroyGameObjGracefully();
")]
#endif
public static void DestroyGameObjGracefully<T>(this T selfBehaviour) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfGracefully();
}
}
#if UNITY_EDITOR
// v1 No.54
[MethodAPI]
[APIDescriptionCN("Object.Destroy(myScript.gameObject,delaySeconds)")]
[APIDescriptionEN("Object.Destroy(myScript.gameObject,delaySeconds)")]
[APIExampleCode(@"
myScript.DestroyGameObjAfterDelay(5);
")]
#endif
public static T DestroyGameObjAfterDelay<T>(this T selfBehaviour, float delay) where T : Component
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
return selfBehaviour;
}
#if UNITY_EDITOR
// v1 No.55
[MethodAPI]
[APIDescriptionCN("if (myScript && myScript.gameObject) Object.Destroy(myScript.gameObject,delaySeconds)")]
[APIDescriptionEN("if (myScript && myScript.gameObject) Object.Destroy(myScript.gameObject,delaySeconds)")]
[APIExampleCode(@"
myScript.DestroyGameObjAfterDelayGracefully(5);
")]
#endif
public static T DestroyGameObjAfterDelayGracefully<T>(this T selfBehaviour, float delay) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
}
return selfBehaviour;
}
#if UNITY_EDITOR
// v1 No.56
[MethodAPI]
[APIDescriptionCN("gameObject.layer = layer")]
[APIDescriptionEN("gameObject.layer = layer")]
[APIExampleCode(@"
new GameObject().Layer(0);
")]
#endif
public static GameObject Layer(this GameObject selfObj, int layer)
{
selfObj.layer = layer;
return selfObj;
}
#if UNITY_EDITOR
// v1 No.57
[MethodAPI]
[APIDescriptionCN("component.gameObject.layer = layer")]
[APIDescriptionEN("component.gameObject.layer = layer")]
[APIExampleCode(@"
rigidbody2D.Layer(0);
")]
#endif
public static T Layer<T>(this T selfComponent, int layer) where T : Component
{
selfComponent.gameObject.layer = layer;
return selfComponent;
}
#if UNITY_EDITOR
// v1 No.58
[MethodAPI]
[APIDescriptionCN("gameObj.layer = LayerMask.NameToLayer(layerName)")]
[APIDescriptionEN("gameObj.layer = LayerMask.NameToLayer(layerName)")]
[APIExampleCode(@"
new GameObject().Layer(""Default"");
")]
#endif
public static GameObject Layer(this GameObject selfObj, string layerName)
{
selfObj.layer = LayerMask.NameToLayer(layerName);
return selfObj;
}
#if UNITY_EDITOR
// v1 No.59
[MethodAPI]
[APIDescriptionCN("component.gameObject.layer = LayerMask.NameToLayer(layerName)")]
[APIDescriptionEN("component.gameObject.layer = LayerMask.NameToLayer(layerName)")]
[APIExampleCode(@"
spriteRenderer.Layer(""Default"");
")]
#endif
public static T Layer<T>(this T selfComponent, string layerName) where T : Component
{
selfComponent.gameObject.layer = LayerMask.NameToLayer(layerName);
return selfComponent;
}
#if UNITY_EDITOR
// v1 No.60
[MethodAPI]
[APIDescriptionCN("layerMask 中的层级是否包含 gameObj 所在的层级")]
[APIDescriptionEN("Whether the layer in layerMask contains the same layer as gameObj")]
[APIExampleCode(@"
gameObj.IsInLayerMask(layerMask);
")]
#endif
public static bool IsInLayerMask(this GameObject selfObj, LayerMask layerMask)
{
return LayerMaskUtility.IsInLayerMask(selfObj, layerMask);
}
#if UNITY_EDITOR
// v1 No.61
[MethodAPI]
[APIDescriptionCN("layerMask 中的层级是否包含 component.gameObject 所在的层级")]
[APIDescriptionEN("Whether the layer in layerMask contains the same layer as component.gameObject")]
[APIExampleCode(@"
spriteRenderer.IsInLayerMask(layerMask);
")]
#endif
public static bool IsInLayerMask<T>(this T selfComponent, LayerMask layerMask) where T : Component
{
return LayerMaskUtility.IsInLayerMask(selfComponent.gameObject, layerMask);
}
#if UNITY_EDITOR
// v1 No.62
[MethodAPI]
[APIDescriptionCN("获取组件,没有则添加再返回")]
[APIDescriptionEN("Get component, add and return if not")]
[APIExampleCode(@"
gameObj.GetOrAddComponent<SpriteRenderer>();
")]
#endif
public static T GetOrAddComponent<T>(this GameObject self) where T : Component
{
var comp = self.gameObject.GetComponent<T>();
return comp ? comp : self.gameObject.AddComponent<T>();
}
#if UNITY_EDITOR
// v1 No.63
[MethodAPI]
[APIDescriptionCN("获取组件,没有则添加再返回")]
[APIDescriptionEN("Get component, add and return if not")]
[APIExampleCode(@"
component.GetOrAddComponent<SpriteRenderer>();
")]
#endif
public static T GetOrAddComponent<T>(this Component component) where T : Component
{
return component.gameObject.GetOrAddComponent<T>();
}
#if UNITY_EDITOR
// v1 No.64
[MethodAPI]
[APIDescriptionCN("获取组件,没有则添加再返回")]
[APIDescriptionEN("Get component, add and return if not")]
[APIExampleCode(@"
gameObj.GetOrAddComponent(typeof(SpriteRenderer));
")]
#endif
public static Component GetOrAddComponent(this GameObject self, Type type)
{
var component = self.gameObject.GetComponent(type);
return component ? component : self.gameObject.AddComponent(type);
}
}
public static class LayerMaskUtility
{
public static bool IsInLayerMask(int layer, LayerMask layerMask)
{
var objLayerMask = 1 << layer;
return (layerMask.value & objLayerMask) == objLayerMask;
}
public static bool IsInLayerMask(GameObject gameObj, LayerMask layerMask)
{
// 根据Layer数值进行移位获得用于运算的Mask值
var objLayerMask = 1 << gameObj.layer;
return (layerMask.value & objLayerMask) == objLayerMask;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 36146f65e25b4ec79d3030f3babbc6cc
timeCreated: 1647490642

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a4b2070a7f53455e8ecc24c4d79c0a22
timeCreated: 1647492399

View File

@@ -0,0 +1,52 @@
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.MonoBehaviour", 3)]
[APIDescriptionCN("MonoBehaviour 静态扩展")]
[APIDescriptionEN("MonoBehaviour extension")]
#endif
public static class UnityEngineMonoBehaviourExtension
{
public static void Example()
{
var gameObject = new GameObject();
var component = gameObject.GetComponent<MonoBehaviour>();
component.Enable(); // component.enabled = true
component.Disable(); // component.enabled = false
}
#if UNITY_EDITOR
// v1 No.149
[MethodAPI]
[APIDescriptionCN("monoBehaviour.enable = true")]
[APIDescriptionEN("monoBehaviour.enable = true)")]
[APIExampleCode(@"
myScript.Enable();
")]
#endif
public static T Enable<T>(this T selfBehaviour, bool enable = true) where T : Behaviour
{
selfBehaviour.enabled = enable;
return selfBehaviour;
}
#if UNITY_EDITOR
// v1 No.150
[MethodAPI]
[APIDescriptionCN("monoBehaviour.enable = false")]
[APIDescriptionEN("monoBehaviour.enable = false")]
[APIExampleCode(@"
myScript.Disable();
")]
#endif
public static T Disable<T>(this T selfBehaviour) where T : Behaviour
{
selfBehaviour.enabled = false;
return selfBehaviour;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8de3fdd3a4964430b98cbc29c78e56f3
timeCreated: 1647507236

View File

@@ -0,0 +1,41 @@
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Camera", 4)]
[APIDescriptionCN("UnityEngine.Camera 静态扩展")]
[APIDescriptionEN("UnityEngine.Camera extension")]
#endif
public static class UnityEngineCameraExtension
{
#if UNITY_EDITOR
// v1 No.151
[MethodAPI]
[APIDescriptionCN("截图")]
[APIDescriptionEN("captureScreen")]
[APIExampleCode(@"
Camera.main.CaptureCamera(new Rect(0, 0, Screen.width, Screen.height));
")]
#endif
public static Texture2D CaptureCamera(this Camera camera, Rect rect)
{
var renderTexture = new RenderTexture(Screen.width, Screen.height, 0);
camera.targetTexture = renderTexture;
camera.Render();
RenderTexture.active = renderTexture;
var screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();
camera.targetTexture = null;
RenderTexture.active = null;
UnityEngine.Object.Destroy(renderTexture);
return screenShot;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 20fcd7ffbe7a4e6eb0a874c17e9d20ac
timeCreated: 1647507743

View File

@@ -0,0 +1,29 @@
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Color", 5)]
[APIDescriptionCN("UnityEngine.Color 静态扩展")]
[APIDescriptionEN("UnityEngine.Color extension")]
#endif
public static class UnityEngineColorExtension
{
#if UNITY_EDITOR
// v1 No.152
[MethodAPI]
[APIDescriptionCN("HTML string(#000000) 转 Color")]
[APIDescriptionEN("HTML string(like #000000)")]
[APIExampleCode(@"
var color = ""#C5563CFF"".HtmlStringToColor();
Debug.Log(color);"
)]
#endif
public static Color HtmlStringToColor(this string htmlString)
{
var parseSucceed = ColorUtility.TryParseHtmlString(htmlString, out var retColor);
return parseSucceed ? retColor : Color.black;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 373d8df28d2643bc823a4326ba396126
timeCreated: 1647507950

View File

@@ -0,0 +1,54 @@
using UnityEngine.UI;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Graphic", 6)]
[APIDescriptionCN("UnityEngine.UI.Graphic 静态扩展")]
[APIDescriptionEN("UnityEngine.UI.Graphic extension")]
#endif
public static class UnityEngineUIGraphicExtension
{
#if UNITY_EDITOR
// v1 No.153
[MethodAPI]
[APIDescriptionCN("设置 Graphic 的 alpha 值 ")]
[APIDescriptionEN("set graphic's alpha value")]
[APIExampleCode(@"
var gameObject = new GameObject();
var image = gameObject.AddComponent<Image>();
var rawImage = gameObject.AddComponent<RawImage>();
image.ColorAlpha(1.0f);
rawImage.ColorAlpha(1.0f);
")]
#endif
public static T ColorAlpha<T>(this T selfGraphic, float alpha) where T : Graphic
{
var color = selfGraphic.color;
color.a = alpha;
selfGraphic.color = color;
return selfGraphic;
}
#if UNITY_EDITOR
// v1 No.154
[MethodAPI]
[APIDescriptionCN("设置 image 的 fillAmount 值")]
[APIDescriptionEN("set image's fillAmount value")]
[APIExampleCode(@"
var gameObject = new GameObject();
var image1 = gameObject.AddComponent<Image>();
image1.FillAmount(0.0f);
")]
#endif
public static Image FillAmount(this Image selfImage, float fillAmount)
{
selfImage.fillAmount = fillAmount;
return selfImage;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ffdcff2f9c014047bc785723bc292477
timeCreated: 1647508258

View File

@@ -0,0 +1,321 @@
using System.Collections.Generic;
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Others", 8)]
[APIDescriptionCN("其他的一些静态扩展")]
[APIDescriptionEN("other extension")]
#endif
public static class UnityEngineOthersExtension
{
#if UNITY_EDITOR
// v1 No.155
[MethodAPI]
[APIDescriptionCN("随机 List 中的一个元素")]
[APIDescriptionEN("get random item in a list")]
[APIExampleCode(@"
new List<int>(){ 1,2,3 }.GetRandomItem();
")]
#endif
public static T GetRandomItem<T>(this List<T> list)
{
return list[UnityEngine.Random.Range(0, list.Count)];
}
#if UNITY_EDITOR
// v1.0.34
[MethodAPI]
[APIDescriptionCN("随机获取并删除 List 中的一个元素")]
[APIDescriptionEN("get and remove random item in a list")]
[APIExampleCode(@"
new List<int>(){ 1,2,3 }.GetAndRemoveRandomItem();
")]
#endif
public static T GetAndRemoveRandomItem<T>(this List<T> list)
{
var randomIndex = UnityEngine.Random.Range(0, list.Count);
var randomItem = list[randomIndex];
list.RemoveAt(randomIndex);
return randomItem;
}
#if UNITY_EDITOR
// v1
[MethodAPI]
[APIDescriptionCN("为 SpriteRender 设置 alpha 值")]
[APIDescriptionEN("set SpriteRender's alpha value")]
[APIExampleCode(@"
mySprRender.Alpha(0.5f);
")]
#endif
public static SpriteRenderer Alpha(this SpriteRenderer self, float alpha)
{
var color = self.color;
color.a = alpha;
self.color = color;
return self;
}
#if UNITY_EDITOR
// Added in v1.0.31
[MethodAPI]
[APIDescriptionCN("Mathf.Lerp")]
[APIDescriptionEN("Mathf.Lerp")]
[APIExampleCode(@"
var v = 0.5f.Lerp(0.1f,0.5f);
// v is 0.3f
")]
#endif
public static float Lerp(this float self, float a, float b)
{
return Mathf.Lerp(a, b, self);
}
#if UNITY_EDITOR
// Added in v1.0.31
[MethodAPI]
[APIDescriptionCN("Mathf.Abs")]
[APIDescriptionEN("Mathf.Abs")]
[APIExampleCode(@"
var absValue = -1.0f.Abs();
// absValue is 1.0f
")]
#endif
public static float Abs(this float self)
{
return Mathf.Abs(self);
}
public static float Abs(this int self)
{
return Mathf.Abs(self);
}
#if UNITY_EDITOR
// Added in v1.0.150
[MethodAPI]
[APIDescriptionCN("Mathf.Exp")]
[APIDescriptionEN("Mathf.Exp")]
[APIExampleCode(@"
var expValue = 1.0f.Exp(); // Mathf.Exp(1.0f)
")]
#endif
public static float Exp(this float self)
{
return Mathf.Exp(self);
}
public static float Exp(this int self)
{
return Mathf.Exp(self);
}
#if UNITY_EDITOR
// Added in v1.0.31
[MethodAPI]
[APIDescriptionCN("Mathf.Sign")]
[APIDescriptionEN("Mathf.Sign")]
[APIExampleCode(@"
var sign = -5.0f.Sign();
// sign is 5.0f
")]
#endif
public static float Sign(this float self)
{
return Mathf.Sign(self);
}
public static float Sign(this int self)
{
return Mathf.Sign(self);
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Cos")]
[APIDescriptionEN("Mathf.Cos")]
[APIExampleCode(@"
var cos = (90.0f * Mathf.Deg2Rad).Cos();
// cos is 0f
")]
#endif
public static float Cos(this float self)
{
return Mathf.Cos(self);
}
public static float Cos(this int self)
{
return Mathf.Cos(self);
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Sin")]
[APIDescriptionEN("Mathf.Sin")]
[APIExampleCode(@"
var sin = (90.0f * Mathf.Deg2Rad).Sin();
// sin is 1f
")]
#endif
public static float Sin(this float self)
{
return Mathf.Sin(self);
}
public static float Sin(this int self)
{
return Mathf.Sin(self);
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Cos(x * Mathf.Deg2Rad)")]
[APIDescriptionEN("Mathf.Cos(x * Mathf.Deg2Rad)")]
[APIExampleCode(@"
var cos = 90.0f.CosAngle();
// cos is 0f
")]
#endif
public static float CosAngle(this float self)
{
return Mathf.Cos(self * Mathf.Deg2Rad);
}
public static float CosAngle(this int self)
{
return Mathf.Cos(self * Mathf.Deg2Rad);
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Sin(x * Mathf.Deg2Rad)")]
[APIDescriptionEN("Mathf.Sin(x * Mathf.Deg2Rad)")]
[APIExampleCode(@"
var sin = 90.0f.SinAngle();
// sin is 1f
")]
#endif
public static float SinAngle(this float self)
{
return Mathf.Sin(self * Mathf.Deg2Rad);
}
public static float SinAngle(this int self)
{
return Mathf.Sin(self * Mathf.Deg2Rad);
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Deg2Rad")]
[APIDescriptionEN("Mathf.Deg2Rad")]
[APIExampleCode(@"
var radius = 90.0f.Deg2Rad();
// radius is 1.57f
")]
#endif
public static float Deg2Rad(this float self)
{
return self * Mathf.Deg2Rad;
}
public static float Deg2Rad(this int self)
{
return self * Mathf.Deg2Rad;
}
#if UNITY_EDITOR
// Added in v1.0.32
[MethodAPI]
[APIDescriptionCN("Mathf.Rad2Deg")]
[APIDescriptionEN("Mathf.Rad2Deg")]
[APIExampleCode(@"
var degree = 1.57f.Rad2Deg();
// degree is 90f
")]
#endif
public static float Rad2Deg(this float self)
{
return self * Mathf.Rad2Deg;
}
public static float Rad2Deg(this int self)
{
return self * Mathf.Rad2Deg;
}
#if UNITY_EDITOR
// Added in v1.0.129
[MethodAPI]
[APIDescriptionCN("将欧拉角转换为方向向量(Vector2)")]
[APIDescriptionEN("Convert Degree To Direction(Vector2)")]
[APIExampleCode(@"
var direction = 90.AngleToDirection2D();
// Vector2(1,0)
")]
#endif
public static Vector2 AngleToDirection2D(this int self)
{
return new Vector2(self.CosAngle(), self.SinAngle());
}
public static Vector2 AngleToDirection2D(this float self)
{
return new Vector2(self.CosAngle(), self.SinAngle());
}
#if UNITY_EDITOR
// Added in v1.0.129
[MethodAPI]
[APIDescriptionCN("将方向(Vector2)转换为欧拉角")]
[APIDescriptionEN("Convert Direction To Degrees")]
[APIExampleCode(@"
var direction = Vector2.right.ToAngle();
// Vector2(1,0)
")]
#endif
public static float ToAngle(this Vector2 self)
{
return Mathf.Atan2(self.y, self.x).Rad2Deg();
}
}
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Random", 7)]
[APIDescriptionCN("针对随机做的一些封装")]
[APIDescriptionEN("wrapper for random")]
#endif
public static class RandomUtility
{
#if UNITY_EDITOR
// v1
[MethodAPI]
[APIDescriptionCN("随机选择")]
[APIDescriptionEN("RandomChoose")]
[APIExampleCode(@"
var result = RandomUtility.Choose(1,1,1,2,2,2,2,3,3);
if (result == 3)
{
// todo ...
}
")]
#endif
public static T Choose<T>(params T[] args)
{
return args[UnityEngine.Random.Range(0, args.Length)];
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 095d03eec50f4f77828198360c9193d3
timeCreated: 1647508997

View File

@@ -0,0 +1,313 @@
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.Vector2/3", 8)]
[APIDescriptionCN("针对 Vector2/Vector3 封装的函数")]
[APIDescriptionEN("wrapper function for Vector2/Vector3")]
[APIExampleCode(@"
gameObjA.DirectionFrom(gameObjB);
myComponentA.DirectionFrom(gameObjB);
gameObjA.DirectionFrom(myComponentB);
myComponentA.DirectionFrom(myComponentB);
// also support DirectionTo/ NormalizedDirectionFrom /NormalizedDirectionTo
")]
#endif
public static class UnityEngineVectorExtension
{
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("to.transform.position - self.transform.position")]
[APIDescriptionEN("to.transform.position - self.transform.position")]
[APIExampleCode(@"
gameObj/otherComponent.DirectionTo(otherGameObj/otherComponent)
")]
#endif
public static Vector3 DirectionTo(this Component self, Component to) =>
to.transform.position - self.transform.position;
public static Vector3 DirectionTo(this GameObject self, GameObject to) =>
to.transform.position - self.transform.position;
public static Vector3 DirectionTo(this Component self, GameObject to) =>
to.transform.position - self.transform.position;
public static Vector3 DirectionTo(this GameObject self, Component to) =>
to.transform.position - self.transform.position;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("self.transform.position - from.transform.position")]
[APIDescriptionEN("self.transform.position - from.transform.position")]
[APIExampleCode(@"
gameObj/otherComponent.DirectionFrom(otherGameObj/otherComponent)
")]
#endif
public static Vector3 DirectionFrom(this Component self, Component from) =>
self.transform.position - from.transform.position;
public static Vector3 DirectionFrom(this GameObject self, GameObject from) =>
self.transform.position - from.transform.position;
public static Vector3 DirectionFrom(this GameObject self, Component from) =>
self.transform.position - from.transform.position;
public static Vector3 DirectionFrom(this Component self, GameObject from) =>
self.transform.position - from.transform.position;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("(to.transform.position - self.transform.position).normalized")]
[APIDescriptionEN("(to.transform.position - self.transform.position).normalized")]
[APIExampleCode(@"
gameObj/otherComponent.NormalizedDirectionTo(otherGameObj/otherComponent)
")]
#endif
public static Vector3 NormalizedDirectionTo(this Component self, Component to) =>
self.DirectionTo(to).normalized;
public static Vector3 NormalizedDirectionTo(this GameObject self, GameObject to) =>
self.DirectionTo(to).normalized;
public static Vector3 NormalizedDirectionTo(this Component self, GameObject to) =>
self.DirectionTo(to).normalized;
public static Vector3 NormalizedDirectionTo(this GameObject self, Component to) =>
self.DirectionTo(to).normalized;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("(self.transform.position - from.transform.position).normalized")]
[APIDescriptionEN("(self.transform.position - from.transform.position).normalized")]
[APIExampleCode(@"
gameObj/otherComponent.NormalizedDirectionTo(otherGameObj/otherComponent)
")]
#endif
public static Vector3 NormalizedDirectionFrom(this Component self, Component from) =>
self.DirectionFrom(from).normalized;
public static Vector3 NormalizedDirectionFrom(this GameObject self, GameObject from) =>
self.DirectionFrom(from).normalized;
public static Vector3 NormalizedDirectionFrom(this GameObject self, Component from) =>
self.DirectionFrom(from).normalized;
public static Vector3 NormalizedDirectionFrom(this Component self, GameObject from) =>
self.DirectionFrom(from).normalized;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("(Vector2)(to.transform.position - self.transform.position)")]
[APIDescriptionEN("(Vector2)(to.transform.position - self.transform.position)")]
[APIExampleCode(@"
gameObj/otherComponent.Direction2DTo(otherGameObj/otherComponent)
")]
#endif
public static Vector2 Direction2DTo(this Component self, Component to) =>
to.transform.position - self.transform.position;
public static Vector2 Direction2DTo(this GameObject self, GameObject to) =>
to.transform.position - self.transform.position;
public static Vector2 Direction2DTo(this Component self, GameObject to) =>
to.transform.position - self.transform.position;
public static Vector2 Direction2DTo(this GameObject self, Component to) =>
to.transform.position - self.transform.position;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("(Vector2)(self.transform.position - from.transform.position)")]
[APIDescriptionEN("(Vector2)(self.transform.position - from.transform.position)")]
[APIExampleCode(@"
gameObj/otherComponent.Direction2DFrom(otherGameObj/otherComponent)
")]
#endif
public static Vector2 Direction2DFrom(this Component self, Component from) =>
self.transform.position - from.transform.position;
public static Vector2 Direction2DFrom(this GameObject self, GameObject from) =>
self.transform.position - from.transform.position;
public static Vector2 Direction2DFrom(this GameObject self, Component from) =>
self.transform.position - from.transform.position;
public static Vector2 Direction2DFrom(this Component self, GameObject from) =>
self.transform.position - from.transform.position;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("((Vector2)(to.transform.position - self.transform.position)).normalized")]
[APIDescriptionEN("((Vector2)(to.transform.position - self.transform.position)).normalized")]
[APIExampleCode(@"
gameObj/otherComponent.NormalizedDirection2DTo(otherGameObj/otherComponent)
")]
#endif
public static Vector2 NormalizedDirection2DTo(this Component self, Component to) =>
self.Direction2DTo(to).normalized;
public static Vector2 NormalizedDirection2DTo(this GameObject self, GameObject to) =>
self.Direction2DTo(to).normalized;
public static Vector2 NormalizedDirection2DTo(this Component self, GameObject to) =>
self.Direction2DTo(to).normalized;
public static Vector2 NormalizedDirection2DTo(this GameObject self, Component to) =>
self.Direction2DTo(to).normalized;
#if UNITY_EDITOR
// v1.0.79
[MethodAPI]
[APIDescriptionCN("((Vector2)(self.transform.position - from.transform.position)).normalized")]
[APIDescriptionEN("((Vector2)(self.transform.position - from.transform.position)).normalized")]
[APIExampleCode(@"
gameObj/otherComponent.NormalizedDirection2DFrom(otherGameObj/otherComponent)
")]
#endif
public static Vector2 NormalizedDirection2DFrom(this Component self, Component from) =>
self.Direction2DFrom(from).normalized;
public static Vector2 NormalizedDirection2DFrom(this GameObject self, GameObject from) =>
self.Direction2DFrom(from).normalized;
public static Vector2 NormalizedDirection2DFrom(this GameObject self, Component from) =>
self.Direction2DFrom(from).normalized;
public static Vector2 NormalizedDirection2DFrom(this Component self, GameObject from) =>
self.Direction2DFrom(from).normalized;
public static Vector2 ToVector2(this Vector3 self) => new Vector2(self.x, self.y);
public static Vector3 ToVector3(this Vector2 self, float z = 0)
{
return new Vector3(self.x, self.y, z);
}
public static Vector3 X(this Vector3 self,float x)
{
self.x = x;
return self;
}
public static Vector3 Y(this Vector3 self,float y)
{
self.y = y;
return self;
}
public static Vector3 Z(this Vector3 self,float z)
{
self.z = z;
return self;
}
public static Vector2 X(this Vector2 self,float x)
{
self.x = x;
return self;
}
public static Vector2 Y(this Vector2 self,float y)
{
self.y = y;
return self;
}
public static float Distance(this GameObject self, GameObject other)
{
return Vector3.Distance(self.Position(), other.Position());
}
public static float Distance(this Component self, GameObject other)
{
return Vector3.Distance(self.Position(), other.Position());
}
public static float Distance(this GameObject self, Component other)
{
return Vector3.Distance(self.Position(), other.Position());
}
public static float Distance(this Component self, Component other)
{
return Vector3.Distance(self.Position(), other.Position());
}
public static float Distance2D(this GameObject self, GameObject other)
{
return Vector2.Distance(self.Position2D(), other.Position2D());
}
public static float Distance2D(this Component self, GameObject other)
{
return Vector2.Distance(self.Position2D(), other.Position2D());
}
public static float Distance2D(this GameObject self, Component other)
{
return Vector2.Distance(self.Position2D(), other.Position2D());
}
public static float Distance2D(this Component self, Component other)
{
return Vector2.Distance(self.Position2D(), other.Position2D());
}
public static float LocalDistance(this GameObject self, GameObject other)
{
return Vector3.Distance(self.LocalPosition(), other.LocalPosition());
}
public static float LocalDistance(this Component self, GameObject other)
{
return Vector3.Distance(self.LocalPosition(), other.LocalPosition());
}
public static float LocalDistance(this GameObject self, Component other)
{
return Vector3.Distance(self.LocalPosition(), other.LocalPosition());
}
public static float LocalDistance(this Component self, Component other)
{
return Vector3.Distance(self.LocalPosition(), other.LocalPosition());
}
public static float LocalDistance2D(this GameObject self, GameObject other)
{
return Vector2.Distance(self.LocalPosition2D(), other.LocalPosition2D());
}
public static float LocalDistance2D(this Component self, GameObject other)
{
return Vector2.Distance(self.LocalPosition2D(), other.LocalPosition2D());
}
public static float LocalDistance2D(this GameObject self, Component other)
{
return Vector2.Distance(self.LocalPosition2D(), other.LocalPosition2D());
}
public static float LocalDistance2D(this Component self, Component other)
{
return Vector2.Distance(self.LocalPosition2D(), other.LocalPosition2D());
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fb2654f2feb44ad6b264c2d6a8c8a2de
timeCreated: 1693400243

View File

@@ -0,0 +1,30 @@
using UnityEngine;
namespace Stary.Evo
{
#if UNITY_EDITOR
[ClassAPI("00.FluentAPI.Unity", "UnityEngine.RectTransform", 9)]
[APIDescriptionCN("针对 RectTransform 封装的函数")]
[APIDescriptionEN("wrapper function for RectTransform")]
#endif
public static class UnityEngineRectTransformExtension
{
#if UNITY_EDITOR
// v1.0.167
[MethodAPI]
[APIDescriptionCN("设置 rectTransform.anchoredPosition.y 值")]
[APIDescriptionEN("set rectTransform.anchoredPosition.y value")]
[APIExampleCode(@"
text.rectTransform.AnchoredPositionY(5);
")]
#endif
public static RectTransform AnchoredPositionY(this RectTransform selfRectTrans, float anchoredPositionY)
{
var anchorPos = selfRectTrans.anchoredPosition;
anchorPos.y = anchoredPositionY;
selfRectTrans.anchoredPosition = anchorPos;
return selfRectTrans;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 76b337d0ece04cab994eb2f50c6bd9aa
timeCreated: 1733116027