private void Awake() { _explosionParticles = Instantiate(ExplosionPrefab).GetComponent<ParticleSystem>(); _explosionAudio = _explosionParticles.GetComponent<AudioSource>(); _explosionParticles.gameObject.SetActive(false); }
public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps) { var material = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MaterialPath, typeof(Material)) as Material; var texture = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.Texture2DPath, typeof(Texture2D)) as Texture2D; var newtexture = ImageUtil.rotateTexture180(texture); newtexture.alphaIsTransparency = true; newtexture.filterMode = texture.filterMode; newtexture.wrapMode = texture.wrapMode; newtexture.name = texture.name + "_rot180"; material.SetTexture("_MainTex", newtexture); //UnityEditor.AssetDatabase.CreateAsset(newtexture, SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + newtexture.name); //UnityEditor.AssetDatabase.Refresh(); float baseTilingX = 1f; float baseTilingY = 1f; float baseOffsetX = 0f; float baseOffsetY = 0f; material.SetTextureScale("_MainTex", new Vector2(baseTilingX, baseTilingY)); material.SetTextureOffset("_MainTex", new Vector2(baseOffsetX, baseOffsetY)); uint color = 0xFFFFFFFF; material.SetColor("_Color", new Color(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f)); ParticleSystemRenderer render = ups.GetComponent <ParticleSystemRenderer>(); render.material = material; render.lengthScale = 1.0f; render.renderMode = ParticleSystemRenderMode.Stretch; }
public ParticleState( AmplifyMotionCamera owner, AmplifyMotionObjectBase obj ) : base( owner, obj ) { m_particleSystem = m_obj.GetComponent<ParticleSystem>(); m_renderer = m_particleSystem.GetComponent<ParticleSystemRenderer>(); rotationOverLifetime = m_particleSystem.rotationOverLifetime; rotationBySpeed = m_particleSystem.rotationBySpeed; }
private static void FillRenderModule(UnityEngine.ParticleSystem ups, ParticleSystem ps) { ParticleSystemRenderer psr = ups.GetComponent <ParticleSystemRenderer>(); psr.sortingOrder = ps.Layer; var material = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MaterialPath, typeof(Material)) as Material; psr.renderMode = (ParticleSystemRenderMode)ps.RenderParam.BillboardType; if (psr.renderMode == ParticleSystemRenderMode.Mesh) { if (ps.SurfId != 0) { psr.mesh = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MeshPath, typeof(Mesh)) as Mesh; } else { if (!File.Exists(SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab")) { PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Quad, true, SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab"); } psr.mesh = UnityEditor.AssetDatabase.LoadAssetAtPath(SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab", typeof(Mesh)) as Mesh; } } else if (psr.renderMode == ParticleSystemRenderMode.Stretch) { psr.lengthScale = 1.0f; var texture = material.mainTexture as Texture2D; var newtexture = ImageUtil.rotateTexture(texture, true); newtexture.alphaIsTransparency = true; newtexture.filterMode = texture.filterMode; newtexture.wrapMode = texture.wrapMode; newtexture.name = texture.name + "_rotNeg90"; //UnityEditor.AssetDatabase.CreateAsset(newtexture, SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + newtexture.name); //UnityEditor.AssetDatabase.Refresh(); material.SetTexture("_MainTex", newtexture); float baseTilingX = 1f; float baseTilingY = 1f; float baseOffsetX = 0f; float baseOffsetY = 0f; material.SetTextureScale("_MainTex", new Vector2(baseTilingX, baseTilingY)); material.SetTextureOffset("_MainTex", new Vector2(baseOffsetX, baseOffsetY)); uint color = 0xFFFFFFFF; material.SetColor("_Color", new Color(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f)); UnityEditor.AssetDatabase.Refresh(); } //如果有mesh,强制使用meshbillboard 类型 if (ps.SurfId != 0) { psr.renderMode = ParticleSystemRenderMode.Mesh; psr.mesh = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MeshPath, typeof(Mesh)) as Mesh; } psr.material = material; }
private void Awake() { // Instantiate the explosion prefab and get a reference to the particle system on it. m_ExplosionParticles = Instantiate (m_ExplosionPrefab).GetComponent<ParticleSystem> (); // Get a reference to the audio source on the instantiated prefab. m_ExplosionAudio = m_ExplosionParticles.GetComponent<AudioSource> (); // Disable the prefab so it can be activated when it's required. m_ExplosionParticles.gameObject.SetActive (false); }
private void RescaleParticles(ParticleSystem particleSystem, float factor) { Undo.RecordObject(particleSystem, "Scale Particles"); // the public ParticleSystem api doesn't expose all the parameters that we need to change when scaling the particle system, // so we need to go direct into the serialized object and poke the properties there. SerializedObject system = new SerializedObject(particleSystem); system.FindProperty("InitialModule.startSize.scalar").floatValue *= factor; system.FindProperty("InitialModule.startSpeed.scalar").floatValue *= factor; system.FindProperty("InitialModule.gravityModifier").floatValue *= factor; system.FindProperty("ShapeModule.radius").floatValue *= factor; system.FindProperty("ShapeModule.boxX").floatValue *= factor; system.FindProperty("ShapeModule.boxY").floatValue *= factor; system.FindProperty("ShapeModule.boxZ").floatValue *= factor; system.FindProperty("VelocityModule.x.scalar").floatValue *= factor; system.FindProperty("VelocityModule.y.scalar").floatValue *= factor; system.FindProperty("VelocityModule.z.scalar").floatValue *= factor; system.FindProperty("ClampVelocityModule.x.scalar").floatValue *= factor; system.FindProperty("ClampVelocityModule.y.scalar").floatValue *= factor; system.FindProperty("ClampVelocityModule.z.scalar").floatValue *= factor; system.FindProperty("ForceModule.x.scalar").floatValue *= factor; system.FindProperty("ForceModule.y.scalar").floatValue *= factor; system.FindProperty("ForceModule.z.scalar").floatValue *= factor; system.FindProperty("SizeBySpeedModule.range").vector2Value *= factor; system.FindProperty("RotationBySpeedModule.range").vector2Value *= factor; system.FindProperty("ColorBySpeedModule.range").vector2Value *= factor; system.ApplyModifiedProperties(); ParticleTurbulence turbulence = particleSystem.GetComponent<ParticleTurbulence>(); if (turbulence != null) { Undo.RecordObject(turbulence, "Scale Particles"); SerializedObject turb = new SerializedObject(turbulence); turb.FindProperty("amplitude").floatValue *= factor; turb.FindProperty("frequency").floatValue /= factor; turb.ApplyModifiedProperties(); } }
public void Init(P5Particle[] p5particles) { particles = p5particles; maxParticles = particles.Length; if (psys == null) { psys = this.gameObject.AddComponent <UnityEngine.ParticleSystem>() as UnityEngine.ParticleSystem; } psys.GetComponent <Renderer>().material = mat; psys.playOnAwake = false; psys.enableEmission = false; psys.loop = false; psys.Stop(); renderParticles = new UnityEngine.ParticleSystem.Particle[maxParticles]; for (int i = 0; i < maxParticles; i++) { renderParticles[i] = new UnityEngine.ParticleSystem.Particle(); } Reset(); }
void On_CosmosReady() { isReady = true; cacheTransform = Cosmos.instance.SpaceCamera.transform; // Create particle system gameObject.AddComponent<ParticleSystem>(); cacheCosmosParticle = GetComponent<ParticleSystem>(); cacheCosmosParticle.playOnAwake = false; cacheCosmosParticle.enableEmission = false; cacheCosmosParticle.simulationSpace = ParticleSystemSimulationSpace.Local; cacheCosmosParticle.emissionRate = 0; cacheCosmosParticle.startSpeed = 0; cacheCosmosParticle.startLifetime = Mathf.Infinity; cacheCosmosParticle.startRotation = Random.Range(-Mathf.PI,Mathf.PI); cacheCosmosParticle.GetComponent<Renderer>().material = mat; cacheCosmosParticle.GetComponent<Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; cacheCosmosParticle.GetComponent<Renderer>().receiveShadows = false; // Pre Spawn for (int i=0; i < maxParticle; i ++) { Vector3 drift = Vector3.zero; if (enableDrift){ drift =new Vector3( Random.Range(-1f,1f),Random.Range(-1f,1f),0) * driftSpeed; } cacheCosmosParticle.Emit( cacheTransform.position + (UnityEngine.Random.insideUnitSphere * 200), drift, Random.Range(minSize, maxSize ) , Mathf.Infinity, color.Evaluate( Random.Range(0f,1f))); } }
public override void OnInspectorGUI(ParticleSystem s) { if (RendererModuleUI.s_Texts == null) { RendererModuleUI.s_Texts = new RendererModuleUI.Texts(); } RendererModuleUI.RenderMode intValue = (RendererModuleUI.RenderMode)this.m_RenderMode.intValue; RendererModuleUI.RenderMode renderMode = (RendererModuleUI.RenderMode)ModuleUI.GUIPopup(RendererModuleUI.s_Texts.renderMode, this.m_RenderMode, RendererModuleUI.s_Texts.particleTypes); if (renderMode == RendererModuleUI.RenderMode.Mesh) { EditorGUI.indentLevel++; this.DoListOfMeshesGUI(); EditorGUI.indentLevel--; if (intValue != RendererModuleUI.RenderMode.Mesh && this.m_Meshes[0].objectReferenceInstanceIDValue == 0) { this.m_Meshes[0].objectReferenceValue = Resources.GetBuiltinResource(typeof(Mesh), "Cube.fbx"); } } else { if (renderMode == RendererModuleUI.RenderMode.Stretch3D) { EditorGUI.indentLevel++; ModuleUI.GUIFloat(RendererModuleUI.s_Texts.cameraSpeedScale, this.m_CameraVelocityScale); ModuleUI.GUIFloat(RendererModuleUI.s_Texts.speedScale, this.m_VelocityScale); ModuleUI.GUIFloat(RendererModuleUI.s_Texts.lengthScale, this.m_LengthScale); EditorGUI.indentLevel--; } } if (renderMode != RendererModuleUI.RenderMode.Mesh) { ModuleUI.GUIFloat(RendererModuleUI.s_Texts.normalDirection, this.m_NormalDirection); } if (this.m_Material != null) { ModuleUI.GUIObject(RendererModuleUI.s_Texts.material, this.m_Material); } ModuleUI.GUIPopup(RendererModuleUI.s_Texts.sortMode, this.m_SortMode, RendererModuleUI.s_Texts.sortTypes); ModuleUI.GUIFloat(RendererModuleUI.s_Texts.sortingFudge, this.m_SortingFudge); ModuleUI.GUIPopup(RendererModuleUI.s_Texts.castShadows, this.m_CastShadows, this.m_CastShadows.enumDisplayNames); ModuleUI.GUIToggle(RendererModuleUI.s_Texts.receiveShadows, this.m_ReceiveShadows); ModuleUI.GUIFloat(RendererModuleUI.s_Texts.maxParticleSize, this.m_MaxParticleSize); EditorGUILayout.Space(); EditorGUILayout.SortingLayerField(RendererModuleUI.s_Texts.sortingLayer, this.m_SortingLayerID, ParticleSystemStyles.Get().popup, ParticleSystemStyles.Get().label); ModuleUI.GUIInt(RendererModuleUI.s_Texts.sortingOrder, this.m_SortingOrder); this.m_Probes.OnGUI(s.GetComponent<Renderer>(), true); }
void Start() { targetSystem = GetComponent<ParticleSystem>(); targetRenderer = targetSystem.GetComponent<ParticleSystemRenderer>(); targetRenderer.enabled = false; }
public override void OnInspectorGUI(ParticleSystem s) { if (RendererModuleUI.s_Texts == null) RendererModuleUI.s_Texts = new RendererModuleUI.Texts(); RendererModuleUI.RenderMode intValue = (RendererModuleUI.RenderMode) this.m_RenderMode.intValue; RendererModuleUI.RenderMode renderMode = (RendererModuleUI.RenderMode) ModuleUI.GUIPopup(RendererModuleUI.s_Texts.renderMode, this.m_RenderMode, RendererModuleUI.s_Texts.particleTypes); if (renderMode == RendererModuleUI.RenderMode.Mesh) { ++EditorGUI.indentLevel; this.DoListOfMeshesGUI(); --EditorGUI.indentLevel; if (intValue != RendererModuleUI.RenderMode.Mesh && this.m_Meshes[0].objectReferenceInstanceIDValue == 0) this.m_Meshes[0].objectReferenceValue = Resources.GetBuiltinResource(typeof (Mesh), "Cube.fbx"); } else if (renderMode == RendererModuleUI.RenderMode.Stretch3D) { ++EditorGUI.indentLevel; double num1 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.cameraSpeedScale, this.m_CameraVelocityScale); double num2 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.speedScale, this.m_VelocityScale); double num3 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.lengthScale, this.m_LengthScale); --EditorGUI.indentLevel; } if (renderMode != RendererModuleUI.RenderMode.Mesh) { double num4 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.normalDirection, this.m_NormalDirection); } if (this.m_Material != null) ModuleUI.GUIObject(RendererModuleUI.s_Texts.material, this.m_Material); ModuleUI.GUIPopup(RendererModuleUI.s_Texts.sortMode, this.m_SortMode, RendererModuleUI.s_Texts.sortTypes); double num5 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.sortingFudge, this.m_SortingFudge); ModuleUI.GUIPopup(RendererModuleUI.s_Texts.castShadows, this.m_CastShadows, this.m_CastShadows.enumDisplayNames); EditorGUI.BeginDisabledGroup(SceneView.IsUsingDeferredRenderingPath()); ModuleUI.GUIToggle(RendererModuleUI.s_Texts.receiveShadows, this.m_ReceiveShadows); EditorGUI.EndDisabledGroup(); double num6 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.minParticleSize, this.m_MinParticleSize); double num7 = (double) ModuleUI.GUIFloat(RendererModuleUI.s_Texts.maxParticleSize, this.m_MaxParticleSize); EditorGUILayout.Space(); EditorGUILayout.SortingLayerField(RendererModuleUI.s_Texts.sortingLayer, this.m_SortingLayerID, ParticleSystemStyles.Get().popup, ParticleSystemStyles.Get().label); ModuleUI.GUIInt(RendererModuleUI.s_Texts.sortingOrder, this.m_SortingOrder); if (renderMode == RendererModuleUI.RenderMode.Billboard) ModuleUI.GUIPopup(RendererModuleUI.s_Texts.space, this.m_RenderAlignment, RendererModuleUI.s_Texts.spaces); ModuleUI.GUIVector3Field(RendererModuleUI.s_Texts.pivot, this.m_Pivot); this.m_Probes.OnGUI((Object[]) null, s.GetComponent<Renderer>(), true); }
public ParticleState( AmplifyMotionCamera owner, AmplifyMotionObjectBase obj ) : base( owner, obj ) { m_particleSystem = m_obj.GetComponent<ParticleSystem>(); m_meshRenderer = m_particleSystem.GetComponent<Renderer>().GetComponent<ParticleSystemRenderer>(); }