修改水
This commit is contained in:
@@ -85,7 +85,7 @@ namespace Obi
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
meshBasedEditor.particleCulling = (ObiMeshBasedActorBlueprintEditor.ParticleCulling)EditorGUILayout.EnumPopup("Culling", meshBasedEditor.particleCulling);
|
||||
if (ObiActorBlueprintEditor.selectedCount == 0)
|
||||
if (editor.selectedCount == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Select at least one particle to use selection mask.", MessageType.Info);
|
||||
selectionMask = false;
|
||||
@@ -111,16 +111,13 @@ namespace Obi
|
||||
|
||||
public override bool Editable(int index)
|
||||
{
|
||||
return editor.visible[index] && (!selectionMask || ObiActorBlueprintEditor.selectionStatus[index]);
|
||||
return editor.visible[index] && (!selectionMask || editor.selectionStatus[index]);
|
||||
}
|
||||
|
||||
public override void OnSceneGUI(SceneView view)
|
||||
{
|
||||
if (Camera.current != null)
|
||||
{
|
||||
var blueprint = meshBasedEditor.blueprint as ObiMeshBasedActorBlueprint;
|
||||
paintBrush.raycastTransform = blueprint != null ? Matrix4x4.TRS(Vector3.zero, blueprint.rotation, blueprint.scale) : Matrix4x4.identity;
|
||||
|
||||
paintBrush.raycastTarget = meshBasedEditor.sourceMesh;
|
||||
paintBrush.DoBrush(editor.blueprint.positions);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace Obi
|
||||
|
||||
public override string GetHelpString()
|
||||
{
|
||||
if (ObiActorBlueprintEditor.selectedCount > 0)
|
||||
return "" + ObiActorBlueprintEditor.selectedCount + " selected particles.";
|
||||
if (editor.selectedCount > 0)
|
||||
return "" + editor.selectedCount + " selected particles.";
|
||||
else
|
||||
return "No particles selected. Click and drag over particles to select them.";
|
||||
}
|
||||
@@ -65,12 +65,12 @@ namespace Obi
|
||||
{
|
||||
if ((Event.current.modifiers & EventModifiers.Shift) == 0)
|
||||
{
|
||||
for (int p = 0; p < ObiActorBlueprintEditor.selectionStatus.Length; p++)
|
||||
ObiActorBlueprintEditor.selectionStatus[p] = false;
|
||||
for (int p = 0; p < editor.selectionStatus.Length; p++)
|
||||
editor.selectionStatus[p] = false;
|
||||
}
|
||||
|
||||
foreach (int p in group.particleIndices)
|
||||
ObiActorBlueprintEditor.selectionStatus[p] = true;
|
||||
editor.selectionStatus[p] = true;
|
||||
|
||||
UpdateSelection();
|
||||
}
|
||||
@@ -78,9 +78,9 @@ namespace Obi
|
||||
if (GUI.Button(new Rect(rect.x + rect.width * 0.5f, rect.y, rect.width * 0.5f, EditorGUIUtility.singleLineHeight), "Set", EditorStyles.miniButtonRight))
|
||||
{
|
||||
group.particleIndices.Clear();
|
||||
for (int p = 0; p < ObiActorBlueprintEditor.selectionStatus.Length; p++)
|
||||
for (int p = 0; p < editor.selectionStatus.Length; p++)
|
||||
{
|
||||
if (ObiActorBlueprintEditor.selectionStatus[p])
|
||||
if (editor.selectionStatus[p])
|
||||
group.particleIndices.Add(p);
|
||||
}
|
||||
}
|
||||
@@ -95,9 +95,9 @@ namespace Obi
|
||||
|
||||
var group = editor.blueprint.AppendNewParticleGroup("new group");
|
||||
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
{
|
||||
if (ObiActorBlueprintEditor.selectionStatus[i])
|
||||
if (editor.selectionStatus[i])
|
||||
group.particleIndices.Add(i);
|
||||
}
|
||||
|
||||
@@ -116,33 +116,33 @@ namespace Obi
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(new GUIContent(Resources.Load<Texture2D>("InvertButton"), "Invert selection"), GUILayout.MaxHeight(24), GUILayout.MaxWidth(48)))
|
||||
{
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
{
|
||||
if (editor.blueprint.IsParticleActive(i))
|
||||
ObiActorBlueprintEditor.selectionStatus[i] = !ObiActorBlueprintEditor.selectionStatus[i];
|
||||
editor.selectionStatus[i] = !editor.selectionStatus[i];
|
||||
}
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
GUI.enabled = ObiActorBlueprintEditor.selectedCount > 0;
|
||||
GUI.enabled = editor.selectedCount > 0;
|
||||
if (GUILayout.Button(new GUIContent(Resources.Load<Texture2D>("ClearButton"), "Clear selection"), GUILayout.MaxHeight(24), GUILayout.MaxWidth(48)))
|
||||
{
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
ObiActorBlueprintEditor.selectionStatus[i] = false;
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
editor.selectionStatus[i] = false;
|
||||
UpdateSelection();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(Resources.Load<Texture2D>("OptimizeButton"), "Optimize selected"), GUILayout.MaxHeight(24), GUILayout.MaxWidth(48)))
|
||||
{
|
||||
Undo.RecordObject(editor.blueprint, "Optimize particles away");
|
||||
editor.blueprint.RemoveSelectedParticles(ref ObiActorBlueprintEditor.selectionStatus);
|
||||
editor.blueprint.RemoveSelectedParticles(ref editor.selectionStatus);
|
||||
editor.Refresh();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(Resources.Load<Texture2D>("RemoveButton"), "Remove selected"), GUILayout.MaxHeight(24), GUILayout.MaxWidth(48)))
|
||||
{
|
||||
Undo.RecordObject(editor.blueprint, "Remove particles");
|
||||
editor.blueprint.RemoveSelectedParticles(ref ObiActorBlueprintEditor.selectionStatus, false);
|
||||
editor.blueprint.RemoveSelectedParticles(ref editor.selectionStatus, false);
|
||||
editor.Refresh();
|
||||
}
|
||||
GUI.enabled = true;
|
||||
@@ -175,12 +175,12 @@ namespace Obi
|
||||
maxSelectionValue = EditorGUILayout.FloatField("Maximum " + property.name, maxSelectionValue);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
{
|
||||
if (editor.blueprint.IsParticleActive(i))
|
||||
{
|
||||
var value = property.Get(i);
|
||||
ObiActorBlueprintEditor.selectionStatus[i] = value >= minSelectionValue && value <= maxSelectionValue;
|
||||
editor.selectionStatus[i] = value >= minSelectionValue && value <= maxSelectionValue;
|
||||
}
|
||||
}
|
||||
UpdateSelection();
|
||||
@@ -244,9 +244,9 @@ namespace Obi
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(editor.blueprint, "Set particle property");
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
{
|
||||
if (!ObiActorBlueprintEditor.selectionStatus[i]) continue;
|
||||
if (!editor.selectionStatus[i]) continue;
|
||||
editor.currentProperty.SetDefaultToIndex(i);
|
||||
}
|
||||
editor.Refresh();
|
||||
@@ -287,7 +287,7 @@ namespace Obi
|
||||
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
|
||||
|
||||
editor.RenderModeSelector();
|
||||
ObiActorBlueprintEditor.dotRadiusScale = EditorGUILayout.Slider(new GUIContent("Particle dot size"), ObiActorBlueprintEditor.dotRadiusScale, 0, 5);
|
||||
editor.dotRadiusScale = EditorGUILayout.Slider(new GUIContent("Particle dot size"), editor.dotRadiusScale, 0, 5);
|
||||
editor.currentProperty.VisualizationOptions();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
@@ -301,31 +301,31 @@ namespace Obi
|
||||
|
||||
protected void UpdateSelection()
|
||||
{
|
||||
ObiActorBlueprintEditor.selectedCount = 0;
|
||||
editor.selectedCount = 0;
|
||||
mixedPropertyValue = false;
|
||||
|
||||
// Find out how many selected particles we have, and whether they all have the same value for the current property:
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; i++)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; i++)
|
||||
{
|
||||
if (editor.blueprint.IsParticleActive(i) && ObiActorBlueprintEditor.selectionStatus[i])
|
||||
if (editor.blueprint.IsParticleActive(i) && editor.selectionStatus[i])
|
||||
{
|
||||
ObiActorBlueprintEditor.selectedCount++;
|
||||
editor.selectedCount++;
|
||||
|
||||
if (ObiActorBlueprintEditor.activeParticle >= 0)
|
||||
if (editor.activeParticle >= 0)
|
||||
{
|
||||
if (!editor.currentProperty.Equals(ObiActorBlueprintEditor.activeParticle, i))
|
||||
if (!editor.currentProperty.Equals(editor.activeParticle, i))
|
||||
mixedPropertyValue = true;
|
||||
}
|
||||
else
|
||||
ObiActorBlueprintEditor.activeParticle = i;
|
||||
editor.activeParticle = i;
|
||||
}
|
||||
else if (ObiActorBlueprintEditor.activeParticle == i)
|
||||
ObiActorBlueprintEditor.activeParticle = -1;
|
||||
else if (editor.activeParticle == i)
|
||||
editor.activeParticle = -1;
|
||||
}
|
||||
|
||||
// Set initial property value:
|
||||
if (!mixedPropertyValue && ObiActorBlueprintEditor.activeParticle >= 0)
|
||||
editor.currentProperty.GetDefaultFromIndex(ObiActorBlueprintEditor.activeParticle);
|
||||
if (!mixedPropertyValue && editor.activeParticle >= 0)
|
||||
editor.currentProperty.GetDefaultFromIndex(editor.activeParticle);
|
||||
|
||||
editor.Repaint();
|
||||
SceneView.RepaintAll();
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Obi
|
||||
|
||||
private void FloatFromTexture(int i, Color color)
|
||||
{
|
||||
if (!selectionMask || ObiActorBlueprintEditor.selectionStatus[i])
|
||||
if (!selectionMask || editor.selectionStatus[i])
|
||||
{
|
||||
float value = minPropertyValue + color[(int)textureChannel] * (maxPropertyValue - minPropertyValue);
|
||||
floatProperty.Set(i, value);
|
||||
@@ -61,7 +61,7 @@ namespace Obi
|
||||
|
||||
private void ColorFromTexture(int i, Color color)
|
||||
{
|
||||
if (!selectionMask || ObiActorBlueprintEditor.selectionStatus[i])
|
||||
if (!selectionMask || editor.selectionStatus[i])
|
||||
colorProperty.Set(i, color);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,20 +57,20 @@ namespace Obi
|
||||
if (GUILayout.Button("Generate tethers",GUILayout.MinHeight(32)))
|
||||
{
|
||||
// Select all particles in the tethered groups:
|
||||
for (int i = 0; i < ObiActorBlueprintEditor.selectionStatus.Length; ++i)
|
||||
for (int i = 0; i < editor.selectionStatus.Length; ++i)
|
||||
{
|
||||
ObiActorBlueprintEditor.selectionStatus[i] = false;
|
||||
editor.selectionStatus[i] = false;
|
||||
for (int j = 0; j < tetheredGroups.Length; ++j)
|
||||
{
|
||||
if (tetheredGroups[j] && editor.blueprint.groups[j].ContainsParticle(i))
|
||||
{
|
||||
ObiActorBlueprintEditor.selectionStatus[i] = true;
|
||||
editor.selectionStatus[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
editor.blueprint.GenerateTethers(ObiActorBlueprintEditor.selectionStatus);
|
||||
editor.blueprint.GenerateTethers(editor.selectionStatus);
|
||||
editor.Refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Obi
|
||||
protected override float WeightFromDistance(float distance)
|
||||
{
|
||||
// anything outside the brush should have zero weight:
|
||||
if (distance * EditorGUIUtility.pixelsPerPoint > radius)
|
||||
if (distance > radius)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -14,27 +14,29 @@ namespace Obi
|
||||
[CustomEditor(typeof(ObiActorBlueprint), true)]
|
||||
public class ObiActorBlueprintEditor : Editor, IObiSelectableParticleProvider
|
||||
{
|
||||
protected IEnumerator routine;
|
||||
|
||||
public List<ObiBlueprintEditorTool> tools = new List<ObiBlueprintEditorTool>();
|
||||
public int currentToolIndex = 0;
|
||||
|
||||
public List<ObiBlueprintPropertyBase> properties = new List<ObiBlueprintPropertyBase>();
|
||||
protected List<ObiBlueprintPropertyBase> properties = new List<ObiBlueprintPropertyBase>();
|
||||
public int currentPropertyIndex = 0;
|
||||
|
||||
public List<ObiBlueprintRenderMode> renderModes = new List<ObiBlueprintRenderMode>();
|
||||
protected List<ObiBlueprintRenderMode> renderModes = new List<ObiBlueprintRenderMode>();
|
||||
public int renderModeFlags = 0;
|
||||
BooleanPreference showRenderModes;
|
||||
|
||||
public bool autoGenerate = false;
|
||||
public bool editMode = false;
|
||||
public bool isEditing = false;
|
||||
protected List<SceneStateCache> m_SceneStates;
|
||||
protected SceneSetup[] oldSetup;
|
||||
protected UnityEngine.Object oldSelection;
|
||||
|
||||
//Additional status info for all particles:
|
||||
public static float dotRadiusScale = 1;
|
||||
public static int selectedCount = 0;
|
||||
public static int activeParticle = -1;
|
||||
public static bool[] selectionStatus = new bool[0];
|
||||
|
||||
public float dotRadiusScale = 1;
|
||||
public int selectedCount = 0;
|
||||
public int activeParticle = -1;
|
||||
public bool[] selectionStatus = new bool[0];
|
||||
public bool[] visible = new bool[0];
|
||||
public Color[] tint = new Color[0];
|
||||
protected float[] sqrDistanceToCamera = new float[0];
|
||||
@@ -76,10 +78,6 @@ namespace Obi
|
||||
|
||||
public virtual void OnEnable()
|
||||
{
|
||||
properties.Clear();
|
||||
renderModes.Clear();
|
||||
tools.Clear();
|
||||
|
||||
properties.Add(new ObiBlueprintMass(this));
|
||||
properties.Add(new ObiBlueprintRadius(this));
|
||||
properties.Add(new ObiBlueprintFilterCategory(this));
|
||||
@@ -90,12 +88,11 @@ namespace Obi
|
||||
|
||||
#if (UNITY_2019_1_OR_NEWER)
|
||||
renderCallback = new System.Action<ScriptableRenderContext, Camera>((cntxt, cam) => { DrawWithCamera(cam); });
|
||||
RenderPipelineManager.beginCameraRendering -= renderCallback;
|
||||
RenderPipelineManager.beginCameraRendering += renderCallback;
|
||||
#endif
|
||||
Camera.onPreCull -= DrawWithCamera;
|
||||
Camera.onPreCull += DrawWithCamera;
|
||||
SceneView.duringSceneGui += OnSceneGUI;
|
||||
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
public virtual void OnDisable()
|
||||
@@ -106,8 +103,8 @@ namespace Obi
|
||||
RenderPipelineManager.beginCameraRendering -= renderCallback;
|
||||
#endif
|
||||
Camera.onPreCull -= DrawWithCamera;
|
||||
SceneView.duringSceneGui -= OnSceneGUI;
|
||||
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
||||
|
||||
ObiParticleEditorDrawing.DestroyParticlesMesh();
|
||||
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
@@ -119,77 +116,51 @@ namespace Obi
|
||||
{
|
||||
renderMode.OnDestroy();
|
||||
}
|
||||
|
||||
properties.Clear();
|
||||
renderModes.Clear();
|
||||
}
|
||||
|
||||
void OnPlayModeStateChanged(PlayModeStateChange playmodeState)
|
||||
protected void Generate()
|
||||
{
|
||||
if (playmodeState == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
if (StageUtility.GetCurrentStage() is ObiActorBlueprintEditorStage)
|
||||
StageUtility.GoToMainStage();
|
||||
}
|
||||
}
|
||||
|
||||
protected bool Generate()
|
||||
{
|
||||
if (!blueprint.edited)
|
||||
if (blueprint.empty)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
CoroutineJob job = new CoroutineJob();
|
||||
IEnumerator routine = job.Start(blueprint.Generate());
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating blueprint...", routine);
|
||||
routine = job.Start(blueprint.Generate());
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating blueprint...", ref routine);
|
||||
Refresh();
|
||||
EditorGUIUtility.ExitGUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Blueprint generation", "This blueprint contains manually edited data. If you regenerate the blueprint, these changes will be lost. Are you sure you want to proceed?", "Ok", "Cancel"))
|
||||
if (EditorUtility.DisplayDialog("Blueprint generation", "This blueprint already contains data. Are you sure you want to re-generate this blueprint from scratch?", "Ok", "Cancel"))
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
CoroutineJob job = new CoroutineJob();
|
||||
IEnumerator routine = job.Start(blueprint.Generate());
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating blueprint...", routine);
|
||||
routine = job.Start(blueprint.Generate());
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating blueprint...", ref routine);
|
||||
Refresh();
|
||||
EditorGUIUtility.ExitGUI();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool ValidateBlueprint() { return true; }
|
||||
|
||||
private void DrawGenerationControls()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
float originalLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 72;
|
||||
autoGenerate = EditorGUILayout.ToggleLeft("Auto Generate", autoGenerate, GUILayout.ExpandWidth(false));
|
||||
EditorGUIUtility.labelWidth = originalLabelWidth;
|
||||
|
||||
GUI.enabled = !autoGenerate;
|
||||
if (GUILayout.Button("Generate", GUI.skin.FindStyle("LargeButton"), GUILayout.Height(32)))
|
||||
Generate();
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
DrawBlueprintProperties();
|
||||
bool blueprintPropertiesChanged = EditorGUI.EndChangeCheck();
|
||||
bool blueprintValid = ValidateBlueprint();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
GUI.enabled = blueprintValid;
|
||||
DrawGenerationControls();
|
||||
GUI.enabled = ValidateBlueprint();
|
||||
if (GUILayout.Button("Generate", GUI.skin.FindStyle("LargeButton"), GUILayout.Height(32)))
|
||||
Generate();
|
||||
|
||||
GUI.enabled = (blueprint != null && !blueprint.empty && !Application.isPlaying);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
@@ -209,10 +180,7 @@ namespace Obi
|
||||
|
||||
if (GUI.changed)
|
||||
{
|
||||
serializedObject.ApplyModifiedPropertiesWithoutUndo();
|
||||
|
||||
if (autoGenerate && blueprintValid && blueprintPropertiesChanged)
|
||||
blueprint.GenerateImmediate();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
// There might be blueprint editing operations that have no undo entry, so do this to
|
||||
// ensure changes are serialized to disk by Unity.
|
||||
@@ -238,17 +206,51 @@ namespace Obi
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
protected class SceneStateCache
|
||||
{
|
||||
public SceneView view;
|
||||
public SceneView.SceneViewState state;
|
||||
}
|
||||
|
||||
void EnterBlueprintEditMode()
|
||||
{
|
||||
if (!isEditing)
|
||||
{
|
||||
ActiveEditorTracker.sharedTracker.isLocked = true;
|
||||
#if (UNITY_2019_1_OR_NEWER)
|
||||
SceneView.duringSceneGui -= this.OnSceneGUI;
|
||||
SceneView.duringSceneGui += this.OnSceneGUI;
|
||||
#else
|
||||
SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
|
||||
SceneView.onSceneGUIDelegate += this.OnSceneGUI;
|
||||
#endif
|
||||
|
||||
string assetPath = AssetDatabase.GetAssetPath(blueprint);
|
||||
ObiActorBlueprintEditorStage stage = ObiActorBlueprintEditorStage.CreateStage(assetPath, this);
|
||||
StageUtility.GoToStage(stage, true);
|
||||
oldSelection = Selection.activeObject;
|
||||
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
||||
{
|
||||
ActiveEditorTracker.sharedTracker.isLocked = true;
|
||||
|
||||
isEditing = true;
|
||||
oldSetup = EditorSceneManager.GetSceneManagerSetup();
|
||||
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
|
||||
|
||||
// Set properties for all scene views:
|
||||
m_SceneStates = new List<SceneStateCache>();
|
||||
foreach (SceneView s in SceneView.sceneViews)
|
||||
{
|
||||
m_SceneStates.Add(new SceneStateCache { state = new SceneView.SceneViewState(s.sceneViewState), view = s });
|
||||
s.sceneViewState.showFlares = false;
|
||||
s.sceneViewState.alwaysRefresh = false;
|
||||
s.sceneViewState.showFog = false;
|
||||
s.sceneViewState.showSkybox = false;
|
||||
s.sceneViewState.showImageEffects = false;
|
||||
s.sceneViewState.showParticleSystems = false;
|
||||
s.Frame(blueprint.bounds);
|
||||
}
|
||||
|
||||
isEditing = true;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,16 +258,50 @@ namespace Obi
|
||||
{
|
||||
if (isEditing)
|
||||
{
|
||||
isEditing = false;
|
||||
AssetDatabase.SaveAssets();
|
||||
StageUtility.GoToMainStage();
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanupEditor()
|
||||
{
|
||||
ActiveEditorTracker.sharedTracker.isLocked = false;
|
||||
ObiParticleEditorDrawing.DestroyParticlesMesh();
|
||||
isEditing = false;
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
// Reset all scene views:
|
||||
foreach (var state in m_SceneStates)
|
||||
{
|
||||
if (state.view == null)
|
||||
continue;
|
||||
|
||||
state.view.sceneViewState.showFog = state.state.showFog;
|
||||
state.view.sceneViewState.showFlares = state.state.showFlares;
|
||||
state.view.sceneViewState.alwaysRefresh = state.state.alwaysRefresh;
|
||||
state.view.sceneViewState.showSkybox = state.state.showSkybox;
|
||||
state.view.sceneViewState.showImageEffects = state.state.showImageEffects;
|
||||
state.view.sceneViewState.showParticleSystems = state.state.showParticleSystems;
|
||||
}
|
||||
|
||||
ActiveEditorTracker.sharedTracker.isLocked = false;
|
||||
|
||||
if (SceneManager.GetActiveScene().path.Length <= 0)
|
||||
{
|
||||
if (oldSetup != null && oldSetup.Length > 0)
|
||||
{
|
||||
EditorSceneManager.RestoreSceneManagerSetup(oldSetup);
|
||||
oldSetup = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||
}
|
||||
}
|
||||
|
||||
Selection.activeObject = oldSelection;
|
||||
|
||||
#if (UNITY_2019_1_OR_NEWER)
|
||||
SceneView.duringSceneGui -= this.OnSceneGUI;
|
||||
#else
|
||||
SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
|
||||
#endif
|
||||
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnSceneGUI(SceneView sceneView)
|
||||
@@ -282,7 +318,7 @@ namespace Obi
|
||||
{
|
||||
|
||||
// Update camera facing status and world space positions array:
|
||||
UpdateParticleVisibility(sceneView.camera);
|
||||
UpdateParticleVisibility();
|
||||
|
||||
// Generate sorted indices for back-to-front rendering:
|
||||
for (int i = 0; i < sortedIndices.Length; i++)
|
||||
@@ -303,7 +339,7 @@ namespace Obi
|
||||
UpdateTintColor();
|
||||
|
||||
// Draw particle handles:
|
||||
ObiParticleEditorDrawing.DrawParticles(sceneView.camera, blueprint, visible, tint, sortedIndices, dotRadiusScale);
|
||||
ObiParticleEditorDrawing.DrawParticles(sceneView.camera, blueprint, activeParticle, visible, tint, sortedIndices, dotRadiusScale);
|
||||
|
||||
}
|
||||
|
||||
@@ -334,7 +370,6 @@ namespace Obi
|
||||
{
|
||||
if (blueprint.positions != null)
|
||||
{
|
||||
activeParticle = Mathf.Min(activeParticle, blueprint.positions.Length - 1);
|
||||
Array.Resize(ref selectionStatus, blueprint.positions.Length);
|
||||
Array.Resize(ref visible, blueprint.positions.Length);
|
||||
Array.Resize(ref tint, blueprint.positions.Length);
|
||||
@@ -378,9 +413,7 @@ namespace Obi
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
// currentProperty might be null after reloading editor during
|
||||
// asset saving.
|
||||
currentProperty?.RecalculateMinMax();
|
||||
currentProperty.RecalculateMinMax();
|
||||
|
||||
// refresh render modes:
|
||||
for (int i = 0; i < renderModes.Count; ++i)
|
||||
@@ -392,7 +425,7 @@ namespace Obi
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
|
||||
public virtual void UpdateParticleVisibility(Camera cam)
|
||||
public virtual void UpdateParticleVisibility()
|
||||
{
|
||||
|
||||
for (int i = 0; i < blueprint.positions.Length; i++)
|
||||
@@ -403,7 +436,7 @@ namespace Obi
|
||||
|
||||
if (Camera.current != null)
|
||||
{
|
||||
Vector3 camToParticle = cam.transform.position - blueprint.positions[i];
|
||||
Vector3 camToParticle = Camera.current.transform.position - blueprint.positions[i];
|
||||
sqrDistanceToCamera[i] = camToParticle.sqrMagnitude;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
[Serializable]
|
||||
class ObiActorBlueprintEditorStage : PreviewSceneStage
|
||||
{
|
||||
ObiActorBlueprintEditor m_BlueprintEditor;
|
||||
|
||||
string m_AssetPath;
|
||||
public override string assetPath { get { return m_AssetPath; } }
|
||||
|
||||
internal static ObiActorBlueprintEditorStage CreateStage(string assetPath, ObiActorBlueprintEditor avatarEditor)
|
||||
{
|
||||
ObiActorBlueprintEditorStage stage = CreateInstance<ObiActorBlueprintEditorStage>();
|
||||
stage.Init(assetPath, avatarEditor);
|
||||
return stage;
|
||||
}
|
||||
|
||||
private void Init(string modelAssetPath, ObiActorBlueprintEditor avatarEditor)
|
||||
{
|
||||
m_AssetPath = modelAssetPath;
|
||||
m_BlueprintEditor = avatarEditor;
|
||||
}
|
||||
|
||||
protected override bool OnOpenStage()
|
||||
{
|
||||
base.OnOpenStage();
|
||||
|
||||
if (!File.Exists(assetPath))
|
||||
{
|
||||
Debug.LogError("ActivateStage called on BlueprintStage with an invalid path: Blueprint file not found " + assetPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnCloseStage()
|
||||
{
|
||||
m_BlueprintEditor.CleanupEditor();
|
||||
|
||||
base.OnCloseStage();
|
||||
}
|
||||
|
||||
protected override void OnFirstTimeOpenStageInSceneView(SceneView sceneView)
|
||||
{
|
||||
// Frame in scene view
|
||||
sceneView.Frame(m_BlueprintEditor.blueprint.bounds);
|
||||
|
||||
// Setup Scene view state
|
||||
sceneView.sceneViewState.showFlares = false;
|
||||
sceneView.sceneViewState.alwaysRefresh = false;
|
||||
sceneView.sceneViewState.showFog = false;
|
||||
sceneView.sceneViewState.showSkybox = false;
|
||||
sceneView.sceneViewState.showImageEffects = false;
|
||||
sceneView.sceneViewState.showParticleSystems = false;
|
||||
sceneView.sceneLighting = true;
|
||||
}
|
||||
|
||||
protected override GUIContent CreateHeaderContent()
|
||||
{
|
||||
return new GUIContent(
|
||||
"Blueprint Editor",
|
||||
Resources.Load<Texture2D>("Icons/ObiActorBlueprint Icon"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ namespace Obi
|
||||
}
|
||||
|
||||
protected Mesh visualizationMesh;
|
||||
protected Mesh visualizationWireMesh;
|
||||
public ParticleCulling particleCulling = ParticleCulling.Back;
|
||||
|
||||
protected Material gradientMaterial;
|
||||
@@ -76,50 +75,46 @@ namespace Obi
|
||||
|
||||
public abstract int VertexToParticle(int vertexIndex);
|
||||
|
||||
public override void UpdateParticleVisibility(Camera cam)
|
||||
public override void UpdateParticleVisibility()
|
||||
{
|
||||
if (cam != null)
|
||||
if (sourceMesh != null && Camera.current != null)
|
||||
{
|
||||
for (int i = 0; i < blueprint.positions.Length; i++)
|
||||
Vector3[] meshNormals = sourceMesh.normals;
|
||||
for (int i = 0; i < sourceMesh.vertexCount; i++)
|
||||
{
|
||||
if (blueprint.IsParticleActive(i))
|
||||
{
|
||||
Vector3 camToParticle = cam.transform.position - blueprint.positions[i];
|
||||
sqrDistanceToCamera[i] = camToParticle.sqrMagnitude;
|
||||
int particle = VertexToParticle(i);
|
||||
|
||||
Vector3 normal;
|
||||
if (particle >= 0 && particle < blueprint.positions.Length)
|
||||
{
|
||||
Vector3 camToParticle = Camera.current.transform.position - blueprint.positions[particle];
|
||||
|
||||
sqrDistanceToCamera[particle] = camToParticle.sqrMagnitude;
|
||||
|
||||
switch (particleCulling)
|
||||
{
|
||||
case ParticleCulling.Off:
|
||||
visible[i] = true;
|
||||
visible[particle] = true;
|
||||
break;
|
||||
case ParticleCulling.Back:
|
||||
normal = blueprint.restOrientations[i] * Vector3.forward;
|
||||
visible[i] = Vector3.Dot(normal, camToParticle) > 0;
|
||||
visible[particle] = Vector3.Dot(meshNormals[i], camToParticle) > 0;
|
||||
break;
|
||||
case ParticleCulling.Front:
|
||||
normal = blueprint.restOrientations[i] * Vector3.forward;
|
||||
visible[i] = Vector3.Dot(normal, camToParticle) <= 0;
|
||||
visible[particle] = Vector3.Dot(meshNormals[i], camToParticle) <= 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((renderModeFlags & 1) != 0)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DrawGradientMesh(float[] vertexWeights = null, float[] wireframeWeights = null)
|
||||
{
|
||||
// Due to this Unity bug: https://issuetracker.unity3d.com/issues/drawmeshnow-is-not-drawing-mesh-immediately-dx12
|
||||
// we need to create two meshes insteaf of one :(
|
||||
if (sourceMesh == null)
|
||||
return;
|
||||
|
||||
visualizationMesh = GameObject.Instantiate(sourceMesh);
|
||||
visualizationWireMesh = GameObject.Instantiate(sourceMesh);
|
||||
|
||||
if (gradientMaterial.SetPass(0))
|
||||
{
|
||||
@@ -162,16 +157,15 @@ namespace Obi
|
||||
colors[i] = Color.gray;
|
||||
}
|
||||
|
||||
visualizationWireMesh.colors = colors;
|
||||
visualizationMesh.colors = colors;
|
||||
GL.wireframe = true;
|
||||
Graphics.DrawMeshNow(visualizationWireMesh, matrix);
|
||||
Graphics.DrawMeshNow(visualizationMesh, matrix);
|
||||
GL.wireframe = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GameObject.DestroyImmediate(visualizationMesh);
|
||||
GameObject.DestroyImmediate(visualizationWireMesh);
|
||||
}
|
||||
|
||||
|
||||
@@ -229,8 +223,7 @@ namespace Obi
|
||||
RenderTexture.active = tempRT;
|
||||
|
||||
GL.PushMatrix();
|
||||
|
||||
var proj = Matrix4x4.Ortho(0, 1, 0, 1, -1, 1);
|
||||
GL.LoadProjectionMatrix(Matrix4x4.Ortho(0, 1, 0, 1, -1, 1));
|
||||
|
||||
Color[] colors = new Color[sourceMesh.vertexCount];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Obi
|
||||
GameObject.DestroyImmediate(particlesMesh);
|
||||
}
|
||||
|
||||
public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, bool[] visible, Color[] baseColor, int[] sortedIndices, float radiusScale = 1)
|
||||
public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, int activeParticle, bool[] visible, Color[] baseColor, int[] sortedIndices, float radiusScale = 1)
|
||||
{
|
||||
CreateParticlesMesh();
|
||||
CreateParticleMaterials();
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Obi
|
||||
public override void Set(int index, Color value)
|
||||
{
|
||||
editor.blueprint.colors[index] = value;
|
||||
editor.blueprint.edited = true;
|
||||
}
|
||||
public override bool Masked(int index)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Obi
|
||||
public override void Set(int index, int value)
|
||||
{
|
||||
editor.blueprint.filters[index] = ObiUtils.MakeFilter(ObiUtils.GetMaskFromFilter(editor.blueprint.filters[index]), value);
|
||||
editor.blueprint.edited = true;
|
||||
}
|
||||
public override bool Masked(int index)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
public override void Set(int index, int value)
|
||||
{
|
||||
editor.blueprint.filters[index] = ObiUtils.MakeFilter(value,ObiUtils.GetCategoryFromFilter(editor.blueprint.filters[index]));
|
||||
editor.blueprint.edited = true;
|
||||
}
|
||||
public override bool Masked(int index)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace Obi
|
||||
public override void Set(int index, float value)
|
||||
{
|
||||
editor.blueprint.invMasses[index] = ObiUtils.MassToInvMass(value);
|
||||
editor.blueprint.edited = true;
|
||||
}
|
||||
public override bool Masked(int index)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace Obi
|
||||
value = Mathf.Max(0.0000001f, value);
|
||||
float ratio = value / Get(index);
|
||||
editor.blueprint.principalRadii[index] = editor.blueprint.principalRadii[index] * ratio;
|
||||
editor.blueprint.edited = true;
|
||||
}
|
||||
public override bool Masked(int index)
|
||||
{
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace Obi
|
||||
{
|
||||
ObiPaintBrushEditorTool paintTool = (ObiPaintBrushEditorTool)meshBasedEditor.currentTool;
|
||||
|
||||
float[] weights = new float[ObiActorBlueprintEditor.selectionStatus.Length];
|
||||
float[] weights = new float[editor.selectionStatus.Length];
|
||||
for (int i = 0; i < weights.Length; i++)
|
||||
{
|
||||
if (paintTool.selectionMask && !ObiActorBlueprintEditor.selectionStatus[i])
|
||||
if (paintTool.selectionMask && !editor.selectionStatus[i])
|
||||
weights[i] = 0;
|
||||
else
|
||||
weights[i] = 1;
|
||||
|
||||
@@ -13,13 +13,11 @@ namespace Obi
|
||||
private Shader shader;
|
||||
private Material material;
|
||||
private ParticleImpostorRendering impostorDrawer;
|
||||
private MaterialPropertyBlock mpb;
|
||||
|
||||
public ObiBlueprintRenderModeParticles(ObiActorBlueprintEditor editor) :base(editor)
|
||||
{
|
||||
impostorDrawer = new ParticleImpostorRendering();
|
||||
impostorDrawer.UpdateMeshes(editor.blueprint);
|
||||
mpb = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
void CreateMaterialIfNeeded()
|
||||
@@ -45,10 +43,8 @@ namespace Obi
|
||||
public override void DrawWithCamera(Camera camera)
|
||||
{
|
||||
CreateMaterialIfNeeded();
|
||||
mpb.SetFloat("_RadiusScale", 1);
|
||||
mpb.SetColor("_ParticleColor", Color.white);
|
||||
foreach (Mesh mesh in impostorDrawer.Meshes)
|
||||
Graphics.DrawMesh(mesh, Matrix4x4.identity, material, 0, camera, 0, mpb);
|
||||
Graphics.DrawMesh(mesh, Matrix4x4.identity, material, 0, camera);
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ObiColliderBase), true), CanEditMultipleObjects]
|
||||
public class ObiColliderEditor : Editor
|
||||
{
|
||||
namespace Obi{
|
||||
|
||||
[CustomEditor(typeof(ObiColliderBase), true), CanEditMultipleObjects]
|
||||
public class ObiColliderEditor : Editor
|
||||
{
|
||||
|
||||
ObiColliderBase collider;
|
||||
SerializedProperty collisionFilter;
|
||||
@@ -17,42 +16,11 @@ namespace Obi
|
||||
collisionFilter = serializedObject.FindProperty("filter");
|
||||
}
|
||||
|
||||
protected void NonReadableMeshWarning(Mesh mesh)
|
||||
{
|
||||
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
Texture2D icon = EditorGUIUtility.Load("icons/console.erroricon.png") as Texture2D;
|
||||
EditorGUILayout.LabelField(new GUIContent("The input mesh is not readable. Read/Write must be enabled in the mesh import settings.", icon), EditorStyles.wordWrappedMiniLabel);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("Fix now", GUILayout.MaxWidth(100), GUILayout.MinHeight(32)))
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(mesh);
|
||||
ModelImporter modelImporter = AssetImporter.GetAtPath(assetPath) as ModelImporter;
|
||||
if (modelImporter != null)
|
||||
{
|
||||
modelImporter.isReadable = true;
|
||||
}
|
||||
modelImporter.SaveAndReimport();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
foreach (ObiColliderBase t in targets)
|
||||
{
|
||||
ObiMeshShapeTracker meshTracker = t.Tracker as ObiMeshShapeTracker;
|
||||
if (meshTracker != null)
|
||||
{
|
||||
if (meshTracker.targetMesh != null && !meshTracker.targetMesh.isReadable)
|
||||
NonReadableMeshWarning(meshTracker.targetMesh);
|
||||
}
|
||||
}
|
||||
|
||||
var rect = EditorGUILayout.GetControlRect();
|
||||
var label = EditorGUI.BeginProperty(rect, new GUIContent("Collision category"), collisionFilter);
|
||||
@@ -88,13 +56,8 @@ namespace Obi
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
|
||||
DrawPropertiesExcluding(serializedObject, "m_Script", "CollisionMaterial", "filter", "Thickness", "Inverted");
|
||||
|
||||
foreach (ObiColliderBase t in targets)
|
||||
{
|
||||
if (!t.gameObject.isStatic)
|
||||
t.ForceUpdate();
|
||||
}
|
||||
DrawPropertiesExcluding(serializedObject, "m_Script", "CollisionMaterial", "filter", "Thickness");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed)
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Obi{
|
||||
EditorUtility.SetDirty(target);
|
||||
CoroutineJob job = new CoroutineJob();
|
||||
routine = job.Start( distanceField.Generate());
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating distance field", routine);
|
||||
EditorCoroutine.ShowCoroutineProgressBar("Generating distance field",ref routine);
|
||||
UpdatePreview();
|
||||
EditorGUIUtility.ExitGUI();
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
|
||||
/**
|
||||
* Custom inspector for ObiForceZone component.
|
||||
*/
|
||||
|
||||
[CustomEditor(typeof(ObiForceZone)), CanEditMultipleObjects]
|
||||
public class ObiForceZoneEditor : Editor
|
||||
{
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
|
||||
DrawPropertiesExcluding(serializedObject, "m_Script");
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed)
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 724435a7a84154b27bb0c8ea49b611df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -24,20 +24,10 @@ namespace Obi
|
||||
GUI.Box(position,"",ObiEditorUtils.GetToggleablePropertyGroupStyle());
|
||||
GUI.enabled = true;
|
||||
|
||||
// Draw main constraint toggle:
|
||||
EditorGUI.BeginProperty(position, label, enabled);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var newEnabled = EditorGUI.ToggleLeft(contRect, label.text, enabled.boolValue, EditorStyles.boldLabel);
|
||||
// Only assign the value back if it was actually changed by the user.
|
||||
// Otherwise a single value will be assigned to all objects when multi-object editing,
|
||||
// even when the user didn't touch the control.
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
enabled.boolValue = newEnabled;
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
// Draw main constraint toggle:
|
||||
enabled.boolValue = EditorGUI.ToggleLeft(contRect, label.text, enabled.boolValue, EditorStyles.boldLabel);
|
||||
|
||||
if (enabled.boolValue){
|
||||
if (enabled.boolValue){
|
||||
|
||||
Rect evalRect = new Rect(position.x+padding, position.y+propHeight+padding, position.width-padding*2, propHeight);
|
||||
Rect iterRect = new Rect(position.x+padding, position.y+propHeight*2+padding, position.width-padding*2, propHeight);
|
||||
|
||||
83
Assets/Obi/Editor/Common/ObiEditorSettings.cs
Normal file
83
Assets/Obi/Editor/Common/ObiEditorSettings.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
class ObiEditorSettings : ScriptableObject
|
||||
{
|
||||
public const string m_ObiEditorSettingsPath = "Assets/ObiEditorSettings.asset";
|
||||
|
||||
[SerializeField] private Color m_ParticleBrush;
|
||||
[SerializeField] private Color m_BrushWireframe;
|
||||
[SerializeField] private Color m_Particle;
|
||||
[SerializeField] private Color m_SelectedParticle;
|
||||
[SerializeField] private Color m_ActiveParticle;
|
||||
[SerializeField] private Gradient m_PropertyGradient;
|
||||
|
||||
public Color brushColor
|
||||
{
|
||||
get { return m_ParticleBrush; }
|
||||
}
|
||||
public Color brushWireframeColor
|
||||
{
|
||||
get { return m_BrushWireframe; }
|
||||
}
|
||||
public Color particleColor
|
||||
{
|
||||
get { return m_Particle; }
|
||||
}
|
||||
public Color selectedParticleColor
|
||||
{
|
||||
get { return m_SelectedParticle; }
|
||||
}
|
||||
public Color activeParticleColor
|
||||
{
|
||||
get { return m_ActiveParticle; }
|
||||
}
|
||||
public Gradient propertyGradient
|
||||
{
|
||||
get { return m_PropertyGradient; }
|
||||
}
|
||||
|
||||
internal static ObiEditorSettings GetOrCreateSettings()
|
||||
{
|
||||
var settings = AssetDatabase.LoadAssetAtPath<ObiEditorSettings>(m_ObiEditorSettingsPath);
|
||||
if (settings == null)
|
||||
{
|
||||
settings = ScriptableObject.CreateInstance<ObiEditorSettings>();
|
||||
settings.m_ParticleBrush = new Color32(243, 77, 43, 255);
|
||||
settings.m_BrushWireframe = new Color32(0, 0, 0, 128);
|
||||
settings.m_Particle = new Color32(240, 240, 240, 255);
|
||||
settings.m_SelectedParticle = new Color32(243, 77, 43, 255);
|
||||
settings.m_ActiveParticle = new Color32(243, 243, 43, 255);
|
||||
settings.m_PropertyGradient = new Gradient();
|
||||
|
||||
// Populate the color keys at the relative time 0 and 1 (0 and 100%)
|
||||
var colorKey = new GradientColorKey[2];
|
||||
colorKey[0].color = Color.grey * 0.7f;
|
||||
colorKey[0].time = 0.0f;
|
||||
colorKey[1].color = Color.white;
|
||||
colorKey[1].time = 1.0f;
|
||||
|
||||
// Populate the alpha keys at relative time 0 and 1 (0 and 100%)
|
||||
var alphaKey = new GradientAlphaKey[2];
|
||||
alphaKey[0].alpha = 1.0f;
|
||||
alphaKey[0].time = 0.0f;
|
||||
alphaKey[1].alpha = 1.0f;
|
||||
alphaKey[1].time = 1.0f;
|
||||
|
||||
settings.m_PropertyGradient.SetKeys(colorKey, alphaKey);
|
||||
|
||||
AssetDatabase.CreateAsset(settings, m_ObiEditorSettingsPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
internal static SerializedObject GetSerializedSettings()
|
||||
{
|
||||
return new SerializedObject(GetOrCreateSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9656e2c54d9e4c478c74ca6d97428f8
|
||||
guid: 7971633b9741349f3add282a07b0d69b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
36
Assets/Obi/Editor/Common/ObiOniInitialize.cs
Normal file
36
Assets/Obi/Editor/Common/ObiOniInitialize.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class ObiOniInitialize
|
||||
{
|
||||
private static BuildTargetGroup[] supportedBuildTargetGroups =
|
||||
{
|
||||
BuildTargetGroup.Standalone,
|
||||
BuildTargetGroup.Android,
|
||||
BuildTargetGroup.iOS
|
||||
};
|
||||
|
||||
static ObiOniInitialize()
|
||||
{
|
||||
|
||||
foreach(var group in supportedBuildTargetGroups)
|
||||
{
|
||||
var defines = GetDefinesList(group);
|
||||
if (!defines.Contains("OBI_ONI_SUPPORTED"))
|
||||
{
|
||||
defines.Add("OBI_ONI_SUPPORTED");
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, string.Join(";", defines.ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> GetDefinesList(BuildTargetGroup group)
|
||||
{
|
||||
return new List<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c8d9d8042d49436c89c515b001088ac
|
||||
guid: e97d151316d5f4d16ac5ae6e68acccb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -15,9 +15,7 @@ namespace Obi
|
||||
public static GUIContent brushWireframe = new GUIContent("Brush wireframe");
|
||||
public static GUIContent particle = new GUIContent("Particle");
|
||||
public static GUIContent selectedParticle = new GUIContent("Selected particle");
|
||||
public static GUIContent activeParticle = new GUIContent("Active particle");
|
||||
public static GUIContent propertyGradient = new GUIContent("Property gradient");
|
||||
public static GUIContent particlePicking = new GUIContent("Particle GO picking");
|
||||
}
|
||||
|
||||
const string m_ObiEditorSettingsPath = "Assets/ObiEditorSettings.asset";
|
||||
@@ -54,11 +52,7 @@ namespace Obi
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_BrushWireframe"),Styles.brushWireframe);
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_Particle"),Styles.particle);
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_SelectedParticle"),Styles.selectedParticle);
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_ActiveParticle"), Styles.activeParticle);
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_PropertyGradient"), Styles.propertyGradient);
|
||||
|
||||
EditorGUILayout.LabelField("Scene view", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(m_ObiSettings.FindProperty("m_ParticlePicking"), Styles.particlePicking);
|
||||
}
|
||||
|
||||
// Register the SettingsProvider
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditorInternal;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -41,34 +40,13 @@ namespace Obi
|
||||
ObiSolver solver;
|
||||
|
||||
SerializedProperty backend;
|
||||
SerializedProperty substeps;
|
||||
SerializedProperty maxStepsPerFrame;
|
||||
SerializedProperty synchronization;
|
||||
SerializedProperty simulateWhenInvisible;
|
||||
SerializedProperty parameters;
|
||||
SerializedProperty gravity;
|
||||
SerializedProperty gravitySpace;
|
||||
SerializedProperty ambientWind;
|
||||
SerializedProperty windSpace;
|
||||
SerializedProperty useLimits;
|
||||
SerializedProperty boundaryLimits;
|
||||
SerializedProperty killOffLimitsParticles;
|
||||
SerializedProperty worldLinearInertiaScale;
|
||||
SerializedProperty worldAngularInertiaScale;
|
||||
|
||||
SerializedProperty foamSubsteps;
|
||||
SerializedProperty foamMinNeighbors;
|
||||
SerializedProperty foamCollisions;
|
||||
SerializedProperty foamRadiusScale;
|
||||
SerializedProperty foamVolumeDensity;
|
||||
SerializedProperty foamAmbientDensity;
|
||||
SerializedProperty foamScatterColor;
|
||||
SerializedProperty foamAmbientColor;
|
||||
SerializedProperty maxFoamVelocityStretch;
|
||||
SerializedProperty foamFade;
|
||||
SerializedProperty foamAccelAgingRange;
|
||||
SerializedProperty foamAccelAging;
|
||||
|
||||
SerializedProperty distanceConstraintParameters;
|
||||
SerializedProperty bendingConstraintParameters;
|
||||
SerializedProperty particleCollisionConstraintParameters;
|
||||
@@ -80,72 +58,37 @@ namespace Obi
|
||||
SerializedProperty shapeMatchingConstraintParameters;
|
||||
SerializedProperty tetherConstraintParameters;
|
||||
SerializedProperty pinConstraintParameters;
|
||||
SerializedProperty pinholeConstraintParameters;
|
||||
SerializedProperty stitchConstraintParameters;
|
||||
SerializedProperty densityConstraintParameters;
|
||||
SerializedProperty stretchShearConstraintParameters;
|
||||
SerializedProperty bendTwistConstraintParameters;
|
||||
SerializedProperty chainConstraintParameters;
|
||||
|
||||
SerializedProperty maxSurfaceChunks;
|
||||
SerializedProperty maxQueryResults;
|
||||
SerializedProperty maxFoamParticles;
|
||||
SerializedProperty maxParticleNeighbors;
|
||||
SerializedProperty maxParticleContacts;
|
||||
|
||||
BooleanPreference solverFoldout;
|
||||
BooleanPreference simulationFoldout;
|
||||
BooleanPreference advectionFoldout;
|
||||
BooleanPreference collisionsFoldout;
|
||||
BooleanPreference constraintsFoldout;
|
||||
BooleanPreference memoryFoldout;
|
||||
|
||||
GUIContent constraintLabelContent;
|
||||
|
||||
BoxBoundsHandle limitsBoxHandle;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
solver = (ObiSolver)target;
|
||||
constraintLabelContent = new GUIContent();
|
||||
limitsBoxHandle = new BoxBoundsHandle();
|
||||
|
||||
solverFoldout = new BooleanPreference($"{target.GetType()}.solverFoldout", true);
|
||||
simulationFoldout = new BooleanPreference($"{target.GetType()}.simulationFoldout", false);
|
||||
advectionFoldout = new BooleanPreference($"{target.GetType()}.advectionFoldout", false);
|
||||
collisionsFoldout = new BooleanPreference($"{target.GetType()}.collisionsFoldout", false);
|
||||
constraintsFoldout = new BooleanPreference($"{target.GetType()}.constraintsFoldout", false);
|
||||
memoryFoldout = new BooleanPreference($"{target.GetType()}.memoryFoldout", false);
|
||||
|
||||
backend = serializedObject.FindProperty("m_Backend");
|
||||
substeps = serializedObject.FindProperty("substeps");
|
||||
maxStepsPerFrame = serializedObject.FindProperty("maxStepsPerFrame");
|
||||
synchronization = serializedObject.FindProperty("synchronization");
|
||||
simulateWhenInvisible = serializedObject.FindProperty("simulateWhenInvisible");
|
||||
parameters = serializedObject.FindProperty("parameters");
|
||||
gravity = serializedObject.FindProperty("gravity");
|
||||
gravitySpace = serializedObject.FindProperty("gravitySpace");
|
||||
ambientWind = serializedObject.FindProperty("ambientWind");
|
||||
windSpace = serializedObject.FindProperty("windSpace");
|
||||
useLimits = serializedObject.FindProperty("useLimits");
|
||||
boundaryLimits = serializedObject.FindProperty("boundaryLimits");
|
||||
killOffLimitsParticles = serializedObject.FindProperty("killOffLimitsParticles");
|
||||
worldLinearInertiaScale = serializedObject.FindProperty("worldLinearInertiaScale");
|
||||
worldAngularInertiaScale = serializedObject.FindProperty("worldAngularInertiaScale");
|
||||
|
||||
foamSubsteps = serializedObject.FindProperty("foamSubsteps");
|
||||
foamMinNeighbors = serializedObject.FindProperty("foamMinNeighbors");
|
||||
foamCollisions = serializedObject.FindProperty("foamCollisions");
|
||||
foamRadiusScale = serializedObject.FindProperty("foamRadiusScale");
|
||||
foamVolumeDensity = serializedObject.FindProperty("foamVolumeDensity");
|
||||
foamAmbientDensity = serializedObject.FindProperty("foamAmbientDensity");
|
||||
foamScatterColor = serializedObject.FindProperty("foamScatterColor");
|
||||
foamAmbientColor = serializedObject.FindProperty("foamAmbientColor");
|
||||
maxFoamVelocityStretch = serializedObject.FindProperty("maxFoamVelocityStretch");
|
||||
foamFade = serializedObject.FindProperty("foamFade");
|
||||
foamAccelAgingRange = serializedObject.FindProperty("foamAccelAgingRange");
|
||||
foamAccelAging = serializedObject.FindProperty("foamAccelAging");
|
||||
|
||||
distanceConstraintParameters = serializedObject.FindProperty("distanceConstraintParameters");
|
||||
bendingConstraintParameters = serializedObject.FindProperty("bendingConstraintParameters");
|
||||
particleCollisionConstraintParameters = serializedObject.FindProperty("particleCollisionConstraintParameters");
|
||||
@@ -157,45 +100,19 @@ namespace Obi
|
||||
shapeMatchingConstraintParameters = serializedObject.FindProperty("shapeMatchingConstraintParameters");
|
||||
tetherConstraintParameters = serializedObject.FindProperty("tetherConstraintParameters");
|
||||
pinConstraintParameters = serializedObject.FindProperty("pinConstraintParameters");
|
||||
pinholeConstraintParameters = serializedObject.FindProperty("pinholeConstraintParameters");
|
||||
stitchConstraintParameters = serializedObject.FindProperty("stitchConstraintParameters");
|
||||
densityConstraintParameters = serializedObject.FindProperty("densityConstraintParameters");
|
||||
stretchShearConstraintParameters = serializedObject.FindProperty("stretchShearConstraintParameters");
|
||||
bendTwistConstraintParameters = serializedObject.FindProperty("bendTwistConstraintParameters");
|
||||
chainConstraintParameters = serializedObject.FindProperty("chainConstraintParameters");
|
||||
|
||||
maxSurfaceChunks = serializedObject.FindProperty("m_MaxSurfaceChunks");
|
||||
maxQueryResults = serializedObject.FindProperty("maxQueryResults");
|
||||
maxFoamParticles = serializedObject.FindProperty("maxFoamParticles");
|
||||
maxParticleNeighbors = serializedObject.FindProperty("maxParticleNeighbors");
|
||||
maxParticleContacts = serializedObject.FindProperty("maxParticleContacts");
|
||||
}
|
||||
|
||||
public void OnSceneGUI()
|
||||
{
|
||||
if (solver.useLimits)
|
||||
{
|
||||
using (new Handles.DrawingScope(Color.red, solver.transform.localToWorldMatrix))
|
||||
{
|
||||
limitsBoxHandle.center = solver.boundaryLimits.center;
|
||||
limitsBoxHandle.size = solver.boundaryLimits.size;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
limitsBoxHandle.DrawHandle();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
solver.boundaryLimits = new Bounds(limitsBoxHandle.center, limitsBoxHandle.size);
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
serializedObject.UpdateIfRequiredOrScript();
|
||||
EditorGUILayout.HelpBox("Particles:" + solver.allocParticleCount + "\n" +
|
||||
"Simplices:" + solver.simplexCounts.simplexCount + "\n" +
|
||||
EditorGUILayout.HelpBox("Particles:" + solver.allocParticleCount +"\n"+
|
||||
"Simplices:" + solver.simplexCounts.simplexCount+"\n" +
|
||||
"Contacts:" + solver.contactCount + "\n" +
|
||||
"Simplex contacts:" + solver.particleContactCount, MessageType.None);
|
||||
|
||||
@@ -206,14 +123,13 @@ namespace Obi
|
||||
EditorGUILayout.PropertyField(backend);
|
||||
|
||||
#if !(OBI_BURST && OBI_MATHEMATICS && OBI_COLLECTIONS)
|
||||
if (backend.enumValueIndex == (int)ObiSolver.BackendType.Burst)
|
||||
EditorGUILayout.HelpBox("The Burst backend depends on the following packages: Mathematics, Collections, Jobs and Burst. Please install the required dependencies. The solver will try to fall back to the Compute backend instead.", MessageType.Warning);
|
||||
if (backend.enumValueIndex == (int)ObiSolver.BackendType.Burst)
|
||||
EditorGUILayout.HelpBox("The Burst backend depends on the following packages: Mathematics, Collections, Jobs and Burst. The default backend (Oni) will be used instead, if possible.", MessageType.Warning);
|
||||
#endif
|
||||
#if !(OBI_ONI_SUPPORTED)
|
||||
if (backend.enumValueIndex == (int)ObiSolver.BackendType.Oni)
|
||||
EditorGUILayout.HelpBox("The Oni backend is not compatible with the target platform. Please switch to a compatible platform, or use the Burst backend instead.", MessageType.Warning);
|
||||
#endif
|
||||
if (!SystemInfo.supportsComputeShaders)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This platform doesn't support compute shaders. Please switch to the Burst backend.", MessageType.Error);
|
||||
}
|
||||
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
@@ -222,11 +138,9 @@ namespace Obi
|
||||
(t as ObiSolver).UpdateBackend();
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("mode"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("interpolation"));
|
||||
EditorGUILayout.PropertyField(synchronization);
|
||||
EditorGUILayout.PropertyField(substeps);
|
||||
EditorGUILayout.PropertyField(maxStepsPerFrame);
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
@@ -235,57 +149,24 @@ namespace Obi
|
||||
{
|
||||
EditorGUILayout.PropertyField(gravitySpace);
|
||||
EditorGUILayout.PropertyField(gravity);
|
||||
EditorGUILayout.PropertyField(windSpace);
|
||||
EditorGUILayout.PropertyField(ambientWind);
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("sleepThreshold"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("maxVelocity"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("maxAngularVelocity"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("damping"));
|
||||
EditorGUILayout.PropertyField(worldLinearInertiaScale);
|
||||
EditorGUILayout.PropertyField(worldAngularInertiaScale);
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("maxAnisotropy"));
|
||||
EditorGUILayout.PropertyField(simulateWhenInvisible);
|
||||
EditorGUILayout.PropertyField(useLimits);
|
||||
if (useLimits.boolValue)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(killOffLimitsParticles);
|
||||
EditorGUILayout.PropertyField(boundaryLimits);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
advectionFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(advectionFoldout, "Foam settings");
|
||||
if (advectionFoldout)
|
||||
{
|
||||
EditorGUILayout.PropertyField(foamSubsteps);
|
||||
EditorGUILayout.PropertyField(foamMinNeighbors);
|
||||
EditorGUILayout.PropertyField(foamCollisions, new GUIContent("Foam Collisions (Compute only)"));
|
||||
EditorGUILayout.PropertyField(foamRadiusScale);
|
||||
EditorGUILayout.PropertyField(foamVolumeDensity);
|
||||
EditorGUILayout.PropertyField(foamAmbientDensity);
|
||||
EditorGUILayout.PropertyField(foamScatterColor);
|
||||
EditorGUILayout.PropertyField(foamAmbientColor);
|
||||
EditorGUILayout.PropertyField(maxFoamVelocityStretch);
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("foamGravityScale"));
|
||||
EditorGUILayout.PropertyField(foamFade);
|
||||
EditorGUILayout.PropertyField(foamAccelAgingRange);
|
||||
EditorGUILayout.PropertyField(foamAccelAging);
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
collisionsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(collisionsFoldout, "Collision settings");
|
||||
if (collisionsFoldout)
|
||||
{
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("colliderCCD"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("particleCCD"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("continuousCollisionDetection"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("collisionMargin"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("maxDepenetration"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("shockPropagation"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("surfaceCollisionIterations"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("surfaceCollisionTolerance"));
|
||||
EditorGUILayout.PropertyField(parameters.FindPropertyRelative("diffusionMask"));
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
@@ -325,9 +206,6 @@ namespace Obi
|
||||
constraintLabelContent.text = "Pin";
|
||||
EditorGUILayout.PropertyField(pinConstraintParameters, constraintLabelContent);
|
||||
|
||||
constraintLabelContent.text = "Pinhole";
|
||||
EditorGUILayout.PropertyField(pinholeConstraintParameters, constraintLabelContent);
|
||||
|
||||
constraintLabelContent.text = "Stitch";
|
||||
EditorGUILayout.PropertyField(stitchConstraintParameters, constraintLabelContent);
|
||||
|
||||
@@ -345,46 +223,13 @@ namespace Obi
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
memoryFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(memoryFoldout, "Memory budget");
|
||||
if (memoryFoldout)
|
||||
{
|
||||
EditorGUILayout.PropertyField(maxQueryResults);
|
||||
EditorGUILayout.PropertyField(maxFoamParticles);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(maxSurfaceChunks);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
foreach (var t in targets)
|
||||
(t as ObiSolver).dirtyRendering |= (int)Oni.RenderingSystemType.Fluid;
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(maxParticleNeighbors);
|
||||
EditorGUILayout.PropertyField(maxParticleContacts);
|
||||
|
||||
uint usedChunks = solver.usedSurfaceChunks;
|
||||
float usagePercentage = usedChunks / (float)maxSurfaceChunks.intValue;
|
||||
uint foamParticles = solver.initialized ? solver.implementation.activeFoamParticleCount : 0;
|
||||
|
||||
// memory consumption per chunk:
|
||||
// (8 + 12 + 64*4 + 64*6*4 + 64*16) = 2836 bytes
|
||||
EditorGUILayout.HelpBox("Active foam particles: " + foamParticles + "/" + maxFoamParticles.intValue + "\n"+
|
||||
"Surface memory (Mb): " + string.Format("{0:N2}", maxSurfaceChunks.intValue * 0.002836f)+ "\n"+
|
||||
"Used surface chunks: "+ usedChunks + "/"+ maxSurfaceChunks.intValue + ", hashtable usage "+ string.Format("{0:N1}", usagePercentage * 100) + "%", MessageType.None);
|
||||
|
||||
if (usagePercentage >= 0.5f)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Hashtable usage should be below 50% for best performance. Increase max surface chunks if % is too high.", MessageType.Warning);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
// Apply changes to the serializedProperty
|
||||
if (GUI.changed)
|
||||
{
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
solver.PushSolverParameters();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -392,12 +237,15 @@ namespace Obi
|
||||
[DrawGizmo(GizmoType.InSelectionHierarchy | GizmoType.Selected)]
|
||||
static void DrawGizmoForSolver(ObiSolver solver, GizmoType gizmoType)
|
||||
{
|
||||
|
||||
if ((gizmoType & GizmoType.InSelectionHierarchy) != 0)
|
||||
{
|
||||
|
||||
Gizmos.color = new Color(1, 1, 1, 0.5f);
|
||||
var bounds = solver.bounds;
|
||||
Bounds bounds = solver.Bounds;
|
||||
Gizmos.DrawWireCube(bounds.center, bounds.size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.IO;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Obi{
|
||||
|
||||
@@ -128,7 +127,17 @@ namespace Obi{
|
||||
public static GameObject CreateNewSolver()
|
||||
{
|
||||
// Root for the actors.
|
||||
var root = new GameObject("Obi Solver", typeof(ObiSolver));
|
||||
var root = new GameObject("Obi Solver");
|
||||
ObiSolver solver = root.AddComponent<ObiSolver>();
|
||||
|
||||
// Try to find a fixed updater in the scene (though other kinds of updaters can exist, updating in FixedUpdate is the preferred option).
|
||||
ObiFixedUpdater updater = StageUtility.GetCurrentStageHandle().FindComponentOfType<ObiFixedUpdater>();
|
||||
// If we could not find an fixed updater in the scene, add one to the solver object.
|
||||
if (updater == null)
|
||||
updater = root.AddComponent<ObiFixedUpdater>();
|
||||
|
||||
// Add the solver to the updater:
|
||||
updater.solvers.Add(solver);
|
||||
|
||||
// Works for all stages.
|
||||
StageUtility.PlaceGameObjectInCurrentStage(root);
|
||||
@@ -221,34 +230,7 @@ namespace Obi{
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Obi
|
||||
SerializedProperty targetTransform;
|
||||
SerializedProperty particleGroup;
|
||||
SerializedProperty attachmentType;
|
||||
SerializedProperty projectPosition;
|
||||
SerializedProperty constrainOrientation;
|
||||
SerializedProperty compliance;
|
||||
SerializedProperty breakThreshold;
|
||||
@@ -29,10 +28,9 @@ namespace Obi
|
||||
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");
|
||||
breakThreshold = serializedObject.FindProperty("m_BreakThreshold");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -57,16 +55,7 @@ namespace Obi
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
EditorGUILayout.PropertyField(targetTransform, new GUIContent("Target"));
|
||||
var blueprint = attachment.actor.sourceBlueprint;
|
||||
|
||||
if (blueprint != null)
|
||||
@@ -100,7 +89,6 @@ namespace Obi
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user