去掉obi,使用自写绳索
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16f13a837c41b437a87aa83162abd677
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,58 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
[CustomEditor(typeof(ObiRopeBlueprintBase), true)]
|
||||
public class ObiRopeBaseBlueprintEditor : ObiActorBlueprintEditor
|
||||
{
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
Undo.undoRedoPerformed += UndoRedoPerformed;
|
||||
}
|
||||
|
||||
public override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
Undo.undoRedoPerformed -= UndoRedoPerformed;
|
||||
}
|
||||
|
||||
void UndoRedoPerformed()
|
||||
{
|
||||
// Re-generate the blueprint after undo/redo.
|
||||
if (blueprint != null)
|
||||
blueprint.GenerateImmediate();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
|
||||
Editor.DrawPropertiesExcluding(serializedObject, "m_Script");
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUI.changed)
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
// Re-generate the blueprint if any element has been changed.
|
||||
if (blueprint != null)
|
||||
blueprint.GenerateImmediate();
|
||||
|
||||
// There might be blueprint editing operations that have no undo entry, so do this to
|
||||
// ensure changes are serialized to disk by Unity.
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87efff4816bdd4fa4bda69ca33516658
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,29 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ObiBone.BonePropertyCurve))]
|
||||
public class BonePropertyCurveDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
float curveFieldWidth = (position.width - EditorGUIUtility.labelWidth) * 0.5f;
|
||||
|
||||
var multRect = new Rect(position.x, position.y, position.width - curveFieldWidth, position.height);
|
||||
EditorGUI.PropertyField(multRect, property.FindPropertyRelative("multiplier"), label);
|
||||
|
||||
var indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
var curveRect = new Rect(position.x + position.width - curveFieldWidth + 3, position.y, curveFieldWidth - 3, position.height);
|
||||
EditorGUI.CurveField(curveRect, property.FindPropertyRelative("curve"), Color.green, new Rect(0, 0, 1, 1), GUIContent.none);
|
||||
|
||||
EditorGUI.indentLevel = indent;
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b78a1342294ee4644a9a0d6a247d3604
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ObiBone.IgnoredBone))]
|
||||
public class IgnoredBoneDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
GUI.Box(EditorGUI.IndentedRect(position), GUIContent.none, ObiEditorUtils.GetToggleablePropertyGroupStyle());
|
||||
|
||||
var rect = new Rect(position.x + 4, position.y + EditorGUIUtility.standardVerticalSpacing, position.width - 8, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.PropertyField(rect, property.FindPropertyRelative("bone"), label);
|
||||
|
||||
rect.position = new Vector2(rect.position.x, rect.position.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
|
||||
EditorGUI.PropertyField(rect, property.FindPropertyRelative("ignoreChildren"));
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
int lineCount = 2;
|
||||
return EditorGUIUtility.singleLineHeight * lineCount + EditorGUIUtility.standardVerticalSpacing * (lineCount + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9e4bd0b2f9544e039fef4cd5d95232f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,225 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiBone))]
|
||||
public class ObiBoneEditor : Editor
|
||||
{
|
||||
ObiBone bone;
|
||||
|
||||
SerializedProperty collisionMaterial;
|
||||
SerializedProperty selfCollisions;
|
||||
SerializedProperty surfaceCollisions;
|
||||
|
||||
SerializedProperty mass;
|
||||
SerializedProperty rotationalMass;
|
||||
SerializedProperty radius;
|
||||
|
||||
SerializedProperty skinConstraintsEnabled;
|
||||
SerializedProperty skinCompliance;
|
||||
SerializedProperty skinRadius;
|
||||
|
||||
SerializedProperty stretchShearConstraintsEnabled;
|
||||
SerializedProperty stretchCompliance;
|
||||
SerializedProperty shear1Compliance;
|
||||
SerializedProperty shear2Compliance;
|
||||
|
||||
SerializedProperty bendTwistConstraintsEnabled;
|
||||
SerializedProperty torsionCompliance;
|
||||
SerializedProperty bend1Compliance;
|
||||
SerializedProperty bend2Compliance;
|
||||
SerializedProperty plasticYield;
|
||||
SerializedProperty plasticCreep;
|
||||
|
||||
SerializedProperty aerodynamicsEnabled;
|
||||
SerializedProperty drag;
|
||||
SerializedProperty lift;
|
||||
|
||||
SerializedProperty fixRoot;
|
||||
SerializedProperty stretchBones;
|
||||
SerializedProperty ignored;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
bone = (ObiBone)target;
|
||||
|
||||
fixRoot = serializedObject.FindProperty("fixRoot");
|
||||
stretchBones = serializedObject.FindProperty("stretchBones");
|
||||
ignored = serializedObject.FindProperty("ignored");
|
||||
|
||||
collisionMaterial = serializedObject.FindProperty("m_CollisionMaterial");
|
||||
selfCollisions = serializedObject.FindProperty("m_SelfCollisions");
|
||||
surfaceCollisions = serializedObject.FindProperty("m_SurfaceCollisions");
|
||||
|
||||
mass = serializedObject.FindProperty("_mass");
|
||||
rotationalMass = serializedObject.FindProperty("_rotationalMass");
|
||||
radius = serializedObject.FindProperty("_radius");
|
||||
|
||||
skinConstraintsEnabled = serializedObject.FindProperty("_skinConstraintsEnabled");
|
||||
skinRadius = serializedObject.FindProperty("_skinRadius");
|
||||
skinCompliance = serializedObject.FindProperty("_skinCompliance");
|
||||
|
||||
stretchShearConstraintsEnabled = serializedObject.FindProperty("_stretchShearConstraintsEnabled");
|
||||
stretchCompliance = serializedObject.FindProperty("_stretchCompliance");
|
||||
shear1Compliance = serializedObject.FindProperty("_shear1Compliance");
|
||||
shear2Compliance = serializedObject.FindProperty("_shear2Compliance");
|
||||
|
||||
bendTwistConstraintsEnabled = serializedObject.FindProperty("_bendTwistConstraintsEnabled");
|
||||
torsionCompliance = serializedObject.FindProperty("_torsionCompliance");
|
||||
bend1Compliance = serializedObject.FindProperty("_bend1Compliance");
|
||||
bend2Compliance = serializedObject.FindProperty("_bend2Compliance");
|
||||
plasticYield = serializedObject.FindProperty("_plasticYield");
|
||||
plasticCreep = serializedObject.FindProperty("_plasticCreep");
|
||||
|
||||
aerodynamicsEnabled = serializedObject.FindProperty("_aerodynamicsEnabled");
|
||||
drag = serializedObject.FindProperty("_drag");
|
||||
lift = serializedObject.FindProperty("_lift");
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
Tools.hidden = false;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
EditorGUILayout.LabelField("Bones", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(fixRoot);
|
||||
EditorGUILayout.PropertyField(stretchBones);
|
||||
EditorGUILayout.PropertyField(ignored);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Collisions", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(collisionMaterial, new GUIContent("Collision material"));
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newCategory = EditorGUILayout.Popup("Collision category", ObiUtils.GetCategoryFromFilter(bone.Filter), ObiUtils.categoryNames);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (ObiBone t in targets)
|
||||
{
|
||||
Undo.RecordObject(t, "Set collision category");
|
||||
t.Filter = ObiUtils.MakeFilter(ObiUtils.GetMaskFromFilter(t.Filter), newCategory);
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(t);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newMask = EditorGUILayout.MaskField("Collides with", ObiUtils.GetMaskFromFilter(bone.Filter), ObiUtils.categoryNames);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (ObiBone t in targets)
|
||||
{
|
||||
Undo.RecordObject(t, "Set collision mask");
|
||||
t.Filter = ObiUtils.MakeFilter(newMask, ObiUtils.GetCategoryFromFilter(t.Filter));
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(t);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.PropertyField(selfCollisions, new GUIContent("Self collisions"));
|
||||
EditorGUILayout.PropertyField(surfaceCollisions, new GUIContent("Surface-based collisions"));
|
||||
EditorGUILayout.Space();
|
||||
|
||||
ObiEditorUtils.DoPropertyGroup(new GUIContent("Particles"),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(mass);
|
||||
EditorGUILayout.PropertyField(rotationalMass);
|
||||
EditorGUILayout.PropertyField(radius);
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(skinConstraintsEnabled, new GUIContent("Skin Constraints", Resources.Load<Texture2D>("Icons/ObiSkinConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(skinRadius, new GUIContent("Skin radius"));
|
||||
EditorGUILayout.PropertyField(skinCompliance, new GUIContent("Skin compliance"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(stretchShearConstraintsEnabled, new GUIContent("Stretch & Shear Constraints", Resources.Load<Texture2D>("Icons/ObiStretchShearConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(stretchCompliance, new GUIContent("Stretch compliance"));
|
||||
EditorGUILayout.PropertyField(shear1Compliance, new GUIContent("Shear compliance X"));
|
||||
EditorGUILayout.PropertyField(shear2Compliance, new GUIContent("Shear compliance Y"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(bendTwistConstraintsEnabled, new GUIContent("Bend & Twist Constraints", Resources.Load<Texture2D>("Icons/ObiBendTwistConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(torsionCompliance, new GUIContent("Torsion compliance"));
|
||||
EditorGUILayout.PropertyField(bend1Compliance, new GUIContent("Bend compliance X"));
|
||||
EditorGUILayout.PropertyField(bend2Compliance, new GUIContent("Bend compliance Y"));
|
||||
EditorGUILayout.PropertyField(plasticYield, new GUIContent("Plastic yield"));
|
||||
EditorGUILayout.PropertyField(plasticCreep, new GUIContent("Plastic creep"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(aerodynamicsEnabled, new GUIContent("Aerodynamics", Resources.Load<Texture2D>("Icons/ObiAerodynamicConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(drag, new GUIContent("Drag"));
|
||||
EditorGUILayout.PropertyField(lift, new GUIContent("Lift"));
|
||||
});
|
||||
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void DrawGizmos(ObiBone actor, GizmoType gizmoType)
|
||||
{
|
||||
if (actor.boneBlueprint != null && actor.isLoaded)
|
||||
{
|
||||
var color = new Color(1, 1, 1, 0.5f);
|
||||
var upColor = new Color(0, 1, 0, 1);
|
||||
|
||||
for (int i = 0; i < actor.boneBlueprint.parentIndices.Count; ++i)
|
||||
{
|
||||
int parent = actor.boneBlueprint.parentIndices[i];
|
||||
if (parent >= 0)
|
||||
{
|
||||
var index = actor.solverIndices[parent];
|
||||
var nextIndex = actor.solverIndices[i];
|
||||
|
||||
var pos = actor.GetParticlePosition(index);
|
||||
var npos = actor.GetParticlePosition(nextIndex);
|
||||
var or = actor.GetParticleOrientation(index);
|
||||
var nor = actor.GetParticleOrientation(nextIndex);
|
||||
var rad = actor.GetParticleMaxRadius(index);
|
||||
var nrad = actor.GetParticleMaxRadius(nextIndex);
|
||||
|
||||
var up = pos + or * Vector3.up * rad;
|
||||
var down = pos + or * Vector3.down * rad;
|
||||
var left = pos + or * Vector3.left * rad;
|
||||
var right = pos + or * Vector3.right * rad;
|
||||
|
||||
var nup = npos + nor * Vector3.up * nrad;
|
||||
var ndown = npos + nor * Vector3.down * nrad;
|
||||
var nleft = npos + nor * Vector3.left * nrad;
|
||||
var nright = npos + nor * Vector3.right * nrad;
|
||||
|
||||
Handles.color = upColor;
|
||||
Handles.DrawLine(up, nup);
|
||||
|
||||
Handles.color = color;
|
||||
Handles.DrawLine(down, ndown);
|
||||
Handles.DrawLine(left, nleft);
|
||||
Handles.DrawLine(right, nright);
|
||||
Handles.DrawWireDisc(npos, nor * Vector3.forward, nrad);
|
||||
}
|
||||
}
|
||||
if (actor.particleCount > 0)
|
||||
{
|
||||
var index = actor.solverIndices[0];
|
||||
var pos = actor.GetParticlePosition(index);
|
||||
var or = actor.GetParticleOrientation(index);
|
||||
var rad = actor.GetParticleMaxRadius(index);
|
||||
|
||||
Handles.DrawWireDisc(pos, or * Vector3.forward, rad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f25827f322514e1bb93fd309cd801bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,73 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi{
|
||||
public class ObiDraggableIcon {
|
||||
|
||||
public static bool Draw(bool selected, int id, ref Vector2 position, Color color){
|
||||
|
||||
Texture texture = Resources.Load<Texture2D>("Dot");
|
||||
|
||||
int controlID = GUIUtility.GetControlID(id,FocusType.Passive);
|
||||
|
||||
// select vertex on mouse click:
|
||||
switch (Event.current.GetTypeForControl(controlID)){
|
||||
|
||||
case EventType.MouseDown:
|
||||
|
||||
Rect area = new Rect (position.x-5, position.y-5, 10, 10);
|
||||
|
||||
if (area.Contains(Event.current.mousePosition))
|
||||
{
|
||||
selected = true;
|
||||
GUIUtility.hotControl = controlID;
|
||||
Event.current.Use();
|
||||
}else if ((Event.current.modifiers & EventModifiers.Shift) == 0 && (Event.current.modifiers & EventModifiers.Command) == 0){
|
||||
|
||||
selected = false;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseDrag:
|
||||
|
||||
if (GUIUtility.hotControl == controlID){
|
||||
|
||||
position = Event.current.mousePosition;
|
||||
GUI.changed = true;
|
||||
|
||||
Event.current.Use();
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
|
||||
if (GUIUtility.hotControl == controlID){
|
||||
|
||||
GUIUtility.hotControl = 0;
|
||||
Event.current.Use();
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.Repaint:
|
||||
|
||||
Color oldColor = GUI.color;
|
||||
GUI.color = selected ? ObiEditorSettings.GetOrCreateSettings().selectedParticleColor : ObiEditorSettings.GetOrCreateSettings().particleColor;
|
||||
Rect rect = new Rect (position.x-2, position.y-2, 4, 4);
|
||||
GUI.Box(rect,EditorGUIUtility.whiteTexture);
|
||||
GUI.color = oldColor;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c736a38cd50af4bccbd08b83993abbdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cb694bcadb6a4909b593111507e1eb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,271 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
public class ObiPathHandles
|
||||
{
|
||||
|
||||
static int splineSelectorHash = "ObiPathSelectorHash".GetHashCode();
|
||||
const int minSelectionDistance = 5;
|
||||
|
||||
static Vector2 startPos;
|
||||
static Vector2 currentPos;
|
||||
static bool dragging = false;
|
||||
static Rect marquee;
|
||||
|
||||
public static bool SplineCPSelector(ObiPath path, bool[] selectionStatus)
|
||||
{
|
||||
|
||||
int controlID = GUIUtility.GetControlID(splineSelectorHash, FocusType.Passive);
|
||||
int selectedCPIndex = -1;
|
||||
bool selectionStatusChanged = false;
|
||||
|
||||
// select vertex on mouse click:
|
||||
switch (Event.current.GetTypeForControl(controlID))
|
||||
{
|
||||
case EventType.Layout:
|
||||
case EventType.MouseMove:
|
||||
|
||||
float minSqrDistance = System.Single.MaxValue;
|
||||
float sqrMinSelectionDistance = minSelectionDistance * minSelectionDistance;
|
||||
|
||||
for (int i = 0; i < path.ControlPointCount; i++)
|
||||
{
|
||||
|
||||
// get particle position in gui space:
|
||||
Vector2 pos = HandleUtility.WorldToGUIPoint(path.points[i].position);
|
||||
|
||||
// get distance from mouse position to particle position:
|
||||
float sqrDistance = Vector2.SqrMagnitude(Event.current.mousePosition - pos);
|
||||
|
||||
// check if this control point is closer to the cursor that any previously considered point.
|
||||
if (sqrDistance < sqrMinSelectionDistance && sqrDistance < minSqrDistance)
|
||||
{
|
||||
minSqrDistance = sqrDistance;
|
||||
}
|
||||
|
||||
}
|
||||
HandleUtility.AddControl(controlID, Mathf.Sqrt(minSqrDistance));
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseDown:
|
||||
|
||||
marquee.Set(0, 0, 0, 0);
|
||||
startPos = Event.current.mousePosition;
|
||||
|
||||
if (Event.current.button == 0)
|
||||
{
|
||||
|
||||
if (HandleUtility.nearestControl == controlID)
|
||||
{
|
||||
GUIUtility.hotControl = controlID;
|
||||
|
||||
// If the user is pressing shift or ctrl, accumulate selection.
|
||||
if ((Event.current.modifiers & (EventModifiers.Shift | EventModifiers.Control)) == 0 && (Event.current.modifiers & EventModifiers.Alt) == 0)
|
||||
{
|
||||
for (int i = 0; i < selectionStatus.Length; i++)
|
||||
selectionStatus[i] = false;
|
||||
|
||||
selectionStatusChanged = true;
|
||||
}
|
||||
|
||||
minSqrDistance = System.Single.MaxValue;
|
||||
sqrMinSelectionDistance = minSelectionDistance * minSelectionDistance;
|
||||
|
||||
for (int i = 0; i < path.ControlPointCount; i++)
|
||||
{
|
||||
|
||||
// get particle position in gui space:
|
||||
Vector2 pos = HandleUtility.WorldToGUIPoint(path.points[i].position);
|
||||
|
||||
// get distance from mouse position to particle position:
|
||||
float sqrDistance = Vector2.SqrMagnitude(startPos - pos);
|
||||
|
||||
// check if this control point is closer to the cursor that any previously considered point.
|
||||
if (sqrDistance < sqrMinSelectionDistance && sqrDistance < minSqrDistance)
|
||||
{
|
||||
minSqrDistance = sqrDistance;
|
||||
selectedCPIndex = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (selectedCPIndex >= 0)
|
||||
{ // toggle particle selection status.
|
||||
|
||||
selectionStatus[selectedCPIndex] = !selectionStatus[selectedCPIndex];
|
||||
selectionStatusChanged = true;
|
||||
|
||||
// Prevent spline deselection if we have selected a particle:
|
||||
Event.current.Use();
|
||||
|
||||
}
|
||||
}
|
||||
else if ((Event.current.modifiers & (EventModifiers.Shift | EventModifiers.Control)) == 0 && (Event.current.modifiers & EventModifiers.Alt) == 0)
|
||||
{
|
||||
for (int i = 0; i < selectionStatus.Length; i++)
|
||||
selectionStatus[i] = false;
|
||||
|
||||
selectionStatusChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseDrag:
|
||||
|
||||
if (Event.current.button == 0 && (Event.current.modifiers & EventModifiers.Alt) == 0)
|
||||
{
|
||||
currentPos = Event.current.mousePosition;
|
||||
if (!dragging && Vector2.Distance(startPos, currentPos) > 5)
|
||||
{
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
if (dragging)
|
||||
{
|
||||
GUIUtility.hotControl = controlID;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
//update marquee rect:
|
||||
float left = Mathf.Min(startPos.x, currentPos.x);
|
||||
float right = Mathf.Max(startPos.x, currentPos.x);
|
||||
float bottom = Mathf.Min(startPos.y, currentPos.y);
|
||||
float top = Mathf.Max(startPos.y, currentPos.y);
|
||||
|
||||
marquee = new Rect(left, bottom, right - left, top - bottom);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
|
||||
if (GUIUtility.hotControl == controlID)
|
||||
{
|
||||
|
||||
dragging = false;
|
||||
|
||||
for (int i = 0; i < path.ControlPointCount; i++)
|
||||
{
|
||||
|
||||
// get particle position in gui space:
|
||||
Vector2 pos = HandleUtility.WorldToGUIPoint(path.points[i].position);
|
||||
|
||||
if (pos.x > marquee.xMin && pos.x < marquee.xMax && pos.y > marquee.yMin && pos.y < marquee.yMax)
|
||||
{
|
||||
selectionStatus[i] = true;
|
||||
selectionStatusChanged = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GUIUtility.hotControl = 0;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.Repaint:
|
||||
|
||||
if (dragging)
|
||||
{
|
||||
GUISkin oldSkin = GUI.skin;
|
||||
GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
|
||||
Handles.BeginGUI();
|
||||
GUI.Box(new Rect(marquee.xMin, marquee.yMin, marquee.width, marquee.height), "");
|
||||
Handles.EndGUI();
|
||||
GUI.skin = oldSkin;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return selectionStatusChanged;
|
||||
}
|
||||
|
||||
private static void DrawControlPointArcs(ObiPath path, float thicknessScale)
|
||||
{
|
||||
for (int i = 0; i < path.ControlPointCount; ++i)
|
||||
{
|
||||
Vector3 position = path.points[i].position;
|
||||
Vector3 tangent = path.points.GetTangent(i);
|
||||
Vector3 right = Vector3.Cross(tangent, path.normals[i]).normalized;
|
||||
float thickness = path.thicknesses[i] * thicknessScale + 0.05f;
|
||||
|
||||
Handles.DrawWireArc(position, tangent, right, -180, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawPathPolylines(Vector3[] samples, Vector3[] leftSamples, Vector3[] rightSamples, Vector3[] upSamples, bool drawOrientation)
|
||||
{
|
||||
Handles.DrawPolyLine(samples);
|
||||
if (drawOrientation)
|
||||
{
|
||||
Handles.DrawPolyLine(leftSamples);
|
||||
Handles.DrawPolyLine(upSamples);
|
||||
Handles.DrawPolyLine(rightSamples);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawPathHandle(ObiPath path, Matrix4x4 referenceFrame, float thicknessScale, int resolution, bool drawOrientation = true)
|
||||
{
|
||||
|
||||
if (path == null || path.GetSpanCount() == 0) return;
|
||||
|
||||
Matrix4x4 prevMatrix = Handles.matrix;
|
||||
Handles.matrix = referenceFrame;
|
||||
|
||||
// Draw the curve:
|
||||
int curveSegments = path.GetSpanCount() * resolution;
|
||||
Vector3[] samples = new Vector3[curveSegments + 1];
|
||||
Vector3[] leftSamples = new Vector3[curveSegments + 1];
|
||||
Vector3[] rightSamples = new Vector3[curveSegments + 1];
|
||||
Vector3[] upSamples = new Vector3[curveSegments + 1];
|
||||
|
||||
for (int i = 0; i <= curveSegments; ++i)
|
||||
{
|
||||
|
||||
float mu = i / (float)curveSegments;
|
||||
samples[i] = path.points.GetPositionAtMu(path.Closed,mu);
|
||||
|
||||
if (drawOrientation)
|
||||
{
|
||||
Vector3 tangent = path.points.GetTangentAtMu(path.Closed,mu);
|
||||
Vector3 right = Vector3.Cross(tangent, path.normals.GetAtMu(path.Closed,mu)).normalized;
|
||||
Vector3 up = Vector3.Cross(right, tangent).normalized;
|
||||
float thickness = path.thicknesses.GetAtMu(path.Closed,mu) * thicknessScale + 0.05f;
|
||||
|
||||
leftSamples[i] = samples[i] - right * thickness;
|
||||
rightSamples[i] = samples[i] + right * thickness;
|
||||
upSamples[i] = samples[i] + up * thickness;
|
||||
|
||||
if (i % 5 == 0)
|
||||
{
|
||||
Handles.DrawLine(leftSamples[i], rightSamples[i]);
|
||||
Handles.DrawLine(samples[i], samples[i] + up * thickness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drawOrientation)
|
||||
DrawControlPointArcs(path, thicknessScale);
|
||||
|
||||
DrawPathPolylines(samples, leftSamples, rightSamples, upSamples, drawOrientation);
|
||||
DrawPathPolylines(samples, leftSamples, rightSamples, upSamples, drawOrientation);
|
||||
|
||||
Handles.matrix = prevMatrix;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3c12ceb831344c47af02f0d6bf73de7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,37 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiPathSmoother), true), CanEditMultipleObjects]
|
||||
public class ObiPathSmootherEditor : Editor
|
||||
{
|
||||
|
||||
ObiPathSmoother shape;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
shape = (ObiPathSmoother)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject, "m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a01b6dc95e7284e2583513863858d670
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,220 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.EditorTools;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiRod))]
|
||||
public class ObiRodEditor : Editor
|
||||
{
|
||||
[MenuItem("GameObject/3D Object/Obi/Obi Rod", false, 301)]
|
||||
static void CreateObiRod(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = new GameObject("Obi Rod", typeof(ObiRod), typeof(ObiRopeExtrudedRenderer));
|
||||
var renderer = go.GetComponent<ObiRopeExtrudedRenderer>();
|
||||
renderer.material = ObiEditorUtils.GetDefaultMaterial();
|
||||
ObiEditorUtils.PlaceActorRoot(go, menuCommand);
|
||||
}
|
||||
|
||||
ObiRod actor;
|
||||
|
||||
SerializedProperty rodBlueprint;
|
||||
|
||||
SerializedProperty collisionMaterial;
|
||||
SerializedProperty selfCollisions;
|
||||
SerializedProperty surfaceCollisions;
|
||||
SerializedProperty massScale;
|
||||
|
||||
SerializedProperty stretchShearConstraintsEnabled;
|
||||
SerializedProperty stretchCompliance;
|
||||
SerializedProperty shear1Compliance;
|
||||
SerializedProperty shear2Compliance;
|
||||
|
||||
SerializedProperty bendTwistConstraintsEnabled;
|
||||
SerializedProperty torsionCompliance;
|
||||
SerializedProperty bend1Compliance;
|
||||
SerializedProperty bend2Compliance;
|
||||
SerializedProperty plasticYield;
|
||||
SerializedProperty plasticCreep;
|
||||
|
||||
SerializedProperty aerodynamicsEnabled;
|
||||
SerializedProperty drag;
|
||||
SerializedProperty lift;
|
||||
|
||||
SerializedProperty chainConstraintsEnabled;
|
||||
SerializedProperty tightness;
|
||||
|
||||
GUIStyle editLabelStyle;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
actor = (ObiRod)target;
|
||||
|
||||
rodBlueprint = serializedObject.FindProperty("m_RodBlueprint");
|
||||
|
||||
collisionMaterial = serializedObject.FindProperty("m_CollisionMaterial");
|
||||
selfCollisions = serializedObject.FindProperty("m_SelfCollisions");
|
||||
surfaceCollisions = serializedObject.FindProperty("m_SurfaceCollisions");
|
||||
massScale = serializedObject.FindProperty("m_MassScale");
|
||||
|
||||
stretchShearConstraintsEnabled = serializedObject.FindProperty("_stretchShearConstraintsEnabled");
|
||||
stretchCompliance = serializedObject.FindProperty("_stretchCompliance");
|
||||
shear1Compliance = serializedObject.FindProperty("_shear1Compliance");
|
||||
shear2Compliance = serializedObject.FindProperty("_shear2Compliance");
|
||||
|
||||
bendTwistConstraintsEnabled = serializedObject.FindProperty("_bendTwistConstraintsEnabled");
|
||||
torsionCompliance = serializedObject.FindProperty("_torsionCompliance");
|
||||
bend1Compliance = serializedObject.FindProperty("_bend1Compliance");
|
||||
bend2Compliance = serializedObject.FindProperty("_bend2Compliance");
|
||||
plasticYield = serializedObject.FindProperty("_plasticYield");
|
||||
plasticCreep = serializedObject.FindProperty("_plasticCreep");
|
||||
|
||||
aerodynamicsEnabled = serializedObject.FindProperty("_aerodynamicsEnabled");
|
||||
drag = serializedObject.FindProperty("_drag");
|
||||
lift = serializedObject.FindProperty("_lift");
|
||||
|
||||
chainConstraintsEnabled = serializedObject.FindProperty("_chainConstraintsEnabled");
|
||||
tightness = serializedObject.FindProperty("_tightness");
|
||||
}
|
||||
|
||||
private void DoEditButton()
|
||||
{
|
||||
using (new EditorGUI.DisabledScope(actor.rodBlueprint == null))
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
bool edit = GUILayout.Toggle(ToolManager.activeToolType == typeof(ObiPathEditor), new GUIContent(Resources.Load<Texture2D>("EditCurves")), "Button", GUILayout.MaxWidth(36), GUILayout.MaxHeight(24));
|
||||
EditorGUILayout.LabelField("Edit path", editLabelStyle, GUILayout.ExpandHeight(true), GUILayout.MaxHeight(24));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (edit)
|
||||
ToolManager.SetActiveTool<ObiPathEditor>();
|
||||
else
|
||||
ToolManager.RestorePreviousPersistentTool();
|
||||
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (editLabelStyle == null)
|
||||
{
|
||||
editLabelStyle = new GUIStyle(GUI.skin.label);
|
||||
editLabelStyle.alignment = TextAnchor.MiddleLeft;
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
if (actor.rodBlueprint != null && actor.rodBlueprint.path.ControlPointCount < 2)
|
||||
{
|
||||
actor.rodBlueprint.GenerateImmediate();
|
||||
}
|
||||
|
||||
using (new EditorGUI.DisabledScope(ToolManager.activeToolType == typeof(ObiPathEditor)))
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(rodBlueprint, new GUIContent("Blueprint"));
|
||||
|
||||
if (actor.rodBlueprint == null)
|
||||
{
|
||||
if (GUILayout.Button("Create", EditorStyles.miniButton, GUILayout.MaxWidth(80)))
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Save blueprint", "Assets/", "RodBlueprint", "asset");
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = FileUtil.GetProjectRelativePath(path);
|
||||
ObiRodBlueprint asset = ScriptableObject.CreateInstance<ObiRodBlueprint>();
|
||||
|
||||
AssetDatabase.CreateAsset(asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
actor.rodBlueprint = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
(t as ObiRod).RemoveFromSolver();
|
||||
(t as ObiRod).ClearState();
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
foreach (var t in targets)
|
||||
(t as ObiRod).AddToSolver();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(massScale, new GUIContent("m_MassScale"));
|
||||
|
||||
DoEditButton();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Collisions", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(collisionMaterial, new GUIContent("Collision material"));
|
||||
EditorGUILayout.PropertyField(selfCollisions, new GUIContent("Self collisions"));
|
||||
EditorGUILayout.PropertyField(surfaceCollisions, new GUIContent("Surface-based collisions"));
|
||||
|
||||
EditorGUILayout.Space();
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(stretchShearConstraintsEnabled, new GUIContent("Stretch & Shear Constraints", Resources.Load<Texture2D>("Icons/ObiStretchShearConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(stretchCompliance, new GUIContent("Stretch compliance"));
|
||||
EditorGUILayout.PropertyField(shear1Compliance, new GUIContent("Shear compliance X"));
|
||||
EditorGUILayout.PropertyField(shear2Compliance, new GUIContent("Shear compliance Y"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(bendTwistConstraintsEnabled, new GUIContent("Bend & Twist Constraints", Resources.Load<Texture2D>("Icons/ObiBendTwistConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(torsionCompliance, new GUIContent("Torsion compliance"));
|
||||
EditorGUILayout.PropertyField(bend1Compliance, new GUIContent("Bend compliance X"));
|
||||
EditorGUILayout.PropertyField(bend2Compliance, new GUIContent("Bend compliance Y"));
|
||||
EditorGUILayout.PropertyField(plasticYield, new GUIContent("Plastic yield"));
|
||||
EditorGUILayout.PropertyField(plasticCreep, new GUIContent("Plastic creep"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(aerodynamicsEnabled, new GUIContent("Aerodynamics", Resources.Load<Texture2D>("Icons/ObiAerodynamicConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(drag, new GUIContent("Drag"));
|
||||
EditorGUILayout.PropertyField(lift, new GUIContent("Lift"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(chainConstraintsEnabled, new GUIContent("Chain Constraints", Resources.Load<Texture2D>("Icons/ObiChainConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(tightness, new GUIContent("Tightness"));
|
||||
});
|
||||
|
||||
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void DrawGizmos(ObiRod actor, GizmoType gizmoType)
|
||||
{
|
||||
Handles.color = Color.white;
|
||||
if (actor.rodBlueprint != null)
|
||||
ObiPathHandles.DrawPathHandle(actor.rodBlueprint.path, actor.transform.localToWorldMatrix, actor.rodBlueprint.thickness ,20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d55c0f03ad50c414cacd39520aef2087
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,54 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
[CustomEditor(typeof(ObiRopeChainRenderer)), CanEditMultipleObjects]
|
||||
public class ObiRopeChainRendererEditor : Editor
|
||||
{
|
||||
|
||||
ObiRopeChainRenderer renderer;
|
||||
|
||||
public void OnEnable(){
|
||||
renderer = (ObiRopeChainRenderer)target;
|
||||
}
|
||||
|
||||
[MenuItem("CONTEXT/ObiRopeChainRenderer/Bake mesh")]
|
||||
static void Bake(MenuCommand command)
|
||||
{
|
||||
ObiRopeChainRenderer renderer = (ObiRopeChainRenderer)command.context;
|
||||
|
||||
if (renderer.actor.isLoaded)
|
||||
{
|
||||
var system = renderer.actor.solver.GetRenderSystem<ObiRopeChainRenderer>() as ObiChainRopeRenderSystem;
|
||||
|
||||
if (system != null)
|
||||
{
|
||||
var mesh = new Mesh();
|
||||
system.BakeMesh(renderer, ref mesh, true);
|
||||
ObiEditorUtils.SaveMesh(mesh, "Save chain mesh", "chain mesh");
|
||||
GameObject.DestroyImmediate(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject,"m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed){
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0efaf4d397fcc4b87842866f9a69f07b
|
||||
labels:
|
||||
- ObiRope
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,99 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiRopeCursor)), CanEditMultipleObjects]
|
||||
public class ObiRopeCursorEditor : Editor
|
||||
{
|
||||
SerializedProperty cursorMu;
|
||||
SerializedProperty sourceMu;
|
||||
SerializedProperty direction;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
cursorMu = serializedObject.FindProperty("m_CursorMu");
|
||||
sourceMu = serializedObject.FindProperty("m_SourceMu");
|
||||
direction = serializedObject.FindProperty("direction");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(cursorMu);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var t in targets)
|
||||
(t as ObiRopeCursor).UpdateCursor();
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(sourceMu);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var t in targets)
|
||||
(t as ObiRopeCursor).UpdateSource();
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(direction);
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
private static void DrawArrow()
|
||||
{
|
||||
Gizmos.DrawLine(Vector3.left, Vector3.up);
|
||||
Gizmos.DrawLine(Vector3.right, Vector3.up);
|
||||
Gizmos.DrawLine(Vector3.left, Vector3.down);
|
||||
Gizmos.DrawLine(Vector3.right, Vector3.down);
|
||||
Gizmos.DrawLine(Vector3.left, Vector3.forward);
|
||||
Gizmos.DrawLine(Vector3.right, Vector3.forward);
|
||||
Gizmos.DrawLine(Vector3.up, Vector3.forward);
|
||||
Gizmos.DrawLine(Vector3.down, Vector3.forward);
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void DrawGizmos(ObiRopeCursor cursor, GizmoType gizmoType)
|
||||
{
|
||||
var rope = cursor.GetComponent<ObiRope>();
|
||||
if (rope.isLoaded)
|
||||
{
|
||||
Handles.matrix = rope.solver.transform.localToWorldMatrix;
|
||||
Handles.color = new Color(1, 0.5f, 0.2f, 1);
|
||||
|
||||
// draw source particle:
|
||||
int sourceIndex = cursor.sourceParticleIndex;
|
||||
|
||||
if (sourceIndex >= 0 && rope.IsParticleActive(rope.solver.particleToActor[sourceIndex].indexInActor))
|
||||
{
|
||||
Vector3 pos = rope.solver.positions[sourceIndex];
|
||||
float size = HandleUtility.GetHandleSize(pos) * 0.15f;
|
||||
Handles.SphereHandleCap(0, pos, Quaternion.identity, size, EventType.Repaint);
|
||||
}
|
||||
|
||||
// draw cursor:
|
||||
var element = cursor.cursorElement;
|
||||
|
||||
if (element != null && element.particle1 != element.particle2)
|
||||
{
|
||||
Vector3 pos = rope.solver.positions[cursor.direction ? element.particle1 : element.particle2];
|
||||
Vector3 pos2 = rope.solver.positions[cursor.direction ? element.particle2 : element.particle1];
|
||||
Vector3 direction = pos2 - pos;
|
||||
|
||||
float size = HandleUtility.GetHandleSize(pos) * 0.25f;
|
||||
Handles.ConeHandleCap(0, pos + Vector3.Normalize(direction)*size*0.5f, Quaternion.LookRotation(direction), size, EventType.Repaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3ec1bf77ba7a47b596abdc62069c72b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,219 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.EditorTools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiRope))]
|
||||
public class ObiRopeEditor : Editor
|
||||
{
|
||||
|
||||
[MenuItem("GameObject/3D Object/Obi/Obi Rope", false, 300)]
|
||||
static void CreateObiRope(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = new GameObject("Obi Rope", typeof(ObiRope), typeof(ObiRopeExtrudedRenderer));
|
||||
var renderer = go.GetComponent<ObiRopeExtrudedRenderer>();
|
||||
renderer.material = ObiEditorUtils.GetDefaultMaterial();
|
||||
ObiEditorUtils.PlaceActorRoot(go, menuCommand);
|
||||
}
|
||||
|
||||
ObiRope actor;
|
||||
|
||||
SerializedProperty ropeBlueprint;
|
||||
|
||||
SerializedProperty collisionMaterial;
|
||||
SerializedProperty selfCollisions;
|
||||
SerializedProperty surfaceCollisions;
|
||||
SerializedProperty massScale;
|
||||
|
||||
SerializedProperty distanceConstraintsEnabled;
|
||||
SerializedProperty stretchingScale;
|
||||
SerializedProperty stretchCompliance;
|
||||
SerializedProperty maxCompression;
|
||||
|
||||
SerializedProperty bendConstraintsEnabled;
|
||||
SerializedProperty bendCompliance;
|
||||
SerializedProperty maxBending;
|
||||
SerializedProperty plasticYield;
|
||||
SerializedProperty plasticCreep;
|
||||
|
||||
SerializedProperty aerodynamicsEnabled;
|
||||
SerializedProperty drag;
|
||||
SerializedProperty lift;
|
||||
|
||||
SerializedProperty tearingEnabled;
|
||||
SerializedProperty tearResistanceMultiplier;
|
||||
SerializedProperty tearRate;
|
||||
|
||||
GUIStyle editLabelStyle;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
actor = (ObiRope)target;
|
||||
|
||||
ropeBlueprint = serializedObject.FindProperty("m_RopeBlueprint");
|
||||
|
||||
collisionMaterial = serializedObject.FindProperty("m_CollisionMaterial");
|
||||
selfCollisions = serializedObject.FindProperty("m_SelfCollisions");
|
||||
surfaceCollisions = serializedObject.FindProperty("m_SurfaceCollisions");
|
||||
massScale = serializedObject.FindProperty("m_MassScale");
|
||||
|
||||
distanceConstraintsEnabled = serializedObject.FindProperty("_distanceConstraintsEnabled");
|
||||
stretchingScale = serializedObject.FindProperty("_stretchingScale");
|
||||
stretchCompliance = serializedObject.FindProperty("_stretchCompliance");
|
||||
maxCompression = serializedObject.FindProperty("_maxCompression");
|
||||
|
||||
bendConstraintsEnabled = serializedObject.FindProperty("_bendConstraintsEnabled");
|
||||
bendCompliance = serializedObject.FindProperty("_bendCompliance");
|
||||
maxBending = serializedObject.FindProperty("_maxBending");
|
||||
plasticYield = serializedObject.FindProperty("_plasticYield");
|
||||
plasticCreep = serializedObject.FindProperty("_plasticCreep");
|
||||
|
||||
aerodynamicsEnabled = serializedObject.FindProperty("_aerodynamicsEnabled");
|
||||
drag = serializedObject.FindProperty("_drag");
|
||||
lift = serializedObject.FindProperty("_lift");
|
||||
|
||||
tearingEnabled = serializedObject.FindProperty("tearingEnabled");
|
||||
tearResistanceMultiplier = serializedObject.FindProperty("tearResistanceMultiplier");
|
||||
tearRate = serializedObject.FindProperty("tearRate");
|
||||
|
||||
}
|
||||
|
||||
private void DoEditButton()
|
||||
{
|
||||
using (new EditorGUI.DisabledScope(actor.ropeBlueprint == null))
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
bool edit = GUILayout.Toggle(ToolManager.activeToolType == typeof(ObiPathEditor), new GUIContent(Resources.Load<Texture2D>("EditCurves")), "Button", GUILayout.MaxWidth(36), GUILayout.MaxHeight(24));
|
||||
EditorGUILayout.LabelField("Edit path", editLabelStyle, GUILayout.ExpandHeight(true), GUILayout.MaxHeight(24));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
if (edit)
|
||||
ToolManager.SetActiveTool<ObiPathEditor>();
|
||||
else
|
||||
ToolManager.RestorePreviousPersistentTool();
|
||||
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (editLabelStyle == null)
|
||||
{
|
||||
editLabelStyle = new GUIStyle(GUI.skin.label);
|
||||
editLabelStyle.alignment = TextAnchor.MiddleLeft;
|
||||
}
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
if (actor.sourceBlueprint != null && actor.ropeBlueprint.path.ControlPointCount < 2)
|
||||
{
|
||||
actor.ropeBlueprint.GenerateImmediate();
|
||||
}
|
||||
|
||||
using (new EditorGUI.DisabledScope(ToolManager.activeToolType == typeof(ObiPathEditor)))
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(ropeBlueprint, new GUIContent("Blueprint"));
|
||||
|
||||
if (actor.ropeBlueprint == null)
|
||||
{
|
||||
if (GUILayout.Button("Create", EditorStyles.miniButton, GUILayout.MaxWidth(80)))
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Save blueprint", "Assets/", "RopeBlueprint", "asset");
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = FileUtil.GetProjectRelativePath(path);
|
||||
ObiRopeBlueprint asset = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
|
||||
|
||||
AssetDatabase.CreateAsset(asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
actor.ropeBlueprint = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
(t as ObiRope).RemoveFromSolver();
|
||||
(t as ObiRope).ClearState();
|
||||
}
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
foreach (var t in targets)
|
||||
(t as ObiRope).AddToSolver();
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUI.enabled = !Application.isPlaying;
|
||||
EditorGUILayout.PropertyField(massScale, new GUIContent("Mass scale"));
|
||||
GUI.enabled = true;
|
||||
|
||||
DoEditButton();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Collisions", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(collisionMaterial, new GUIContent("Collision material"));
|
||||
EditorGUILayout.PropertyField(selfCollisions, new GUIContent("Self collisions"));
|
||||
EditorGUILayout.PropertyField(surfaceCollisions, new GUIContent("Surface-based collisions"));
|
||||
|
||||
EditorGUILayout.Space();
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(tearingEnabled, new GUIContent("Tearing"),
|
||||
() =>
|
||||
{
|
||||
EditorGUILayout.PropertyField(tearResistanceMultiplier, new GUIContent("Tear resistance"));
|
||||
EditorGUILayout.PropertyField(tearRate, new GUIContent("Tear rate"));
|
||||
});
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(distanceConstraintsEnabled, new GUIContent("Distance Constraints", Resources.Load<Texture2D>("Icons/ObiDistanceConstraints Icon")),
|
||||
() =>
|
||||
{
|
||||
EditorGUILayout.PropertyField(stretchingScale, new GUIContent("Stretching scale"));
|
||||
EditorGUILayout.PropertyField(stretchCompliance, new GUIContent("Stretch compliance"));
|
||||
EditorGUILayout.PropertyField(maxCompression, new GUIContent("Max compression"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(bendConstraintsEnabled, new GUIContent("Bend Constraints", Resources.Load<Texture2D>("Icons/ObiBendConstraints Icon")),
|
||||
() =>
|
||||
{
|
||||
EditorGUILayout.PropertyField(bendCompliance, new GUIContent("Bend compliance"));
|
||||
EditorGUILayout.PropertyField(maxBending, new GUIContent("Max bending"));
|
||||
EditorGUILayout.PropertyField(plasticYield, new GUIContent("Plastic yield"));
|
||||
EditorGUILayout.PropertyField(plasticCreep, new GUIContent("Plastic creep"));
|
||||
});
|
||||
|
||||
ObiEditorUtils.DoToggleablePropertyGroup(aerodynamicsEnabled, new GUIContent("Aerodynamics", Resources.Load<Texture2D>("Icons/ObiAerodynamicConstraints Icon")),
|
||||
() => {
|
||||
EditorGUILayout.PropertyField(drag, new GUIContent("Drag"));
|
||||
EditorGUILayout.PropertyField(lift, new GUIContent("Lift"));
|
||||
});
|
||||
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void DrawGizmos(ObiRope actor, GizmoType gizmoType)
|
||||
{
|
||||
Handles.color = Color.white;
|
||||
if (actor.ropeBlueprint != null)
|
||||
ObiPathHandles.DrawPathHandle(actor.ropeBlueprint.path, actor.transform.localToWorldMatrix, actor.ropeBlueprint.thickness, 20, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7e5f7e0daf504c86885734478e9c965
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
[CustomEditor(typeof(ObiRopeExtrudedRenderer)), CanEditMultipleObjects]
|
||||
public class ObiRopeExtrudedRendererEditor : Editor
|
||||
{
|
||||
|
||||
ObiRopeExtrudedRenderer renderer;
|
||||
|
||||
public void OnEnable(){
|
||||
renderer = (ObiRopeExtrudedRenderer)target;
|
||||
}
|
||||
|
||||
[MenuItem("CONTEXT/ObiRopeExtrudedRenderer/Bake mesh")]
|
||||
static void Bake(MenuCommand command)
|
||||
{
|
||||
ObiRopeExtrudedRenderer renderer = (ObiRopeExtrudedRenderer)command.context;
|
||||
|
||||
if (renderer.actor.isLoaded)
|
||||
{
|
||||
var system = renderer.actor.solver.GetRenderSystem<ObiRopeExtrudedRenderer>() as ObiExtrudedRopeRenderSystem;
|
||||
|
||||
if (system != null)
|
||||
{
|
||||
var mesh = new Mesh();
|
||||
system.BakeMesh(renderer, ref mesh, true);
|
||||
ObiEditorUtils.SaveMesh(mesh, "Save rope mesh", "rope mesh");
|
||||
GameObject.DestroyImmediate(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject,"m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed){
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d0e145ce66cd47e798bf4b926eddfc2
|
||||
labels:
|
||||
- ObiRope
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,38 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
[CustomEditor(typeof(ObiRopeLineRenderer)), CanEditMultipleObjects]
|
||||
public class ObiRopeLineRendererEditor : Editor
|
||||
{
|
||||
|
||||
ObiRopeLineRenderer renderer;
|
||||
|
||||
public void OnEnable(){
|
||||
renderer = (ObiRopeLineRenderer)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject,"m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed){
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
//renderer.UpdateRenderer(null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0a72c38772bb454dabc7efc5b8f03be
|
||||
labels:
|
||||
- ObiRope
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,52 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
[CustomEditor(typeof(ObiRopeMeshRenderer)), CanEditMultipleObjects]
|
||||
public class ObiRopeMeshRendererEditor : Editor
|
||||
{
|
||||
|
||||
ObiRopeMeshRenderer renderer;
|
||||
|
||||
[MenuItem("CONTEXT/ObiRopeMeshRenderer/Bake mesh")]
|
||||
static void Bake(MenuCommand command)
|
||||
{
|
||||
ObiRopeMeshRenderer renderer = (ObiRopeMeshRenderer)command.context;
|
||||
|
||||
if (renderer.actor.isLoaded)
|
||||
{
|
||||
var system = renderer.actor.solver.GetRenderSystem<ObiRopeMeshRenderer>() as ObiMeshRopeRenderSystem;
|
||||
|
||||
if (system != null)
|
||||
{
|
||||
var mesh = new Mesh();
|
||||
system.BakeMesh(renderer, ref mesh, true);
|
||||
ObiEditorUtils.SaveMesh(mesh, "Save rope mesh", "rope mesh");
|
||||
GameObject.DestroyImmediate(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnable(){
|
||||
renderer = (ObiRopeMeshRenderer)target;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject,"m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed){
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 297abfc8979aa46329f3a7e914866adc
|
||||
labels:
|
||||
- ObiRope
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,213 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
/**
|
||||
* Custom inspector for ObiParticleRenderer component.
|
||||
*/
|
||||
|
||||
[CustomEditor(typeof(ObiRopeSection))]
|
||||
public class ObiRopeSectionEditor : Editor
|
||||
{
|
||||
|
||||
ObiRopeSection section;
|
||||
bool[] selected = new bool[0];
|
||||
|
||||
Color previewBck = new Color(0.2f,0.2f,0.2f,1);
|
||||
Color previewLines = new Color(0.15f,0.15f,0.15f,1);
|
||||
|
||||
public void OnEnable(){
|
||||
section = (ObiRopeSection)target;
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI(){
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ResetSelection(){
|
||||
selected = new bool[section.Segments];
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
Editor.DrawPropertiesExcluding(serializedObject,"m_Script");
|
||||
|
||||
GUI.enabled = !EditorApplication.isPlaying;
|
||||
GUILayout.Label("Presets");
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("4-segment circle")){
|
||||
Undo.RecordObject(section, "Set rope section preset");
|
||||
section.CirclePreset(4);
|
||||
ResetSelection();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("8-segment circle")){
|
||||
Undo.RecordObject(section, "Set rope section preset");
|
||||
section.CirclePreset(8);
|
||||
ResetSelection();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("12-segment circle")){
|
||||
Undo.RecordObject(section, "Set rope section preset");
|
||||
section.CirclePreset(12);
|
||||
ResetSelection();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("16-segment circle")){
|
||||
Undo.RecordObject(section, "Set rope section preset");
|
||||
section.CirclePreset(16);
|
||||
ResetSelection();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label("Tools");
|
||||
if (GUILayout.Button("Add vertex")){
|
||||
Undo.RecordObject(section, "Add rope vertex");
|
||||
section.vertices.Add(Vector2.zero);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Remove selected vertices")){
|
||||
Undo.RecordObject(section, "Remove rope vertices");
|
||||
for (int i = selected.Length-1; i > 0; --i){
|
||||
if (selected[i] && section.vertices.Count > 3)
|
||||
section.vertices.RemoveAt(i);
|
||||
}
|
||||
// special cases: first vertex:
|
||||
if (selected[0] && section.vertices.Count > 3){
|
||||
section.vertices.RemoveAt(0);
|
||||
section.vertices[section.vertices.Count-1] = section.vertices[0];
|
||||
}
|
||||
|
||||
ResetSelection();
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed){
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DrawSectionOutline(Rect region, Color color){
|
||||
// Draw segment lines:
|
||||
Handles.BeginGUI( );
|
||||
Color oldColor = Handles.color;
|
||||
Handles.color = color;
|
||||
Vector3[] points = new Vector3[section.vertices.Count];
|
||||
for (int i = 0; i < section.vertices.Count; i++){
|
||||
points[i] = new Vector3(region.center.x + section.vertices[i].x * region.width * 0.5f,
|
||||
region.center.y + section.vertices[i].y * region.height * 0.5f,0);
|
||||
}
|
||||
Handles.DrawAAPolyLine(points);
|
||||
Handles.EndGUI();
|
||||
Handles.color = oldColor;
|
||||
}
|
||||
|
||||
private void DrawDrawingArea(Rect region){
|
||||
// Draw drawing area grid:
|
||||
Handles.BeginGUI();
|
||||
Handles.DrawSolidRectangleWithOutline(region,previewBck,previewLines);
|
||||
|
||||
Color oldColor = Handles.color;
|
||||
Handles.color = previewLines;
|
||||
|
||||
if (section.snapX > 5){
|
||||
float x = region.center.x;
|
||||
while (x < region.xMax){
|
||||
Handles.DrawLine(new Vector3(x,region.yMin,0),new Vector3(x,region.yMax,0));
|
||||
x += section.snapX;
|
||||
}
|
||||
x = region.center.x - section.snapX;
|
||||
while (x > region.xMin){
|
||||
Handles.DrawLine(new Vector3(x,region.yMin,0),new Vector3(x,region.yMax,0));
|
||||
x -= section.snapX;
|
||||
}
|
||||
}
|
||||
|
||||
if (section.snapY > 5){
|
||||
float y = region.center.y;
|
||||
while (y < region.yMax){
|
||||
Handles.DrawLine(new Vector3(region.xMin,y,0),new Vector3(region.xMax,y,0));
|
||||
y += section.snapY;
|
||||
}
|
||||
y = region.center.y - section.snapY;
|
||||
while (y > region.yMin){
|
||||
Handles.DrawLine(new Vector3(region.xMin,y,0),new Vector3(region.xMax,y,0));
|
||||
y -= section.snapY;
|
||||
}
|
||||
}
|
||||
|
||||
Handles.color = oldColor;
|
||||
Handles.EndGUI();
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI(Rect region, GUIStyle background)
|
||||
{
|
||||
DrawSectionOutline(region, Color.red);
|
||||
}
|
||||
|
||||
public override void OnInteractivePreviewGUI(Rect region, GUIStyle background)
|
||||
{
|
||||
Array.Resize(ref selected,section.Segments);
|
||||
|
||||
// Calculate drawing area rect:
|
||||
Vector2 oldCenter = region.center;
|
||||
if (region.width > region.height)
|
||||
region.width = region.height;
|
||||
if (region.height > region.width)
|
||||
region.height = region.width;
|
||||
|
||||
region.width -= 10;
|
||||
region.height -= 15;
|
||||
|
||||
region.center = oldCenter;
|
||||
|
||||
// Draw background and lines:
|
||||
DrawDrawingArea(region);
|
||||
|
||||
// Draw the section outline:
|
||||
DrawSectionOutline(region, Color.white);
|
||||
|
||||
// Draw all draggable vertices:
|
||||
for (int i = 0; i < section.Segments; i++){
|
||||
|
||||
float x = region.center.x + section.vertices[i].x * region.width * 0.5f;
|
||||
float y = region.center.y + section.vertices[i].y * region.height * 0.5f;
|
||||
Vector2 pos = new Vector2(x,y);
|
||||
|
||||
bool oldSelection = selected[i];
|
||||
Vector2 olsPos = pos;
|
||||
selected[i] = ObiDraggableIcon.Draw(selected[i],i,ref pos,Color.red);
|
||||
|
||||
if (selected[i] != oldSelection)
|
||||
this.Repaint();
|
||||
|
||||
if (pos != olsPos){
|
||||
|
||||
pos.x = Mathf.Clamp(ObiRopeSection.SnapTo(pos.x - region.center.x,section.snapX,5) / (region.width * 0.5f),-1,1);
|
||||
pos.y = Mathf.Clamp(ObiRopeSection.SnapTo(pos.y - region.center.y,section.snapY,5) / (region.height * 0.5f),-1,1);
|
||||
section.vertices[i] = pos;
|
||||
if (i == 0)
|
||||
section.vertices[section.Segments] = pos;
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1539d8c58261942e28859228dfa310fb
|
||||
labels:
|
||||
- ObiRope
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72e3dd3ad91bf485099095b5e59ff81b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,169 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiPinhole))]
|
||||
public class ObiPinholeEditor : Editor
|
||||
{
|
||||
|
||||
SerializedProperty targetTransform;
|
||||
SerializedProperty position;
|
||||
SerializedProperty limitRange;
|
||||
SerializedProperty range;
|
||||
SerializedProperty compliance;
|
||||
SerializedProperty friction;
|
||||
SerializedProperty motorSpeed;
|
||||
SerializedProperty motorForce;
|
||||
SerializedProperty clamp;
|
||||
SerializedProperty breakThreshold;
|
||||
|
||||
ObiPinhole pinhole;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
|
||||
pinhole = target as ObiPinhole;
|
||||
targetTransform = serializedObject.FindProperty("m_Target");
|
||||
position = serializedObject.FindProperty("m_Position");
|
||||
limitRange = serializedObject.FindProperty("m_LimitRange");
|
||||
range = serializedObject.FindProperty("m_Range");
|
||||
friction = serializedObject.FindProperty("m_Friction");
|
||||
motorSpeed = serializedObject.FindProperty("m_MotorSpeed");
|
||||
motorForce = serializedObject.FindProperty("m_MotorForce");
|
||||
compliance = serializedObject.FindProperty("m_Compliance");
|
||||
clamp = serializedObject.FindProperty("m_ClampAtEnds");
|
||||
breakThreshold = serializedObject.FindProperty("breakThreshold");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
// warn about incorrect setups:
|
||||
if (!targetTransform.hasMultipleDifferentValues)
|
||||
{
|
||||
var targetValue = targetTransform.objectReferenceValue as UnityEngine.Component;
|
||||
if (targetValue != null)
|
||||
{
|
||||
var collider = targetValue.GetComponent<ObiColliderBase>();
|
||||
if (collider == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Pinholes require the target object to have a ObiCollider component. Please add one.", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Transform trget = EditorGUILayout.ObjectField("Target", pinhole.target, typeof(Transform), true) as Transform;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(pinhole, "Set target");
|
||||
pinhole.target = trget;
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(pinhole);
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(position, new GUIContent("Position"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
pinhole.CalculateMu();
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(limitRange, new GUIContent("Limit Range"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
pinhole.CalculateRange();
|
||||
}
|
||||
|
||||
if (limitRange.boolValue)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(range, new GUIContent("Range"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
pinhole.CalculateRange();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
EditorGUILayout.PropertyField(clamp, new GUIContent("Clamp at ends"));
|
||||
EditorGUILayout.PropertyField(friction, new GUIContent("Friction"));
|
||||
EditorGUILayout.PropertyField(motorSpeed, new GUIContent("Motor Target Speed"));
|
||||
EditorGUILayout.PropertyField(motorForce, new GUIContent("Motor Max Force"));
|
||||
EditorGUILayout.PropertyField(compliance, new GUIContent("Compliance"));
|
||||
EditorGUILayout.PropertyField(breakThreshold, new GUIContent("Break threshold"));
|
||||
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
private static void DrawGizmos(ObiPinhole pinhole, GizmoType gizmoType)
|
||||
{
|
||||
var rope = pinhole.GetComponent<ObiRope>();
|
||||
|
||||
var ropeBlueprint = rope.sharedBlueprint as ObiRopeBlueprintBase;
|
||||
if (rope.isLoaded && ropeBlueprint != null && ropeBlueprint.deformableEdges != null)
|
||||
{
|
||||
Handles.color = new Color(1, 0.5f, 0.2f, 1);
|
||||
Handles.matrix = rope.solver.transform.localToWorldMatrix;
|
||||
|
||||
// draw limits:
|
||||
if (pinhole.limitRange)
|
||||
{
|
||||
for (int i = pinhole.firstEdge.edgeIndex; i <= pinhole.lastEdge.edgeIndex; ++i)
|
||||
{
|
||||
if (i >= 0 && i < ropeBlueprint.deformableEdges.Length)
|
||||
{
|
||||
int p1 = ropeBlueprint.deformableEdges[i * 2];
|
||||
int p2 = ropeBlueprint.deformableEdges[i * 2 + 1];
|
||||
var pos1 = rope.solver.positions[rope.solverIndices[p1]];
|
||||
var pos2 = rope.solver.positions[rope.solverIndices[p2]];
|
||||
|
||||
if (i == pinhole.firstEdge.edgeIndex)
|
||||
{
|
||||
pos1 = Vector4.Lerp(pos1, pos2, pinhole.firstEdge.coordinate);
|
||||
Handles.DrawSolidDisc(pos1, pos2 - pos1, HandleUtility.GetHandleSize(pos1) * 0.05f);
|
||||
}
|
||||
if (i == pinhole.lastEdge.edgeIndex)
|
||||
{
|
||||
pos2 = Vector4.Lerp(pos1, pos2, pinhole.lastEdge.coordinate);
|
||||
Handles.DrawSolidDisc(pos2, pos1 - pos2, HandleUtility.GetHandleSize(pos2) * 0.05f);
|
||||
}
|
||||
|
||||
Handles.DrawLine(pos1, pos2, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw source particle:
|
||||
int edgeIndex = pinhole.edgeIndex;
|
||||
|
||||
if (edgeIndex >= 0 && edgeIndex < ropeBlueprint.deformableEdges.Length)
|
||||
{
|
||||
int p1 = ropeBlueprint.deformableEdges[edgeIndex * 2];
|
||||
int p2 = ropeBlueprint.deformableEdges[edgeIndex * 2 + 1];
|
||||
var pos1 = rope.solver.positions[rope.solverIndices[p1]];
|
||||
var pos2 = rope.solver.positions[rope.solverIndices[p2]];
|
||||
Vector4 pos = Vector4.Lerp(pos1, pos2, pinhole.edgeCoordinate);
|
||||
Handles.DrawWireDisc(pos, pos1 - pos2, HandleUtility.GetHandleSize(pos) * 0.1f, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f58defb5faddb428ea91cd06eecd8729
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user