Skip to content

Commit

Permalink
Added FloatingSwarm.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Jun 4, 2017
1 parent bd71719 commit f1c3c29
Show file tree
Hide file tree
Showing 8 changed files with 636 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Assets/Swarm/CrawlingSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,15 @@ void Start()
);

_drawArgsBuffer.SetData(new uint[5] {
_template.mesh.GetIndexCount(0),
(uint)InstanceCount, 0, 0, 0
_template.mesh.GetIndexCount(0), (uint)InstanceCount, 0, 0, 0
});

// Allocate compute buffers.
_positionBuffer = new ComputeBuffer(HistoryLength * InstanceCount, 16);
_tangentBuffer = new ComputeBuffer(HistoryLength * InstanceCount, 16);
_normalBuffer = new ComputeBuffer(HistoryLength * InstanceCount, 16);

// Initialize the position buffer.
// Initialize the compute buffers.
var kernel = _compute.FindKernel("CrawlingInit");
_compute.SetInt("InstanceCount", InstanceCount);
_compute.SetInt("HistoryLength", HistoryLength);
Expand Down
115 changes: 115 additions & 0 deletions Assets/Swarm/Editor/FloatingSwarmEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Swarm - Special renderer that draws a swarm of swirling/crawling lines.
// https://github.com/keijiro/Swarm

using UnityEngine;
using UnityEditor;

namespace Swarm
{
// Custom inspector for FloatingSwarm
[CustomEditor(typeof(FloatingSwarm)), CanEditMultipleObjects]
public class FloatingSwarmEditor : Editor
{
SerializedProperty _instanceCount;
SerializedProperty _template;
SerializedProperty _radius;

SerializedProperty _attractor;
SerializedProperty _attractorPosition;
SerializedProperty _attractorSpread;
SerializedProperty _attractorForce;

SerializedProperty _forceRandomness;
SerializedProperty _drag;

SerializedProperty _headNoiseForce;
SerializedProperty _headNoiseFrequency;
SerializedProperty _trailNoiseVelocity;
SerializedProperty _trailNoiseFrequency;
SerializedProperty _noiseSpread;
SerializedProperty _noiseMotion;

SerializedProperty _material;
SerializedProperty _gradient;

SerializedProperty _randomSeed;

static class Labels
{
public static GUIContent force = new GUIContent("Force");
public static GUIContent frequency = new GUIContent("Frequency");
public static GUIContent headForce = new GUIContent("Force (head)");
public static GUIContent headFrequency = new GUIContent("Frequency (head)");
public static GUIContent motion = new GUIContent("Motion");
public static GUIContent position = new GUIContent("Position");
public static GUIContent randomness = new GUIContent("Randomness");
public static GUIContent spread = new GUIContent("Spread");
public static GUIContent trailFrequency = new GUIContent("Frequency (trail)");
public static GUIContent trailVelocity = new GUIContent("Velocity (trail)");
}

void OnEnable()
{
_instanceCount = serializedObject.FindProperty("_instanceCount");
_template = serializedObject.FindProperty("_template");
_radius = serializedObject.FindProperty("_radius");

_attractor = serializedObject.FindProperty("_attractor");
_attractorPosition = serializedObject.FindProperty("_attractorPosition");
_attractorSpread = serializedObject.FindProperty("_attractorSpread");
_attractorForce = serializedObject.FindProperty("_attractorForce");

_forceRandomness = serializedObject.FindProperty("_forceRandomness");
_drag = serializedObject.FindProperty("_drag");

_headNoiseForce = serializedObject.FindProperty("_headNoiseForce");
_headNoiseFrequency = serializedObject.FindProperty("_headNoiseFrequency");
_trailNoiseVelocity = serializedObject.FindProperty("_trailNoiseVelocity");
_trailNoiseFrequency = serializedObject.FindProperty("_trailNoiseFrequency");
_noiseSpread = serializedObject.FindProperty("_noiseSpread");
_noiseMotion = serializedObject.FindProperty("_noiseMotion");

_material = serializedObject.FindProperty("_material");
_gradient = serializedObject.FindProperty("_gradient");

_randomSeed = serializedObject.FindProperty("_randomSeed");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_instanceCount);
EditorGUILayout.PropertyField(_template);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_radius);
EditorGUI.indentLevel--;

EditorGUILayout.PropertyField(_attractor);
EditorGUI.indentLevel++;
if (_attractor.objectReferenceValue == null)
EditorGUILayout.PropertyField(_attractorPosition, Labels.position);
EditorGUILayout.PropertyField(_attractorSpread, Labels.spread);
EditorGUILayout.PropertyField(_attractorForce, Labels.force);
EditorGUILayout.PropertyField(_forceRandomness, Labels.randomness);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(_drag);

EditorGUILayout.LabelField("Noise Field");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(_headNoiseForce, Labels.headForce);
EditorGUILayout.PropertyField(_headNoiseFrequency, Labels.headFrequency);
EditorGUILayout.PropertyField(_trailNoiseVelocity, Labels.trailVelocity);
EditorGUILayout.PropertyField(_trailNoiseFrequency, Labels.trailFrequency);
EditorGUILayout.PropertyField(_noiseSpread, Labels.spread);
EditorGUILayout.PropertyField(_noiseMotion, Labels.motion);
EditorGUI.indentLevel--;

EditorGUILayout.PropertyField(_material);
EditorGUILayout.PropertyField(_gradient);
EditorGUILayout.PropertyField(_randomSeed);

serializedObject.ApplyModifiedProperties();
}
}
}
12 changes: 12 additions & 0 deletions Assets/Swarm/Editor/FloatingSwarmEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1c3c29

Please sign in to comment.