修改水
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c8d9d8042d49436c89c515b001088ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user