Created
May 17, 2017 15:13
-
-
Save onotchi/67655f580c1d4aeae49aa2533389521e to your computer and use it in GitHub Desktop.
Ink Painterを使って、パーティクルの衝突でインクを塗る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Es.InkPainter; | |
using UnityEngine; | |
namespace Onoty3D | |
{ | |
public class ParticlePainter : MonoBehaviour | |
{ | |
public Brush Brush = null; | |
public ParticleSystem Particle; | |
private List<ParticleCollisionEvent> _collisionEvents; | |
// Use this for initialization | |
private void Start() | |
{ | |
this.Particle = this.GetComponent<ParticleSystem>(); | |
this._collisionEvents = new List<ParticleCollisionEvent>(16); | |
} | |
// Update is called once per frame | |
private void Update() | |
{ | |
} | |
private void OnParticleCollision(GameObject other) | |
{ | |
var safeSize = Particle.GetSafeCollisionEventSize(); | |
if (this._collisionEvents.Count < safeSize) | |
{ | |
this._collisionEvents = new List<ParticleCollisionEvent>(safeSize); | |
} | |
this.Particle.GetCollisionEvents(other, this._collisionEvents); | |
foreach (var collisionEvent in this._collisionEvents) | |
{ | |
if (collisionEvent.colliderComponent == null) | |
{ | |
continue; | |
} | |
var canvas = collisionEvent.colliderComponent.GetComponent<InkCanvas>(); | |
if (canvas == null) | |
{ | |
continue; | |
} | |
canvas.PaintNearestTriangleSurface(Brush, collisionEvent.intersection); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment