初
line renderer不尽如人意,所以有一个场面,particle走私到制作的像线。
示威
- particle使用了2 playground build player(web版)
- 不履行债务责任的particle system版(webglbuild)
解说
跟随鼠标的画线制作了示威。 補間鼠标坐标图单纯只是传达出虞国虞国就会在一定程度上消失,于是胡乱補間成为。 漂亮的曲线企图用过去的需要很多9推迟变得大了,所以1帧缓慢可以在这里2次,平均スプライン亲手制作方式。
using UnityEngine; using System.Collections.Generic; public static class LineInterpolation { public static List<Vector3> GetQuadraticPoints( Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, int num) { var points = new List<Vector3>(); for (int i = 0; i < num; ++i) { var t = (float)i / (num - 1); var l1 = GetQuadraticPoint(p1, p2, p3, 0.5f * (1f + t)); var l2 = GetQuadraticPoint(p2, p3, p4, 0.5f * t); points.Add((l1 + l2) * 0.5f); } return points; } private static Vector3 GetQuadraticPoint( Vector3 p1, Vector3 p2, Vector3 p3, float t) { return Vector3.Lerp(Vector3.Lerp(p1, p2, t), Vector3.Lerp(p2, p3, t), t); } }
最新摆脱过去的4分,2 ~ 3之间的曲线给人的感觉。 用这个来()particlesystem.emit
也可以创造。
using UnityEngine; using System.Collections.Generic; public class ParticleTrail : MonoBehaviour { public ParticleSystem particleSystem; public int pointNum = 100; public float interpolateLength = 0.2f; private List<Vector3> points_ = new List<Vector3>(); public List<Vector3> points { get { return points_; } } void Start() { points_.Clear(); } void Update() { AddPoint(transform.position); if (points_.Count > 3) { var n = Mathf.CeilToInt((points_[1] - points_[2]).magnitude / interpolateLength); if (n < 2) n = 2; foreach (var point in LineInterpolation.GetQuadraticPoints( points_[0], points_[1], points_[2], points_[3], n)) { Emit(point); } } else { Emit(points_[0]); } } void AddPoint(Vector3 point) { if (points_.Count >= pointNum) { points_.RemoveAt(pointNum - 1); } points_.Insert(0, point); } void Emit(Vector3 point) { particleSystem.Emit( point, Random.onUnitSphere * particleSystem.startSpeed, particleSystem.startSize, particleSystem.startLifetime, particleSystem.startColor); } }
这里transform.position
的位置上,所以无论如何,鼠标坐标可以根据自己的适当的一种脚本。
using UnityEngine; using System.Collections; public class MoveByMouse : MonoBehaviour { void Update() { var mousePos = Input.mousePosition; mousePos.z = 10f; transform.position = Camera.main.ScreenToWorldPoint(mousePos); } }
这两种脚本gameobject的天空,配属的是这样的感觉的表达方式。
在particlebillboardポリゴン标记,renderer line成为比任何一个角度看都很好看。 particle代替system particle playground,()particleplaygroundc.emit
在パーティクル,各种各样的动向,越发的线描写。 在此スクショ开头提到的。
而且在view作家朴正宇:補間分确认
线補間提供一种时editor脚本作家朴正宇view,使用補間分是如何绘图的方便。 软件editor参考脚本写一下。<a href="http://catlikecoding.com/unity/tutorials/curves-and-splines/">Curves and Splines, a Unity C# Tutorial</a>catlikecoding.com
using UnityEngine; using System.Collections.Generic; [CustomEditor(typeof(ParticleTrail))] public class ParticleTrailEditor : Editor { private const float PointSize = 0.05f; private const float DeltaLength = 0.05f; private void OnSceneGUI() { var trail = target as ParticleTrail; var points = trail.points; Handles.color = Color.gray; Handles.DrawPolyLine(points.ToArray()); var interpolatedPoints = new List<Vector3>(); for (int i = 0; i < points.Count; ++i) { var sceneForward = SceneView.lastActiveSceneView.camera.transform.forward; Handles.color = Color.white; Handles.DrawSolidDisc(points[i], sceneForward, PointSize); if (i >= 3) { var n = Mathf.CeilToInt((points[i - 2] - points[i - 1]).magnitude / trail.interpolateLength); if (n == 0) n = 1; var partialPoints = LineInterpolation.GetQuadraticPoints( points[i - 3], points[i - 2], points[i - 1], points[i], n); interpolatedPoints.AddRange(partialPoints); } } Handles.color = Color.green; Handles.DrawPolyLine(interpolatedPoints.ToArray()); } }
至此,原创的分开始的线和補間了怎样的差距视觉上确认开发变得可能。 适当的分国防科学研究所(add)测试数据突っ込める变好(以下测试数据的例子和particle)。playground版的代码
using UnityEngine; using System.Collections.Generic; using ParticlePlayground; public class ParticleTrail : MonoBehaviour { public PlaygroundParticlesC particle; public int pointNum = 100; public float interpolateLength = 0.2f; private List<Vector3> points_ = new List<Vector3>(); public List<Vector3> points { get { return points_; } } void Start() { points_.Clear(); } void Update() { AddPoint(transform.position); if (points_.Count > 3) { var n = Mathf.CeilToInt((points_[1] - points_[2]).magnitude / interpolateLength); if (n < 2) n = 2; foreach (var point in LineInterpolation.GetQuadraticPoints( points_[0], points_[1], points_[2], points_[3], n)) { particle.Emit(point); } } else { particle.Emit(points_[0]); } } void AddPoint(Vector3 point) { if (points_.Count >= pointNum) { points_.RemoveAt(pointNum - 1); } points_.Insert(0, point); } [ContextMenu("Input Test Data")] void Test() { points_.Add(new Vector3(0, 0, 0)); points_.Add(new Vector3(0, 1, 0)); points_.Add(new Vector3(0, 0, 1)); points_.Add(new Vector3(1, 1, 0)); points_.Add(new Vector3(2, 0, 0)); points_.Add(new Vector3(0, 2, 2)); points_.Add(new Vector3(3, 0, 3)); } }
至此,作家朴正宇view确认的是这样的感觉。
结束
数千个单位绘图不会因为不能继续负荷的游戏用途,我很严峻的时候,我想,インタラクションデモ或好吗?
附带提一下,
playground利用particlewebgl俊朗的东西都动不了的。 线程切啊。