public static void Init() { var instances = Resources.FindObjectsOfTypeAll <TCParticleGlobalManager>(); foreach (var inst in instances) { DestroyImmediate(inst); } Instance = new GameObject("TCParticleGlobalManager").AddComponent <TCParticleGlobalManager>(); Instance.gameObject.hideFlags = HideFlags.HideAndDontSave; if (Application.isPlaying) { DontDestroyOnLoad(Instance); } //Have to load compute shader first frame as other components //TODO: I don't like resource loading this Instance.ComputeShader = Resources.Load("Compute/MassParticle") as ComputeShader; if (Instance.ComputeShader == null) { Debug.LogError("Failed to load compute shader!"); } }
public void SetMeshData(ComputeShader cs, int kern, ref ParticleEmitterData emitter) { if (emitMesh == null) { return; } var buffer = TCParticleGlobalManager.GetMeshBuffer(emitMesh, uvChannel); uint onSurface; if (!spawnOnMeshSurface) { onSurface = 0; } else { onSurface = normalizeArea ? (uint)1 : 2; } emitter.MeshVertLen = (uint)buffer.count; emitter.OnSurface = onSurface; cs.SetBuffer(kern, "emitFaces", buffer); if (texture != null) { cs.SetTexture(kern, "_MeshTexture", texture); } else { cs.SetTexture(kern, "_MeshTexture", Texture2D.whiteTexture); } }