添加了自定义布尔类型;

添加了线段类型
This commit is contained in:
2023-12-01 20:07:02 +08:00
parent 39de0d24e3
commit 1f920a465f
9 changed files with 324 additions and 49 deletions

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XericLibrary.Runtime
{
/// <summary>
/// <20><>ɫ<EFBFBD><C9AB>
/// </summary>
public static class MacroColor
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f5c47ecb8ab7ce47a00a8417cd42d10
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,3 @@
using Sirenix.Utilities.Editor;
using System;
using System.Collections;
using System.Collections.Generic;

View File

@@ -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 <EFBFBD>ֶι<EFBFBD><EFBFBD><EFBFBD>
[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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 19e8ace902b02d74fbf3df96233b7ee9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -51,15 +51,18 @@ namespace XericLibrary.Runtime.Type
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
// // ʹ<><CAB9>SerializedObject<63><74>SerializedProperty<74><79><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// SerializedProperty xProp = property.FindPropertyRelative("x");
// SerializedProperty yProp = property.FindPropertyRelative("y");
// SerializedProperty zProp = property.FindPropertyRelative("z");
// // <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
// 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);
// ʹ<><CAB9>SerializedObject<63><74>SerializedProperty<74><79><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SerializedProperty axisProp = property.FindPropertyRelative("axis");
// <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>

View File

@@ -0,0 +1,204 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XericLibrary.Runtime.Type
{
/// <summary>
/// <20><>ά<EFBFBD>߶Σ<DFB6>Ĭ<EFBFBD><C4AC><EFBFBD>Ե<EFBFBD><41><CEAA><EFBFBD>ģ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><E8B6A8>B<EFBFBD><42>
/// <20><><EFBFBD><EFBFBD>һϵ<D2BB><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶εIJ<CEB5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ȡʱ<C8A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
[Serializable]
public struct LineSegment3
{
#region <EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[SerializeField]
private Vector3 pointA;
[SerializeField]
private Vector3 pointB;
/// <summary>
/// <20>˵<EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public Vector3 PointA
{
get => pointA;
set
{
if(pointA != value)
SetDrity();
pointA = value;
}
}
/// <summary>
/// <20>˵<EFBFBD>B<EFBFBD><42><EFBFBD>յ㣩
/// </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>
/// <20>߶γ<DFB6><CEB3>ȣ<EFBFBD><C8A3>ǵ<EFBFBD>A<EFBFBD><41><EFBFBD><EFBFBD>B<EFBFBD>ĵѿ<C4B5><D1BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>߾<EFBFBD><DFBE><EFBFBD>
/// </summary>
public float Length
{
get
{
if(dirtyLength)
length = Vector.magnitude;
dirtyLength = false;
return length;
}
set
{
pointB = pointA + Dirtection * value;
length = value;
dirtyLength = false;
}
}
/// <summary>
/// <20>߶<EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><41><D6B8>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>
/// <20>߶ε<DFB6>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǹ<EFBFBD><C7B9>񻯵<EFBFBD>ʸ<EFBFBD><CAB8>
/// </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>
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ά<EFBFBD>߶Σ<DFB6><CEA3><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
/// </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>
/// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ά<EFBFBD>߶Σ<DFB6><CEA3><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>ߵķ<DFB5>ʽ<EFBFBD><CABD>ʼ<EFBFBD><CABC>
/// </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 ˽<EFBFBD>з<EFBFBD><EFBFBD><EFBFBD>
/// <summary>
/// <20><><EFBFBD><EFBFBD>˶˵<CBB6>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
/// </summary>
private void SetDrity()
{
dirtyLength = true;
dirtyVector = true;
dirtyDriection = true;
}
#endregion
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// <summary>
/// <20><>ת<EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵㣬Ҳ<E3A3AC><D2B2><EFBFBD><EFBFBD>ڷ<EFBFBD>ת<EFBFBD><D7AA>ʸ<EFBFBD><CAB8><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD>
/// </summary>
public LineSegment3 Reversal()
=> new LineSegment3(pointB, pointA);
/// <summary>
/// <20><>ȡ<EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><E3B5BD><EFBFBD>߶εĴ<CEB5><C4B4>ߵ<DFB5><E3A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>ߣ<EFBFBD>
/// </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 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8296410a7b8d52944890a8aef5efaac9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,5 +1,3 @@
using Sirenix.OdinInspector.Editor;
using System;
using System.Collections;
using System.Collections.Generic;