去掉obi,使用自写绳索

This commit is contained in:
2026-02-23 20:51:03 +08:00
parent cb636f862d
commit 91e2309eeb
2011 changed files with 2593 additions and 190578 deletions

View File

@@ -1,46 +0,0 @@
using UnityEditor;
namespace Obi
{
public class BooleanPreference
{
bool m_Value;
string m_Name;
bool m_Loaded;
public BooleanPreference(string name, bool value)
{
m_Name = name;
m_Loaded = false;
m_Value = value;
}
private void Load()
{
if (m_Loaded)
return;
m_Loaded = true;
m_Value = EditorPrefs.GetBool(m_Name, m_Value);
}
public bool value
{
get { Load(); return m_Value; }
set
{
Load();
if (m_Value == value)
return;
m_Value = value;
EditorPrefs.SetBool(m_Name, value);
}
}
public static implicit operator bool(BooleanPreference s)
{
return s.value;
}
}
}

View File

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

View File

@@ -1,254 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.IO;
using UnityEngine.Rendering;
namespace Obi{
public static class ObiEditorUtils
{
static GUIStyle separatorLine;
static GUIStyle toggleablePropertyGroup;
static GUIStyle boldToggle;
public static GUIStyle GetSeparatorLineStyle()
{
if (separatorLine == null)
{
separatorLine = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene).box);
separatorLine.normal.background = Resources.Load<Texture2D>("SeparatorLine");
separatorLine.border = new RectOffset(3, 3, 0, 0);
separatorLine.padding = new RectOffset(0, 0, 0, 0);
separatorLine.margin = new RectOffset(0, 0, 0, 0);
separatorLine.fixedHeight = 3;
separatorLine.stretchWidth = true;
}
return separatorLine;
}
public static GUIStyle GetToggleablePropertyGroupStyle()
{
if (toggleablePropertyGroup == null)
{
toggleablePropertyGroup = new GUIStyle();
toggleablePropertyGroup.normal.background = Resources.Load<Texture2D>("ToggleableGroupBg");
toggleablePropertyGroup.border = new RectOffset(3, 3, 3, 3);
toggleablePropertyGroup.padding = new RectOffset(0, 0, 0, 0);
toggleablePropertyGroup.margin = new RectOffset(0, 0, 3, 3);
}
return toggleablePropertyGroup;
}
public static GUIStyle GetBoldToggleStyle()
{
if (boldToggle == null)
{
boldToggle = new GUIStyle(EditorStyles.toggle);
boldToggle.fontStyle = FontStyle.Bold;
}
return boldToggle;
}
public static void SaveMesh (Mesh mesh, string title, string name, bool makeNewInstance = true, bool optimizeMesh = true) {
string path = EditorUtility.SaveFilePanel(title, "Assets/", name, "asset");
if (string.IsNullOrEmpty(path)) return;
path = FileUtil.GetProjectRelativePath(path);
Mesh meshToSave = (makeNewInstance) ? GameObject.Instantiate(mesh) as Mesh : mesh;
if (optimizeMesh)
MeshUtility.Optimize(meshToSave);
AssetDatabase.CreateAsset(meshToSave, path);
AssetDatabase.SaveAssets();
}
public static void PlaceActorRoot(GameObject element, MenuCommand menuCommand)
{
GameObject parent = menuCommand.context as GameObject;
if (parent == null)
{
parent = GetOrCreateSolverObject();
}
if (parent.GetComponentsInParent<ObiSolver>(true).Length == 0)
{
// Create solver under context GameObject,
// and make that be the parent which actor is added under.
GameObject solver = CreateNewSolver();
solver.transform.SetParent(parent.transform, false);
parent = solver;
}
// The element needs to be already in its destination scene when the
// RegisterCreatedObjectUndo is performed; otherwise the scene it was created in is dirtied.
SceneManager.MoveGameObjectToScene(element, parent.scene);
Undo.RegisterCreatedObjectUndo(element, "Create " + element.name);
if (element.transform.parent == null)
Undo.SetTransformParent(element.transform, parent.transform, "Parent " + element.name);
GameObjectUtility.EnsureUniqueNameForSibling(element);
// We have to fix up the undo name since the name of the object was only known after reparenting it.
Undo.SetCurrentGroupName("Create " + element.name);
GameObjectUtility.SetParentAndAlign(element, parent);
Selection.activeGameObject = element;
}
// Helper function that returns a Solver GameObject; preferably a parent of the selection, or other existing Canvas.
private static GameObject GetOrCreateSolverObject()
{
GameObject selectedGo = Selection.activeGameObject;
// Try to find a gameobject that is the selected GO or one if its parents.
ObiSolver solver = (selectedGo != null) ? selectedGo.GetComponentInParent<ObiSolver>() : null;
if (IsValidSolver(solver))
return solver.gameObject;
// No solver in selection or its parents? Then use any valid solver.
// We have to find all loaded solvers, not just the ones in main scenes.
ObiSolver[] solverArray = StageUtility.GetCurrentStageHandle().FindComponentsOfType<ObiSolver>();
for (int i = 0; i < solverArray.Length; i++)
if (IsValidSolver(solverArray[i]))
return solverArray[i].gameObject;
// No solver in the scene at all? Then create a new one.
return CreateNewSolver();
}
public static GameObject CreateNewSolver()
{
// Root for the actors.
var root = new GameObject("Obi Solver", typeof(ObiSolver));
// Works for all stages.
StageUtility.PlaceGameObjectInCurrentStage(root);
Undo.RegisterCreatedObjectUndo(root, "Create " + root.name);
return root;
}
static bool IsValidSolver(ObiSolver solver)
{
if (solver == null || !solver.gameObject.activeInHierarchy)
return false;
if (EditorUtility.IsPersistent(solver) || (solver.hideFlags & HideFlags.HideInHierarchy) != 0)
return false;
if (StageUtility.GetStageHandle(solver.gameObject) != StageUtility.GetCurrentStageHandle())
return false;
return true;
}
public static void DoPropertyGroup(GUIContent content, System.Action action)
{
EditorGUILayout.BeginVertical(GetToggleablePropertyGroupStyle());
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(content, EditorStyles.boldLabel);
EditorGUILayout.EndHorizontal();
if (action != null)
{
EditorGUI.indentLevel++;
action();
EditorGUI.indentLevel--;
}
}
EditorGUILayout.EndVertical();
}
public static void DoToggleablePropertyGroup(SerializedProperty enabledProperty, GUIContent content, System.Action action)
{
bool enabled = GUI.enabled;
GUI.enabled &= enabledProperty.boolValue;
EditorGUILayout.BeginVertical(GetToggleablePropertyGroupStyle());
GUI.enabled = enabled;
{
EditorGUILayout.BeginHorizontal();
enabledProperty.boolValue = EditorGUILayout.ToggleLeft(content,enabledProperty.boolValue,EditorStyles.boldLabel);
EditorGUILayout.EndHorizontal();
if (enabledProperty.boolValue && action != null)
{
EditorGUI.indentLevel++;
action();
EditorGUI.indentLevel--;
}
}
EditorGUILayout.EndVertical();
}
public static int DoToolBar(int selected, GUIContent[] items)
{
// Keep the selected index within the bounds of the items array
selected = selected < 0 ? 0 : selected >= items.Length ? items.Length - 1 : selected;
GUIStyle style = GUI.skin.FindStyle("Button");
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
for (int i = 0; i < items.Length; i++)
{
if (i == 0 && items.Length > 1)
style = GUI.skin.FindStyle("ButtonLeft");
else if (items.Length > 1 && i == items.Length-1)
style = GUI.skin.FindStyle("ButtonRight");
else if (i > 0)
style = GUI.skin.FindStyle("ButtonMid");
// Display toggle. Get if toggle changed.
bool change = GUILayout.Toggle(selected == i, items[i],style,GUILayout.Height(24));
// If changed, set selected to current index.
if (change)
selected = i;
}
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
// Return the currently selected item's index
return selected;
}
public static void DrawArrowHandle(Vector3 posA, Vector3 posB, float headAngle = 30, float headLength = 0.18f)
{
Handles.DrawLine(posA, posB);
var look = Quaternion.LookRotation(posA - posB, Camera.current.transform.forward);
var one = look * Quaternion.Euler(0, 180 + headAngle, 0) * new Vector3(0, 0, 1);
var two = look * Quaternion.Euler(0, 180 - headAngle, 0) * new Vector3(0, 0, 1);
var sizeA = HandleUtility.GetHandleSize(posA) * headLength;
Handles.DrawLine(posA, posA + one * sizeA);
Handles.DrawLine(posA, posA + two * sizeA);
var sizeB = HandleUtility.GetHandleSize(posB) * headLength;
Handles.DrawLine(posB, posB - one * sizeB);
Handles.DrawLine(posB, posB - two * sizeB);
}
public static Material GetDefaultMaterial()
{
if (GraphicsSettings.defaultRenderPipeline != null)
{
return GraphicsSettings.defaultRenderPipeline.defaultMaterial;
}
else
{
return AssetDatabase.GetBuiltinExtraResource<Material>("Default-Diffuse.mat");
}
}
}
}

View File

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

View File

@@ -1,24 +0,0 @@
using UnityEditor;
using UnityEngine;
namespace Obi
{
[CustomEditor(typeof(ObiFoamGenerator)), CanEditMultipleObjects]
public class ObiFoamGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
serializedObject.UpdateIfRequiredOrScript();
DrawPropertiesExcluding(serializedObject, "m_Script");
// Apply changes to the serializedProperty
if (GUI.changed)
serializedObject.ApplyModifiedProperties();
}
}
}

View File

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

View File

@@ -1,124 +0,0 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
namespace Obi
{
[CustomEditor(typeof(ObiParticleAttachment))]
public class ObiParticleAttachmentEditor : Editor
{
SerializedProperty targetTransform;
SerializedProperty particleGroup;
SerializedProperty attachmentType;
SerializedProperty projectPosition;
SerializedProperty constrainOrientation;
SerializedProperty compliance;
SerializedProperty breakThreshold;
ObiParticleAttachment attachment;
public void OnEnable()
{
attachment = target as ObiParticleAttachment;
targetTransform = serializedObject.FindProperty("m_Target");
particleGroup = serializedObject.FindProperty("m_ParticleGroup");
attachmentType = serializedObject.FindProperty("m_AttachmentType");
projectPosition = serializedObject.FindProperty("m_Projection");
constrainOrientation = serializedObject.FindProperty("m_ConstrainOrientation");
compliance = serializedObject.FindProperty("m_Compliance");
breakThreshold = serializedObject.FindProperty("breakThreshold");
}
public override void OnInspectorGUI()
{
serializedObject.UpdateIfRequiredOrScript();
// warn about incorrect setups:
if (!attachmentType.hasMultipleDifferentValues && !targetTransform.hasMultipleDifferentValues)
{
if (attachmentType.enumValueIndex == (int)ObiParticleAttachment.AttachmentType.Dynamic)
{
var targetValue = targetTransform.objectReferenceValue as UnityEngine.Component;
if (targetValue != null)
{
var collider = targetValue.GetComponent<ObiColliderBase>();
if (collider == null)
{
EditorGUILayout.HelpBox("Dynamic attachments require the target object to have a ObiCollider component. Either add one, or change the attachment type to Static.", MessageType.Warning);
}
}
}
}
EditorGUI.BeginChangeCheck();
Transform trget = EditorGUILayout.ObjectField("Target", attachment.target, typeof(Transform), true) as Transform;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(attachment, "Set target");
attachment.target = trget;
PrefabUtility.RecordPrefabInstancePropertyModifications(attachment);
}
var blueprint = attachment.actor.sourceBlueprint;
if (blueprint != null)
{
var rect = EditorGUILayout.GetControlRect();
var label = EditorGUI.BeginProperty(rect, new GUIContent("Particle group"), particleGroup);
rect = EditorGUI.PrefixLabel(rect, label);
if (GUI.Button(rect, attachment.particleGroup != null ? attachment.particleGroup.name : "None", EditorStyles.popup))
{
// create the menu and add items to it
GenericMenu menu = new GenericMenu();
menu.allowDuplicateNames = true;
for (int i = 0; i < blueprint.groups.Count; ++i)
{
menu.AddItem(new GUIContent(blueprint.groups[i].name), blueprint.groups[i] == attachment.particleGroup, OnParticleGroupSelected, blueprint.groups[i]);
}
// display the menu
menu.DropDown(rect);
}
EditorGUI.EndProperty();
}
EditorGUILayout.PropertyField(attachmentType, new GUIContent("Type"));
if (attachment.actor.usesOrientedParticles)
EditorGUILayout.PropertyField(constrainOrientation, new GUIContent("Constraint Orientation"));
if (attachment.attachmentType == ObiParticleAttachment.AttachmentType.Dynamic)
{
EditorGUILayout.PropertyField(projectPosition, new GUIContent("Projection"));
EditorGUILayout.PropertyField(compliance, new GUIContent("Compliance"));
EditorGUILayout.PropertyField(breakThreshold, new GUIContent("Break threshold"));
}
if (GUI.changed)
serializedObject.ApplyModifiedProperties();
}
// the GenericMenu.MenuFunction2 event handler for when a menu item is selected
void OnParticleGroupSelected(object index)
{
Undo.RecordObject(attachment, "Set particle group");
attachment.particleGroup = index as ObiParticleGroup;
PrefabUtility.RecordPrefabInstancePropertyModifications(attachment);
}
}
}

View File

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

View File

@@ -1,26 +0,0 @@
using UnityEngine;
using System.Collections.Generic;
namespace Obi
{
public class ObiRaycastHit
{
/// Distance from the Raycast origin to the point of impact.
public float distance;
/// The position in model space where a raycast intercepted a triangle.
public Vector3 position;
/// The normal in model space of the triangle that this raycast hit.
public Vector3 normal;
/// The triangle index of the hit face.
public int triangle;
public ObiRaycastHit(float distance, Vector3 position, Vector3 normal, int triangle)
{
this.distance = distance;
this.position = position;
this.normal = normal;
this.triangle = triangle;
}
}
}

View File

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

View File

@@ -1,150 +0,0 @@
using System;
using UnityEditor;
using UnityEngine;
namespace Obi{
class PreviewHelpers
{
// Preview interaction related stuff:
static int sliderHash = "Slider".GetHashCode();
public static Vector2 Drag2D(Vector2 scrollPosition, Rect position)
{
int controlID = GUIUtility.GetControlID(PreviewHelpers.sliderHash, FocusType.Passive);
Event current = Event.current;
switch (current.GetTypeForControl(controlID))
{
case EventType.MouseDown:
if (position.Contains(current.mousePosition) && position.width > 50f)
{
GUIUtility.hotControl = controlID;
current.Use();
EditorGUIUtility.SetWantsMouseJumping(1);
}
break;
case EventType.MouseUp:
if (GUIUtility.hotControl == controlID)
{
GUIUtility.hotControl = 0;
}
EditorGUIUtility.SetWantsMouseJumping(0);
break;
case EventType.MouseDrag:
if (GUIUtility.hotControl == controlID)
{
scrollPosition -= current.delta * (float)((!current.shift) ? 1 : 3) / Mathf.Min(position.width, position.height) * 140f;
scrollPosition.y = Mathf.Clamp(scrollPosition.y, -90f, 90f);
current.Use();
GUI.changed = true;
}
break;
}
return scrollPosition;
}
public Camera m_Camera;
public float m_CameraFieldOfView = 30f;
public Light[] m_Light = new Light[2];
internal RenderTexture m_RenderTexture;
public PreviewHelpers() : this(false)
{
}
public PreviewHelpers(bool renderFullScene)
{
GameObject gameObject = EditorUtility.CreateGameObjectWithHideFlags("PreRenderCamera", HideFlags.HideAndDontSave, new Type[]
{
typeof(Camera)
});
this.m_Camera = gameObject.GetComponent<Camera>();
this.m_Camera.fieldOfView = this.m_CameraFieldOfView;
this.m_Camera.cullingMask = 1 << 1;
this.m_Camera.enabled = false;
this.m_Camera.clearFlags = CameraClearFlags.SolidColor;
this.m_Camera.farClipPlane = 10f;
this.m_Camera.nearClipPlane = 1f;
this.m_Camera.backgroundColor = new Color(0.192156866f, 0.192156866f, 0.192156866f, 0);
this.m_Camera.renderingPath = RenderingPath.Forward;
this.m_Camera.useOcclusionCulling = false;
for (int i = 0; i < 2; i++)
{
GameObject gameObject2 = EditorUtility.CreateGameObjectWithHideFlags("PreRenderLight", HideFlags.HideAndDontSave, new Type[]
{
typeof(Light)
});
this.m_Light[i] = gameObject2.GetComponent<Light>();
this.m_Light[i].type = LightType.Directional;
this.m_Light[i].intensity = 1f;
this.m_Light[i].enabled = false;
}
this.m_Light[0].color = new Color(0.4f, 0.4f, 0.45f, 0f);
this.m_Light[1].transform.rotation = Quaternion.Euler(340f, 218f, 177f);
this.m_Light[1].color = new Color(0.4f, 0.4f, 0.45f, 0f) * 0.7f;
}
public void Cleanup()
{
if (this.m_Camera)
{
UnityEngine.Object.DestroyImmediate(this.m_Camera.gameObject, true);
}
if (this.m_RenderTexture)
{
UnityEngine.Object.DestroyImmediate(this.m_RenderTexture);
this.m_RenderTexture = null;
}
Light[] light = this.m_Light;
for (int i = 0; i < light.Length; i++)
{
Light light2 = light[i];
if (light2)
{
UnityEngine.Object.DestroyImmediate(light2.gameObject, true);
}
}
}
private void InitPreview(Rect r)
{
int num = (int)r.width;
int num2 = (int)r.height;
if (!this.m_RenderTexture || this.m_RenderTexture.width != num || this.m_RenderTexture.height != num2)
{
if (this.m_RenderTexture)
{
UnityEngine.Object.DestroyImmediate(this.m_RenderTexture);
this.m_RenderTexture = null;
}
float scaleFactor = this.GetScaleFactor((float)num, (float)num2);
this.m_RenderTexture = new RenderTexture((int)((float)num * scaleFactor), (int)((float)num2 * scaleFactor), 16);
this.m_RenderTexture.hideFlags = HideFlags.HideAndDontSave;
this.m_Camera.targetTexture = this.m_RenderTexture;
}
float num3 = (this.m_RenderTexture.width > 0) ? Mathf.Max(1f, (float)this.m_RenderTexture.height / (float)this.m_RenderTexture.width) : 1f;
this.m_Camera.fieldOfView = Mathf.Atan(num3 * Mathf.Tan(this.m_CameraFieldOfView * 0.5f * 0.0174532924f)) * 57.29578f * 2f;
}
public float GetScaleFactor(float width, float height)
{
float a = Mathf.Max(Mathf.Min(width * 2f, 1024f), width) / width;
float b = Mathf.Max(Mathf.Min(height * 2f, 1024f), height) / height;
return Mathf.Min(a, b);
}
public void BeginPreview(Rect r, GUIStyle previewBackground)
{
this.InitPreview(r);
if (previewBackground == null || previewBackground == GUIStyle.none)
{
return;
}
}
public Texture EndPreview()
{
m_Camera.Render();
return this.m_RenderTexture;
}
}
}

View File

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