将Spline移出Plugin,以调整SplineRenderer的OnWillCameraRender

This commit is contained in:
SoulliesOfficial
2025-03-01 22:58:20 -05:00
parent 860d7393fb
commit 5d775ae687
529 changed files with 237 additions and 119 deletions

View File

@@ -0,0 +1,43 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ColorModifierEditor : SplineSampleModifierEditor
{
private float addTime = 0f;
public ColorModifierEditor(SplineUser user, SplineUserEditor editor) : base(user, editor, "_colorModifier")
{
title = "Color Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add New Color"))
{
AddKey(addTime - 0.1f, addTime + 0.1f);
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty color = key.FindPropertyRelative("color");
SerializedProperty blendMode = key.FindPropertyRelative("blendMode");
base.KeyGUI(key);
EditorGUILayout.PropertyField(color);
EditorGUILayout.PropertyField(blendMode);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e4533e035e560d64aaa86e06610a58ed
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class FollowerSpeedModifierEditor : SplineSampleModifierEditor
{
public bool allowSelection = true;
private float addTime = 0f;
public FollowerSpeedModifierEditor(SplineUser user, SplineUserEditor editor) : base(user, editor, "_speedModifier")
{
title = "Speed Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add Speed Region"))
{
AddKey(addTime - 0.1f, addTime + 0.1f);
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty speed = key.FindPropertyRelative("speed");
SerializedProperty mode = key.FindPropertyRelative("mode");
base.KeyGUI(key);
EditorGUILayout.PropertyField(mode);
string text = (mode.intValue == (int)FollowerSpeedModifier.SpeedKey.Mode.Add ? "Add" : "Multiply") + " Speed";
EditorGUILayout.PropertyField(speed, new GUIContent(text));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ffa7555a9d798574584a7e90f0fdebf2
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class MeshScaleModifierEditor : SplineSampleModifierEditor
{
public bool allowSelection = true;
private float addTime = 0f;
public MeshScaleModifierEditor(MeshGenerator user, SplineUserEditor editor, int channelIndex) : base(user, editor, "_channels/["+channelIndex+"]/_scaleModifier")
{
title = "Scale Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add New Scale"))
{
var key = AddKey(addTime - 0.1f, addTime + 0.1f);
key.FindPropertyRelative("scale").vector3Value = Vector3.one;
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty scale = key.FindPropertyRelative("scale");
base.KeyGUI(key);
EditorGUILayout.PropertyField(scale);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5d48815d31d0e5549be897862f9353bc
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,92 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class OffsetModifierEditor : SplineSampleModifierEditor
{
public bool allowSelection = true;
private float addTime = 0f;
Matrix4x4 matrix = new Matrix4x4();
public OffsetModifierEditor(SplineUser user, SplineUserEditor editor) : base(user, editor, "_offsetModifier")
{
title = "Offset Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add New Offset"))
{
AddKey(addTime - 0.1f, addTime + 0.1f);
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty offset = key.FindPropertyRelative("offset");
base.KeyGUI(key);
EditorGUILayout.PropertyField(offset);
}
protected override bool KeyHandles(SerializedProperty key, bool edit)
{
if (!isOpen) return false;
bool changed = false;
bool is2D = user.spline != null && user.spline.is2D;
SplineSample result = new SplineSample();
SerializedProperty start = key.FindPropertyRelative("_featherStart");
SerializedProperty end = key.FindPropertyRelative("_featherEnd");
SerializedProperty centerStart = key.FindPropertyRelative("_centerStart");
SerializedProperty centerEnd = key.FindPropertyRelative("_centerEnd");
SerializedProperty offset = key.FindPropertyRelative("offset");
float position = GetPosition(start.floatValue, end.floatValue, centerStart.floatValue, centerEnd.floatValue);
user.spline.Evaluate(position, ref result);
matrix.SetTRS(result.position, Quaternion.LookRotation(result.forward, result.up), Vector3.one * result.size);
Vector3 pos = matrix.MultiplyPoint(offset.vector2Value);
if (is2D)
{
Handles.DrawLine(result.position, result.position + result.right * offset.vector2Value.x * result.size);
Handles.DrawLine(result.position, result.position - result.right * offset.vector2Value.x * result.size);
}
else Handles.DrawWireDisc(result.position, result.forward, offset.vector2Value.magnitude * result.size);
Handles.DrawLine(result.position, pos);
if (edit)
{
Vector3 lastPos = pos;
pos = SplineEditorHandles.FreeMoveRectangle(pos, HandleUtility.GetHandleSize(pos) * 0.1f);
if (pos != lastPos)
{
MainPointModule.HoldInteraction();
changed = true;
pos = matrix.inverse.MultiplyPoint(pos);
pos.z = 0f;
if (is2D)
{
offset.vector2Value = Vector2.right * pos.x;
}
else
{
offset.vector2Value = pos;
}
}
}
return base.KeyHandles(key, edit) || changed;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: eaf21c57b8cb8f548984f66d80cfe07d
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class RotationModifierEditor : SplineSampleModifierEditor
{
public bool allowSelection = true;
private float addTime = 0f;
public RotationModifierEditor(SplineUser user, SplineUserEditor parent) : base(user, parent, "_rotationModifier")
{
title = "Rotation Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add New Rotation"))
{
AddKey(addTime - 0.1f, addTime + 0.1f);
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty rotation = key.FindPropertyRelative("rotation");
SerializedProperty target = key.FindPropertyRelative("target");
SerializedProperty useLookTarget = key.FindPropertyRelative("useLookTarget");
base.KeyGUI(key);
if (!useLookTarget.boolValue)
{
EditorGUILayout.PropertyField(rotation);
}
EditorGUILayout.PropertyField(useLookTarget);
if (useLookTarget.boolValue)
{
EditorGUILayout.PropertyField(target);
}
}
protected override bool KeyHandles(SerializedProperty key, bool edit)
{
if (!isOpen) return false;
bool changed = false;
SerializedProperty start = key.FindPropertyRelative("_featherStart");
SerializedProperty end = key.FindPropertyRelative("_featherEnd");
SerializedProperty centerStart = key.FindPropertyRelative("_centerStart");
SerializedProperty centerEnd = key.FindPropertyRelative("_centerEnd");
SerializedProperty rotation = key.FindPropertyRelative("rotation");
SerializedProperty target = key.FindPropertyRelative("target");
SerializedProperty useLookTarget = key.FindPropertyRelative("useLookTarget");
float position = GetPosition(start.floatValue, end.floatValue, centerStart.floatValue, centerEnd.floatValue);
SplineSample result = new SplineSample();
user.spline.Evaluate(position, ref result);
if (useLookTarget.boolValue)
{
if (target.objectReferenceValue != null)
{
Transform targetTransform = ((Transform)target.objectReferenceValue);
Handles.DrawDottedLine(result.position, targetTransform.position, 5f);
if (edit)
{
Vector3 lastPos = targetTransform.position;
targetTransform.position = Handles.PositionHandle(targetTransform.position, Quaternion.identity);
if (lastPos != targetTransform.position)
{
MainPointModule.HoldInteraction();
EditorUtility.SetDirty(targetTransform);
changed = true;
}
}
}
}
else
{
Quaternion directionRot = Quaternion.LookRotation(result.forward, result.up);
Quaternion rot = directionRot * Quaternion.Euler(rotation.vector3Value);
SplineEditorHandles.DrawArrowCap(result.position, rot, HandleUtility.GetHandleSize(result.position));
if (edit)
{
Vector3 lastEuler = rot.eulerAngles;
rot = Handles.RotationHandle(rot, result.position);
rot = Quaternion.Inverse(directionRot) * rot;
rotation.vector3Value = rot.eulerAngles;
if (rot.eulerAngles != lastEuler)
{
MainPointModule.HoldInteraction();
changed = true;
}
}
}
return base.KeyHandles(key, edit) || changed;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 610b2b9894ff02a4abf2f483a19aeccc
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
namespace Dreamteck.Splines.Editor
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class SizeModifierEditor : SplineSampleModifierEditor
{
public bool allowSelection = true;
private float addTime = 0f;
public SizeModifierEditor(SplineUser user, SplineUserEditor editor) : base(user, editor, "_sizeModifier")
{
title = "Size Modifiers";
}
public void ClearSelection()
{
selected = -1;
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (GUILayout.Button("Add New Size"))
{
AddKey(addTime - 0.1f, addTime + 0.1f);
UpdateValues();
}
}
protected override void KeyGUI(SerializedProperty key)
{
SerializedProperty size = key.FindPropertyRelative("size");
base.KeyGUI(key);
EditorGUILayout.PropertyField(size);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dbfe0843022c91745a4144f758c78367
timeCreated: 1482695688
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,353 @@
namespace Dreamteck.Splines.Editor
{
using UnityEngine;
using UnityEditor;
public class SplineSampleModifierEditor : SplineUserSubEditor
{
protected int selected = -1;
protected bool drawAllKeys = false;
protected virtual SerializedProperty _keysProperty => _keys;
protected SerializedProperty _keys;
protected SerializedProperty _blend;
protected SerializedProperty _useClipped;
protected SerializedProperty _modifier;
protected virtual string _keysPropertyName => "keys";
private int _deleteElement = -1;
protected SerializedObject _serializedObject;
public SplineSampleModifierEditor(SplineUser user, SplineUserEditor editor, string modifierPropertyPath = "") : base(user, editor)
{
title = "Sample Modifier";
_serializedObject = new SerializedObject(user);
string[] propertyPath = modifierPropertyPath.Split('/');
var property = _serializedObject.FindProperty(propertyPath[0]);
for (int i = 1; i < propertyPath.Length; i++)
{
if(propertyPath[i].StartsWith("[") && propertyPath[i].EndsWith("]"))
{
var num = propertyPath[i].Substring(1, propertyPath[i].Length - 2);
property = property.GetArrayElementAtIndex(int.Parse(num));
continue;
}
property = property.FindPropertyRelative(propertyPath[i]);
}
_modifier = property;
_keys = _modifier.FindPropertyRelative(_keysPropertyName);
_blend = _modifier.FindPropertyRelative("blend");
_useClipped = _modifier.FindPropertyRelative("useClippedPercent");
}
public override void DrawInspector()
{
base.DrawInspector();
if (!isOpen) return;
if (_keysProperty.arraySize > 0)
{
drawAllKeys = EditorGUILayout.Toggle("Draw all Modules", drawAllKeys);
}
_serializedObject.Update();
EditorGUI.BeginChangeCheck();
for (int i = 0; i < _keysProperty.arraySize; i++)
{
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
SerializedProperty keyProperty = _keysProperty.GetArrayElementAtIndex(i);
if (selected == i)
{
EditorGUI.BeginChangeCheck();
KeyGUI(keyProperty);
if (EditorGUI.EndChangeCheck()) user.Rebuild();
}
else
{
SerializedProperty start = keyProperty.FindPropertyRelative("_featherStart");
SerializedProperty end = keyProperty.FindPropertyRelative("_featherEnd");
EditorGUILayout.LabelField(i + " [" + (Mathf.Round(start.floatValue * 10) / 10f) + " - " + (Mathf.Round(end.floatValue * 10) / 10f) + "]");
}
EditorGUILayout.EndVertical();
Rect lastRect = GUILayoutUtility.GetLastRect();
if (lastRect.Contains(Event.current.mousePosition))
{
if(Event.current.type == EventType.MouseDown)
{
if(Event.current.button == 0)
{
selected = i;
editor.Repaint();
} else if (Event.current.button == 1)
{
int index = i;
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Delete"), false, delegate
{
_deleteElement = index;
});
menu.ShowAsContext();
UpdateValues();
_serializedObject.Update();
}
}
}
}
EditorGUILayout.Space();
if (_keysProperty.arraySize > 0)
{
EditorGUILayout.PropertyField(_blend);
EditorGUILayout.PropertyField(_useClipped, new GUIContent("Use Clipped Percents", "Whether the percentages relate to the clip range of the user or not."));
}
if(_deleteElement >= 0)
{
_keysProperty.DeleteArrayElementAtIndex(_deleteElement);
_deleteElement = -1;
UpdateValues();
} else
{
if (EditorGUI.EndChangeCheck())
{
UpdateValues();
}
}
}
public override void DrawScene()
{
base.DrawScene();
_serializedObject.Update();
bool changed = false;
for (int i = 0; i < _keysProperty.arraySize; i++)
{
if (selected == i || drawAllKeys)
{
if(KeyHandles(_keysProperty.GetArrayElementAtIndex(i), selected == i))
{
changed = true;
}
}
}
if (changed)
{
UpdateValues();
}
}
protected void UpdateValues()
{
if (_serializedObject != null)
{
_serializedObject.ApplyModifiedProperties();
}
user.Rebuild();
editor.Repaint();
}
protected virtual SerializedProperty AddKey(float f, float t)
{
_keys.InsertArrayElementAtIndex(_keys.arraySize);
var key = _keys.GetArrayElementAtIndex(_keys.arraySize - 1);
SerializedProperty start = key.FindPropertyRelative("_featherStart");
SerializedProperty end = key.FindPropertyRelative("_featherEnd");
SerializedProperty centerStart = key.FindPropertyRelative("_centerStart");
SerializedProperty centerEnd = key.FindPropertyRelative("_centerEnd");
SerializedProperty blend = key.FindPropertyRelative("blend");
SerializedProperty interpolation = key.FindPropertyRelative("interpolation");
start.floatValue = Mathf.Clamp01(f);
end.floatValue = Mathf.Clamp01(t);
blend.floatValue = 1f;
interpolation.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f);
centerStart.floatValue = 0.1f;
centerEnd.floatValue = 0.9f;
return key;
}
protected virtual void KeyGUI(SerializedProperty keyProperty)
{
SerializedProperty start = keyProperty.FindPropertyRelative("_featherStart");
SerializedProperty end = keyProperty.FindPropertyRelative("_featherEnd");
SerializedProperty centerStart = keyProperty.FindPropertyRelative("_centerStart");
SerializedProperty centerEnd = keyProperty.FindPropertyRelative("_centerEnd");
SerializedProperty interpolation = keyProperty.FindPropertyRelative("interpolation");
SerializedProperty blend = keyProperty.FindPropertyRelative("blend");
EditorGUILayout.BeginHorizontal();
EditorGUIUtility.labelWidth = 50f;
start.floatValue = EditorGUILayout.Slider("Start", start.floatValue, 0f, 1f);
end.floatValue = EditorGUILayout.Slider("End", end.floatValue, 0f, 1f);
EditorGUILayout.EndHorizontal();
EditorGUIUtility.labelWidth = 0f;
float cs = centerStart.floatValue;
float ce = centerEnd.floatValue;
EditorGUILayout.MinMaxSlider("Center", ref cs, ref ce, 0f, 1f);
centerStart.floatValue = cs;
centerEnd.floatValue = ce;
EditorGUILayout.PropertyField(interpolation);
EditorGUILayout.PropertyField(blend);
}
protected static float GlobalToLocalPercent(float start, float end, float t)
{
if (start > end)
{
if (t > start) return Mathf.InverseLerp(start, start + (1f - start) + end, t);
else if (t < end) return Mathf.InverseLerp(-(1f - start), end, t);
else return 0f;
}
return Mathf.InverseLerp(start, end, t);
}
protected static float LocalToGlobalPercent(float start, float end, float t)
{
if (start > end)
{
t = Mathf.Lerp(start, start + (1f - start) + end, t);
if (t > 1f)
{
t -= Mathf.Floor(t);
}
return t;
}
return Mathf.Lerp(start, end, t);
}
protected static float GetPosition(float start, float end, float centerStart, float centerEnd)
{
float center = Mathf.Lerp(centerStart, centerEnd, 0.5f);
if (start > end)
{
float fromToEndDistance = 1f - start;
float centerDistance = center * (fromToEndDistance + end);
float pos = start + centerDistance;
if (pos > 1f)
{
pos -= Mathf.Floor(pos);
}
return pos;
}
return Mathf.Lerp(start, end, center);
}
protected virtual bool KeyHandles(SerializedProperty key, bool edit)
{
if (!isOpen) return false;
bool useClip = _useClipped.boolValue;
SerializedProperty start = key.FindPropertyRelative("_featherStart");
SerializedProperty end = key.FindPropertyRelative("_featherEnd");
SerializedProperty centerStart = key.FindPropertyRelative("_centerStart");
SerializedProperty centerEnd = key.FindPropertyRelative("_centerEnd");
bool changed = false;
double value = start.floatValue;
if (useClip)
{
user.UnclipPercent(ref value);
}
SplineComputerEditorHandles.Slider(user.spline, ref value, user.spline.editorPathColor, "Start", SplineComputerEditorHandles.SplineSliderGizmo.ForwardTriangle, 0.8f);
if (useClip)
{
user.ClipPercent(ref value);
}
if (start.floatValue != value)
{
MainPointModule.HoldInteraction();
start.floatValue = (float)value;
changed = true;
}
value = LocalToGlobalPercent(start.floatValue, end.floatValue, centerStart.floatValue);
if (useClip)
{
user.UnclipPercent(ref value);
}
SplineComputerEditorHandles.Slider(user.spline, ref value, user.spline.editorPathColor, "", SplineComputerEditorHandles.SplineSliderGizmo.Rectangle, 0.6f);
if (useClip)
{
user.ClipPercent(ref value);
}
if (LocalToGlobalPercent(start.floatValue, end.floatValue, centerStart.floatValue) != value)
{
MainPointModule.HoldInteraction();
centerStart.floatValue = GlobalToLocalPercent(start.floatValue, end.floatValue, (float)value);
changed = true;
}
value = LocalToGlobalPercent(start.floatValue, end.floatValue, centerEnd.floatValue);
if (useClip)
{
user.UnclipPercent(ref value);
}
SplineComputerEditorHandles.Slider(user.spline, ref value, user.spline.editorPathColor, "", SplineComputerEditorHandles.SplineSliderGizmo.Rectangle, 0.6f);
if (useClip)
{
user.ClipPercent(ref value);
}
if (LocalToGlobalPercent(start.floatValue, end.floatValue, centerEnd.floatValue) != value)
{
MainPointModule.HoldInteraction();
centerEnd.floatValue = GlobalToLocalPercent(start.floatValue, end.floatValue, (float)value);
changed = true;
}
value = end.floatValue;
if (useClip)
{
user.UnclipPercent(ref value);
}
SplineComputerEditorHandles.Slider(user.spline, ref value, user.spline.editorPathColor, "End", SplineComputerEditorHandles.SplineSliderGizmo.BackwardTriangle, 0.8f);
if (useClip)
{
user.ClipPercent(ref value);
}
if (end.floatValue != value)
{
MainPointModule.HoldInteraction();
end.floatValue = (float)value;
changed = true;
}
if (Event.current.control)
{
value = GetPosition(start.floatValue, end.floatValue, centerStart.floatValue, centerEnd.floatValue);
double lastValue = value;
if (useClip)
{
user.UnclipPercent(ref value);
}
SplineComputerEditorHandles.Slider(user.spline, ref value, user.spline.editorPathColor, "", SplineComputerEditorHandles.SplineSliderGizmo.Circle, 0.4f);
if (useClip)
{
user.ClipPercent(ref value);
}
if (value != lastValue)
{
MainPointModule.HoldInteraction();
double delta = value - lastValue;
start.floatValue += (float)delta;
end.floatValue += (float)delta;
start.floatValue = Mathf.Clamp01(start.floatValue);
end.floatValue = Mathf.Clamp(end.floatValue, start.floatValue, 1f);
changed = true;
}
}
return changed;
}
}
}

View File

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