Archived
添加了自定义布尔类型;
添加了线段类型
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// ÑÕÉ«ºê
|
||||
/// </summary>
|
||||
public static class MacroColor
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f5c47ecb8ab7ce47a00a8417cd42d10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,3 @@
|
||||
using Sirenix.Utilities.Editor;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.MacroLibrary;
|
||||
|
||||
namespace XericLibrary.Runtime.Type
|
||||
{
|
||||
public struct Bool1
|
||||
{
|
||||
#region ×ֶι¹Ôì
|
||||
|
||||
[SerializeField]
|
||||
private int axis;
|
||||
|
||||
public bool x
|
||||
{
|
||||
get => axis.GetEnumIndex(0);
|
||||
set => axis.SetEnumIndex(0);
|
||||
}
|
||||
|
||||
public Bool1 (bool x)
|
||||
{
|
||||
axis = x ? 1 : 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ÔËËã
|
||||
|
||||
|
||||
public static implicit operator int(Bool1 value)
|
||||
=> value.axis;
|
||||
|
||||
public static implicit operator bool(Bool1 value)
|
||||
=> value.axis > 0;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(Bool1))]
|
||||
public class Bool1DDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
SerializedProperty axisProp = property.FindPropertyRelative("axis");
|
||||
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
float checkboxWidth = 30f;
|
||||
Rect labelRect = new Rect(position.x, position.y, labelWidth, position.height);
|
||||
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
|
||||
float checkboxX = position.x + labelWidth;
|
||||
|
||||
Rect toggleRect = new Rect(checkboxX, position.y, checkboxWidth, position.height);
|
||||
axisProp.intValue = new Bool1(EditorGUI.Toggle(toggleRect, axisProp.intValue.GetEnumIndex(0)));
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19e8ace902b02d74fbf3df96233b7ee9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -51,15 +51,18 @@ namespace XericLibrary.Runtime.Type
|
||||
|
||||
#region 运算
|
||||
|
||||
public static implicit operator Bool3(int x)
|
||||
public static implicit operator Bool3(int value)
|
||||
{
|
||||
var res = new Bool3();
|
||||
res.axis = x;
|
||||
res.axis = value;
|
||||
return res;
|
||||
}
|
||||
|
||||
public static implicit operator int(Bool3 x)
|
||||
=> x.axis;
|
||||
public static implicit operator int(Bool3 value)
|
||||
=> value.axis;
|
||||
|
||||
public static implicit operator Vector3(Bool3 value)
|
||||
=> new Vector3(value.x ? 1 : 0, value.y ? 1 : 0, value.z ? 1 : 0);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -70,51 +73,10 @@ namespace XericLibrary.Runtime.Type
|
||||
{
|
||||
private readonly GUIContent[] labels = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") };
|
||||
|
||||
//public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
//{
|
||||
// EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// // 使用SerializedObject和SerializedProperty来获取子属性
|
||||
// SerializedProperty xProp = property.FindPropertyRelative("x");
|
||||
// SerializedProperty yProp = property.FindPropertyRelative("y");
|
||||
// SerializedProperty zProp = property.FindPropertyRelative("z");
|
||||
|
||||
// // 设置布尔框的位置
|
||||
// float labelWidth = EditorGUIUtility.labelWidth;
|
||||
// float checkboxWidth = 30f;
|
||||
// Rect labelRect = new Rect(position.x, position.y, labelWidth, position.height);
|
||||
|
||||
// EditorGUI.LabelField(labelRect, label);
|
||||
|
||||
// for(int i = 0; i < 3; i++)
|
||||
// {
|
||||
// float checkboxX = position.x + labelWidth + i * (checkboxWidth + 2);
|
||||
// Rect checkboxRect = new Rect(checkboxX, position.y, checkboxWidth, position.height);
|
||||
// EditorGUI.PrefixLabel(checkboxRect, GUIUtility.GetControlID(FocusType.Passive), labels[i]);
|
||||
|
||||
// Rect toggleRect = new Rect(checkboxX + 12, position.y, checkboxWidth, position.height);
|
||||
// switch(i)
|
||||
// {
|
||||
// case 0:
|
||||
// xProp.boolValue = EditorGUI.Toggle(toggleRect, xProp.boolValue);
|
||||
// break;
|
||||
// case 1:
|
||||
// yProp.boolValue = EditorGUI.Toggle(toggleRect, yProp.boolValue);
|
||||
// break;
|
||||
// case 2:
|
||||
// zProp.boolValue = EditorGUI.Toggle(toggleRect, zProp.boolValue);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// EditorGUI.EndProperty();
|
||||
//}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
// 使用SerializedObject和SerializedProperty来获取子属性
|
||||
SerializedProperty axisProp = property.FindPropertyRelative("axis");
|
||||
|
||||
// 设置布尔框的位置
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.Type
|
||||
{
|
||||
/// <summary>
|
||||
/// 三维线段,默认以点A为中心,通过调整距离,方向可以间接设定点B;
|
||||
/// 包含一系列于两点线段的参数,并通过脏文件管理,可以减少重复获取时的冗余计算
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct LineSegment3
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 pointA;
|
||||
|
||||
[SerializeField]
|
||||
private Vector3 pointB;
|
||||
|
||||
/// <summary>
|
||||
/// 端点A(起点)
|
||||
/// </summary>
|
||||
public Vector3 PointA
|
||||
{
|
||||
get => pointA;
|
||||
set
|
||||
{
|
||||
if(pointA != value)
|
||||
SetDrity();
|
||||
pointA = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 端点B(终点)
|
||||
/// </summary>
|
||||
public Vector3 PointB
|
||||
{
|
||||
get => pointB;
|
||||
set
|
||||
{
|
||||
if(pointB != value)
|
||||
SetDrity();
|
||||
pointB = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private float length;
|
||||
|
||||
private Vector3 vector;
|
||||
|
||||
private Vector3 direction;
|
||||
|
||||
private bool dirtyLength;
|
||||
|
||||
private bool dirtyVector;
|
||||
|
||||
private bool dirtyDriection;
|
||||
|
||||
/// <summary>
|
||||
/// 线段长度,是点A到点B的笛卡尔坐标直线距离
|
||||
/// </summary>
|
||||
public float Length
|
||||
{
|
||||
get
|
||||
{
|
||||
if(dirtyLength)
|
||||
length = Vector.magnitude;
|
||||
dirtyLength = false;
|
||||
return length;
|
||||
}
|
||||
set
|
||||
{
|
||||
pointB = pointA + Dirtection * value;
|
||||
length = value;
|
||||
dirtyLength = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线段矢量,由A指向B
|
||||
/// </summary>
|
||||
public Vector3 Vector
|
||||
{
|
||||
get
|
||||
{
|
||||
if(dirtyVector)
|
||||
vector = pointB - pointA;
|
||||
dirtyVector = false;
|
||||
return vector;
|
||||
}
|
||||
set
|
||||
{
|
||||
pointB = pointA + value;
|
||||
vector = value;
|
||||
dirtyVector = false;
|
||||
dirtyLength = true;
|
||||
dirtyDriection = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线段单位方向,是规格化的矢量
|
||||
/// </summary>
|
||||
public Vector3 Dirtection
|
||||
{
|
||||
get
|
||||
{
|
||||
if(dirtyDriection)
|
||||
direction = Vector / Length;
|
||||
dirtyDriection = false;
|
||||
return direction;
|
||||
}
|
||||
set
|
||||
{
|
||||
var normal = value.normalized;
|
||||
pointB = pointA + normal * Length;
|
||||
direction = normal;
|
||||
dirtyDriection = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个三维线段,并指定两个端点
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
public LineSegment3(Vector3 a, Vector3 b)
|
||||
{
|
||||
pointA = a;
|
||||
pointB = b;
|
||||
length = -1;
|
||||
vector = Vector3.zero;
|
||||
direction = Vector3.zero;
|
||||
dirtyLength = true;
|
||||
dirtyVector = true;
|
||||
dirtyDriection = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个三维线段,但使用射线的方式初始化
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="dir"></param>
|
||||
/// <param name="length"></param>
|
||||
public LineSegment3(Vector3 a, Vector3 dir, float length)
|
||||
{
|
||||
pointA = a;
|
||||
pointB = a + dir.normalized * length;
|
||||
this.length = -1;
|
||||
vector = Vector3.zero;
|
||||
direction = Vector3.zero;
|
||||
dirtyLength = true;
|
||||
dirtyVector = true;
|
||||
dirtyDriection = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 私有方法
|
||||
|
||||
/// <summary>
|
||||
/// 当设定了端点时,所有相关参数将不再有效
|
||||
/// </summary>
|
||||
private void SetDrity()
|
||||
{
|
||||
dirtyLength = true;
|
||||
dirtyVector = true;
|
||||
dirtyDriection = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 公开方法
|
||||
|
||||
/// <summary>
|
||||
/// 反转线段两个端点,也就相当于反转了矢量等参数
|
||||
/// </summary>
|
||||
public LineSegment3 Reversal()
|
||||
=> new LineSegment3(pointB, pointA);
|
||||
|
||||
/// <summary>
|
||||
/// 获取空间中任意一点到此线段的垂线点(不包含延长线)
|
||||
/// </summary>
|
||||
/// <param name="pointC"></param>
|
||||
public Vector3 GetVerticalLine(Vector3 pointC)
|
||||
{
|
||||
var t = Mathf.Clamp01(Vector3.Dot(pointC - pointA, Vector) / Vector3.Dot(Vector, Vector));
|
||||
return pointA + Vector * t;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 运算
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8296410a7b8d52944890a8aef5efaac9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,3 @@
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
Reference in New Issue
Block a user