protected void Initialize() { if (_initialized) { return; } _initialized = true; _rectTransform = GetComponent <RectTransform>(); _particleSystem = GetComponent <ParticleSystem>(); _main = _particleSystem.main; _textureSheetAnimation = _particleSystem.textureSheetAnimation; _shape = _particleSystem.shape; _particleSystemRenderer = GetComponent <ParticleSystemRenderer>(); _particleSystemRenderer.enabled = false; _particleSystemRenderer.material = null; int maxCount = _main.maxParticles; _particles = new ParticleSystem.Particle[maxCount]; _particlesLifeProgress = new float[maxCount]; _particleElapsedLifetime = new float[maxCount]; }
private void Initialize() { if (initialized) { return; } var particleSystem = GetParticleSystem(); var mainModule = GetMainModule(); // limit max particles. mainModule.maxParticles = Mathf.Clamp(mainModule.maxParticles, 0, 10000); // automatically set scaling. mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; startFrames = new int?[particleSystem.main.maxParticles]; particles = new ParticleSystem.Particle[particleSystem.main.maxParticles]; // prepare texture sheet animation. textureSheetAnimation = particleSystem.textureSheetAnimation; raycastTarget = false; // disable particle renderer. var particleSystemRenderer = GetParticleSystemRenderer(); particleSystemRenderer.enabled = false; initialized = true; }
protected bool Initialize() { // initialize members if (_transform == null) { _transform = transform; } if (_particleSystem == null) { _particleSystem = GetComponent <ParticleSystem>(); if (_particleSystem == null) { return(false); } // automatically set material to UI/Particles/Hidden shader, and get previous texture ParticleSystemRenderer renderer = _particleSystem.GetComponent <ParticleSystemRenderer>(); if (renderer == null) { renderer = _particleSystem.gameObject.AddComponent <ParticleSystemRenderer>(); } Material currentMaterial = renderer.sharedMaterial; if (currentMaterial && currentMaterial.HasProperty("_MainTex")) { particleTexture = currentMaterial.mainTexture; } // automatically set scaling _particleSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; _particles = null; } if (_particles == null) { _particles = new ParticleSystem.Particle[_particleSystem.maxParticles]; } // prepare uvs if (particleTexture) { _uv = new Vector4(0, 0, 1, 1); } else if (particleSprite) { _uv = UnityEngine.Sprites.DataUtility.GetOuterUV(particleSprite); } // prepare texture sheet animation _textureSheetAnimation = _particleSystem.textureSheetAnimation; _textureSheetAnimationFrames = 0; _textureSheedAnimationFrameSize = Vector2.zero; if (_textureSheetAnimation.enabled) { _textureSheetAnimationFrames = _textureSheetAnimation.numTilesX * _textureSheetAnimation.numTilesY; _textureSheedAnimationFrameSize = new Vector2(1f / _textureSheetAnimation.numTilesX, 1f / _textureSheetAnimation.numTilesY); } return(true); }
protected bool Initialize() { if (_transform == null) { _transform = transform; } if (_pSystem == null) { _pSystem = GetComponent <ParticleSystem>(); if (_pSystem == null) { return(false); } } _pSystem.Simulate(0, true, true); _pRenderer = _pSystem.GetComponent <ParticleSystemRenderer>(); if (_pRenderer != null) { _pRenderer.enabled = false; } if (material == null) { var foundShader = Shader.Find("UI/Particles/Additive"); material = new Material(foundShader); } _mainModule = _pSystem.main; if (_pSystem.main.maxParticles > 14000) { _mainModule.maxParticles = 14000; } _currentMaterial = material; if (_pRenderer != null && _pRenderer.sharedMaterial.mainTexture != null) { _currentTexture = _pRenderer.sharedMaterial.mainTexture; } else if (_currentMaterial && _currentMaterial.HasProperty("_MainTex")) { _currentTexture = _currentMaterial.mainTexture; } if (_currentTexture == null) { _currentTexture = Texture2D.whiteTexture; } material = _currentMaterial; // automatically set scaling _mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; _particles = new ParticleSystem.Particle[_pSystem.main.maxParticles]; _imageUv = new Vector4(0, 0, 1, 1); // prepare texture sheet animation _textureSheetAnimation = _pSystem.textureSheetAnimation; _textureSheetAnimationFrames = 0; _textureSheetAnimationFrameSize = Vector2.zero; if (_textureSheetAnimation.enabled) { _textureSheetAnimationFrames = _textureSheetAnimation.numTilesX * _textureSheetAnimation.numTilesY; _textureSheetAnimationFrameSize = new Vector2(1f / _textureSheetAnimation.numTilesX, 1f / _textureSheetAnimation.numTilesY); } return(true); }
public void Initialize(AsteroidManager.AsteroidData asteroidData, int atlasIndex) { // get references billboardPS = GetComponent <ParticleSystem>(); this.asteroidData = asteroidData; this.atlasIndex = atlasIndex; // initialize the particle system settings ParticleSystem.MainModule main = billboardPS.main; main.maxParticles = maxActiveAsteroids; main.startLifetime = particleLifeTime; ParticleSystem.TextureSheetAnimationModule textureSheet = billboardPS.textureSheetAnimation; textureSheet.mode = ParticleSystemAnimationMode.Grid; textureSheet.rowMode = ParticleSystemAnimationRowMode.Custom; textureSheet.rowIndex = atlasIndex; if (AsteroidManager.instance.squareAtlas) { textureSheet.animation = ParticleSystemAnimationType.WholeSheet; textureSheet.numTilesX = AsteroidManager.altasSideSize; textureSheet.numTilesY = AsteroidManager.altasSideSize; } else { textureSheet.animation = ParticleSystemAnimationType.SingleRow; textureSheet.numTilesX = 1; textureSheet.numTilesY = AsteroidManager.altasSideSize; } //textureSheet.frameOverTimeMultiplier = AsteroidManager.altasTotalSize; // get the updated texture altas GetComponent <ParticleSystemRenderer>().sharedMaterial.mainTexture = AsteroidManager.instance.altasTexture; }
// random void SetSpriteInParticleSystem(int _mid = -1, int _gameMidsIndex = -1) { Debug.Log("SetRandomSpriteInParticleSystem() mid =" + mid); // choose random if (_mid < 1) { // sprites to choose from totalSprites = MonsterIndex.Instance.monstersFromSheetsDistinct.Length; // make sure its divisible by 3 spriteIndex = (int)Random.Range(0, totalSprites); while (spriteIndex % 3 != 0) { spriteIndex = (int)Random.Range(0, totalSprites); } } else { spriteIndex = _gameMidsIndex * 3; } // access particle system's TextureSheetAnimationModule ParticleSystem ps = GetComponent <ParticleSystem> (); ParticleSystem.TextureSheetAnimationModule tsam = ps.textureSheetAnimation; // SetSprite on the three tsam.SetSprite(0, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 0]); tsam.SetSprite(1, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 1]); tsam.SetSprite(2, MonsterIndex.Instance.monstersFromSheetsDistinct [spriteIndex + 2]); }
private void DrawParticleBillboard( ParticleSystem.Particle particle, VertexHelper vh, ParticleSystem.MinMaxCurve frameOverTime, ParticleSystem.MinMaxCurve velocityOverTimeX, ParticleSystem.MinMaxCurve velocityOverTimeY, ParticleSystem.MinMaxCurve velocityOverTimeZ, bool isWorldSimulationSpace, ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule) { var center = particle.position; var rotation = Quaternion.Euler(particle.rotation3D); if (isWorldSimulationSpace) { center = rectTransform.InverseTransformPoint(center); } float timeAlive = particle.startLifetime - particle.remainingLifetime; float globalTimeAlive = timeAlive / particle.startLifetime; Vector3 size3D = particle.GetCurrentSize3D(ParticleSystem); if (m_RenderMode == UiParticleRenderMode.StreachedBillboard) { GetStrechedBillboardsSizeAndRotation(particle, globalTimeAlive, ref size3D, out rotation, velocityOverTimeX, velocityOverTimeY, velocityOverTimeZ); } var leftTop = new Vector3(-size3D.x * 0.5f, size3D.y * 0.5f); var rightTop = new Vector3(size3D.x * 0.5f, size3D.y * 0.5f); var rightBottom = new Vector3(size3D.x * 0.5f, -size3D.y * 0.5f); var leftBottom = new Vector3(-size3D.x * 0.5f, -size3D.y * 0.5f); leftTop = rotation * leftTop + center; rightTop = rotation * rightTop + center; rightBottom = rotation * rightBottom + center; leftBottom = rotation * leftBottom + center; Color32 color32 = particle.GetCurrentColor(ParticleSystem); var i = vh.currentVertCount; Vector2 uv0; Vector2 uv1; Vector2 uv2; Vector2 uv3; CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv0, out uv1, out uv2, out uv3); vh.AddVert(leftBottom, color32, uv0); vh.AddVert(leftTop, color32, uv1); vh.AddVert(rightTop, color32, uv2); vh.AddVert(rightBottom, color32, uv3); vh.AddTriangle(i, i + 1, i + 2); vh.AddTriangle(i + 2, i + 3, i); }
private void DrawParticleMesh( ParticleSystem.Particle particle, VertexHelper vh, ParticleSystem.MinMaxCurve frameOverTime, bool isWorldSimulationSpace, ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule, Vector3[] verts, int[] triangles, Vector2[] uvs) { var center = particle.position; var rotation = Quaternion.Euler(particle.rotation3D); if (isWorldSimulationSpace) { center = rectTransform.InverseTransformPoint(center); } float timeAlive = particle.startLifetime - particle.remainingLifetime; float globalTimeAlive = timeAlive / particle.startLifetime; Vector3 size3D = particle.GetCurrentSize3D(ParticleSystem); Color32 color32 = particle.GetCurrentColor(ParticleSystem); Vector2 uv0; Vector2 uv1; Vector2 uv2; Vector2 uv3; CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv0, out uv1, out uv2, out uv3); var currentVertCount = vh.currentVertCount; for (int j = 0; j < verts.Length; j++) { Vector3 pos = verts[j]; pos.x *= size3D.x; pos.y *= size3D.y; pos.z *= size3D.z; pos = rotation * pos + center; var uvXpercent = uvs[j].x; var uvYpercent = uvs[j].y; var newUvx = Mathf.Lerp(uv0.x, uv2.x, uvXpercent); var newUvy = Mathf.Lerp(uv0.y, uv2.y, uvYpercent); vh.AddVert(pos, color32, new Vector2(newUvx, newUvy)); } for (int i = 0; i < triangles.Length; i += 3) { vh.AddTriangle(currentVertCount + triangles[i], currentVertCount + triangles[i + 1], currentVertCount + triangles[i + 2]); } }
public static void CopyTextureSheetAnimation(this ParticleSystem.TextureSheetAnimationModule self, TextureSheetAnimationTemplate other) { //turn the module on if the module is off self.enabled = other.enabled; self.numTilesX = other.tilesX; self.numTilesY = other.tilesY; self.flipU = other.flipU; self.flipV = other.flipV; }
private void TestSelection() { // Selection (accounts for transparency) if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (!Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit)) { return; } ParticleCollider hitParticleCollider = hit.transform.gameObject.GetComponent <ParticleCollider>(); if (hitParticleCollider != null) { Renderer rend = hit.transform.GetComponent <Renderer>(); MeshCollider meshCollider = hit.collider as MeshCollider; meshCollider.convex = false; if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null) { Debug.Log("HIT! " + hitParticleCollider.ParticleSys.name, this); return; } Texture2D tex = rend.material.mainTexture as Texture2D; Vector2 pixelUV = hit.textureCoord; // Apply texture sheet animation offset ParticleSystem.TextureSheetAnimationModule texModule = hitParticleCollider.ParticleSys.textureSheetAnimation; if (texModule.enabled) { SubUVTextureInfo subUV = new SubUVTextureInfo(texModule, hitParticleCollider.Particle); pixelUV.x = (subUV.currentColumn / subUV.columns) + (pixelUV.x / subUV.columns); pixelUV.y = (subUV.currentRow / subUV.rows) + ((1 - pixelUV.y) / subUV.rows); pixelUV.y = 1 - pixelUV.y; } pixelUV.x *= tex.width; pixelUV.y *= tex.height; Color hitColor = tex.GetPixelForced((int)pixelUV.x, (int)pixelUV.y); Debug.Log("Raycast hit color: " + hitColor, this); if (debugImg != null) { debugImg.color = hitColor; } if (hitColor.a > hitTestAlphaCutoff) { Debug.Log("HIT! " + hitParticleCollider.ParticleSys.name, this); } } } }
public void Destroy(bool particle = true) { if (particle) { ParticleSystem explosion = Instantiate(this.explosionParticle, this.transform.position, this.explosionParticle.transform.rotation); ParticleSystem.TextureSheetAnimationModule sheetAnimation = explosion.textureSheetAnimation; sheetAnimation.SetSprite(0, this.spriteRenderer.sprite); GameManager.Instance.PlaySound(this.explosionSound, 0.1f); } SpawnerManager.Instance.DestroyMeteor(this); }
public void EmitAtPosition(ParticleTemplate template) { ParticleSystem system = library.GetParticleSystemFromName(template.systemName); if (system == null) { return; } var emitParams = new ParticleSystem.EmitParams(); if (template.emitParams.enabled) { emitParams.position = template.emitParams.position + template.emitParams.positionOffset; emitParams.rotation = template.emitParams.rotation + template.emitParams.rotationOffset; emitParams.rotation3D = template.emitParams.rotation3D + template.emitParams.rotation3DOffset; if (template.emitParams.startSize >= 0) { emitParams.startSize = template.emitParams.startSize; } else { emitParams.startSize3D = template.emitParams.startSize3D; } emitParams.startLifetime = template.emitParams.startLifetime; emitParams.startColor = template.emitParams.startColor; emitParams.velocity = template.emitParams.velocity.ComponentMultiply(template.emitParams.velocityMultiplier); emitParams.applyShapeToPosition = template.emitParams.applyShapeToPosition; } if (template.shape.enabled) { ParticleSystem.ShapeModule shape = system.shape; shape.CopyShape(template.shape); } if (template.colorOverLifetime.enabled) { ParticleSystem.ColorOverLifetimeModule colorOverLifetime = system.colorOverLifetime; colorOverLifetime.CopyColorOverLifeTime(template.colorOverLifetime); } if (template.textureSheetAnimation.enabled) { ParticleSystem.TextureSheetAnimationModule textureSheetAnimation = system.textureSheetAnimation; textureSheetAnimation.CopyTextureSheetAnimation(template.textureSheetAnimation); } system.Emit(emitParams, template.numberOfParticles); }
public override void GetDepsFrom(object obj, GetDepsFromContext context) { base.GetDepsFrom(obj, context); if (obj == null) { return; } ParticleSystem.TextureSheetAnimationModule o = (ParticleSystem.TextureSheetAnimationModule)obj; for (int i = 0; i < o.spriteCount; ++i) { AddDep(o.GetSprite(i), context); } }
void Start() { groundCheck = transform.GetChild(0); body = GetComponent <Rigidbody2D>(); col = GetComponent <Collider2D>(); noteAnim = noteFX.textureSheetAnimation; groundCheckRadius = transform.GetChild(0).GetComponent <CircleCollider2D>().radius;// 0.22f; climbFixLayer = LayerMask.NameToLayer("Blockable"); playerLayer = LayerMask.NameToLayer("Player"); items = new int[System.Enum.GetNames(typeof(ItemType)).Length]; currentRespawnOrder = -1; respawnLocation = startSpawn.transform; defaultMat = Resources.Load("Materials/Default") as PhysicsMaterial2D; fullFriction = Resources.Load("Materials/FullFriction") as PhysicsMaterial2D; noFriction = Resources.Load("Materials/NoFriction") as PhysicsMaterial2D; body.sharedMaterial = defaultMat; melodyData.Start(); spriteRenderer = GetComponent <SpriteRenderer>(); anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody2D>(); controller = GetComponent <StateController>(); melodyData.MelodyRange = transform.Find("MelodyRange").GetComponent <CircleCollider2D>(); songSheet.SetActive(false); // Statics GameManager.instance.player = this; hitInvincibilityTimer = new Timer(hitInvincibilityDuration); hitInvincibilityTimer.Start(); hitInvincibilityTimer.InstantFinish(); if (Input.GetJoystickNames() != null) { gamepadConnected = true; } axisSensitivity = 0.75f; hasKey = false; hasReadNote = false; audioData = new PlayerAudioData(); }
public SubUVTextureInfo(ParticleSystem.TextureSheetAnimationModule texModule, ParticleSystem.Particle curParticle) { columns = texModule.numTilesX; rows = texModule.numTilesY; totalFrames = columns * rows; float curParticleLifeNormalized = (curParticle.startLifetime - curParticle.remainingLifetime) / curParticle.startLifetime; float startFrame = texModule.startFrame.Evaluate(curParticleLifeNormalized); // TODO: might be particleSys.time and might need Mathf.Floor() float animation = texModule.frameOverTime.Evaluate(curParticleLifeNormalized); currentFrame = startFrame + Mathf.Floor(animation * totalFrames); currentColumn = currentFrame % columns; currentRow = Mathf.Floor(currentFrame / columns); }
public override void ReadFrom(object obj) { base.ReadFrom(obj); if (obj == null) { return; } ParticleSystem.TextureSheetAnimationModule o = (ParticleSystem.TextureSheetAnimationModule)obj; m_sprites = new TID[o.spriteCount]; for (int i = 0; i < o.spriteCount; ++i) { m_sprites[i] = ToID(o.GetSprite(i)); } }
private void DrawParticleMesh(ParticleSystem.Particle particle, VertexHelper vh, ParticleSystem.MinMaxCurve frameOverTime, bool isWorldSimulationSpace, ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule, Vector3[] verts, int[] triangles, Vector2[] uvs) { var center = particle.position; var rotation = Quaternion.Euler(particle.rotation3D); if (isWorldSimulationSpace) { center = rectTransform.InverseTransformPoint(center); } float timeAlive = particle.startLifetime - particle.remainingLifetime; Vector3 size3D = particle.GetCurrentSize3D(Particle); Color32 color32 = particle.GetCurrentColor(Particle); CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv4[0], out uv4[1], out uv4[2], out uv4[3]); int count = vh.currentVertCount; Vector3 position; Vector2 point = new Vector2(); for (int j = 0; j < verts.Length; j++) { position = verts[j]; position.x *= size3D.x; position.y *= size3D.y; position.z *= size3D.z; position = rotation * position + center; point.x = Mathf.Lerp(uv4[0].x, uv4[2].x, uvs[j].x); point.y = Mathf.Lerp(uv4[0].y, uv4[2].y, uvs[j].y); vh.AddVert(position, color32, point); } for (int i = 0; i < triangles.Length; i += 3) { vh.AddTriangle(count + triangles[i], count + triangles[i + 1], count + triangles[i + 2]); } }
public void RefreshParticleSystem() { ParticleSystem ps = gameObject.GetComponent <ParticleSystem>(); if (ps == null) { Debug.LogError("No ParticleSystem"); return; } if (mAtlas == null) { return; } UISpriteData sp = mAtlas.GetSprite(mSpriteName); if (sp == null) { Debug.LogErrorFormat("物体'{0}'引用图元'{1}'没有找到", gameObject.name, mSpriteName); return; } mSprite = sp; int x = mSprite.x; int y = mSprite.y; int width = mSprite.width; int height = mSprite.height; int bigWidth = mAtlas.texture.width; int bigHeight = mAtlas.texture.height; int numInLine = bigWidth / width; index = (y / height) * numInLine + x / width; int numInHeight = bigHeight / height; int num = numInHeight * numInLine; ParticleSystem.TextureSheetAnimationModule tsa = ps.textureSheetAnimation; tsa.enabled = true; tsa.mode = ParticleSystemAnimationMode.Grid; tsa.animation = ParticleSystemAnimationType.WholeSheet; tsa.numTilesX = numInLine; tsa.numTilesY = numInHeight; var frameOverTimeCurve = tsa.frameOverTime; frameOverTimeCurve.mode = ParticleSystemCurveMode.Constant; frameOverTimeCurve.constant = (float)index / (float)(num); tsa.frameOverTime = frameOverTimeCurve; }
private static bool checkAniModuel(ParticleSystem.TextureSheetAnimationModule texAni, string prefabName, string objName) { if (false == texAni.enabled) { return(true); } else { if (texAni.startFrame.mode == ParticleSystemCurveMode.Constant && 0 == texAni.startFrame.constant) { if (texAni.frameOverTime.mode == ParticleSystemCurveMode.Constant) { if (texAni.animation == ParticleSystemAnimationType.SingleRow) { if (texAni.useRandomRow == false) { return(true); } } else if (texAni.animation == ParticleSystemAnimationType.WholeSheet) { return(true); } } else if (texAni.frameOverTime.mode == ParticleSystemCurveMode.Curve) { if (texAni.animation == ParticleSystemAnimationType.WholeSheet) { return(true); } } } } //Debug.LogError("AniModuel invalid! " // + "\n" + prefabName + " " + objName // + "\n" + texAni.frameOverTime.mode.ToString() // + "\n" + texAni.animation // + "\nRandomRow " + texAni.useRandomRow // + "\nstartFrameMode " + texAni.startFrame.mode // + "\nstartFrame " + texAni.startFrame.constant // ); return(false); }
private void RotateAnimation(GameObject go, string side) { Vector3 localPosition = go.transform.localPosition; if (side.ToLower() == "left") { if (localPosition.x > 0f) { localPosition.x = -1f * localPosition.x; } go.transform.localRotation = Quaternion.Euler(180f, 0f, 0f); if (go.name.ToLower().Contains("gull") || go.name.ToLower().Contains("bird")) { //go.GetComponent<ParticleSystem>().textureSheetAnimation.flipV = 1f; ParticleSystem.TextureSheetAnimationModule module = go.GetComponent <ParticleSystem>().textureSheetAnimation; module.flipV = 1; } if (go.name.ToLower().Contains("fog") || go.name.ToLower().Contains("cloud") || go.name.ToLower().Contains("sand")) { go.transform.localRotation = Quaternion.Euler(0f, 105f, 0f); } go.transform.localPosition = localPosition; } else if (side == "right") { if (localPosition.x < 0f) { localPosition.x = -1f * localPosition.x; } go.transform.localRotation = Quaternion.Euler(180f, 0f, 180f); if (go.name.ToLower().Contains("gull") || go.name.ToLower().Contains("bird")) { //go.GetComponent<ParticleSystem>().textureSheetAnimation.flipV = 0f; ParticleSystem.TextureSheetAnimationModule module = go.GetComponent <ParticleSystem>().textureSheetAnimation; module.flipV = 0; } if (go.name.ToLower().Contains("fog") || go.name.ToLower().Contains("cloud") || go.name.ToLower().Contains("sand")) { go.transform.localRotation = Quaternion.Euler(180f, 80f, 0f); } go.transform.localPosition = localPosition; } }
/// <summary> /// 纹理信息获取之后,处理帧动画数据 /// 只支持匀速播放 /// </summary> /// <param name="data"></param> private void WriteTextureSheetAnimation(ParticleSystem.TextureSheetAnimationModule data) { if (data.enabled) { texWidth = renderer.sharedMaterial.mainTexture.width; texHeight = renderer.sharedMaterial.mainTexture.height; CommaNL(); Indent(); jsonWriter.Write("\"texSheeetAnim\":{\n"); IndentIn(); CommaNL(); Indent(); jsonWriter.Write("\"cellWidth\":" + texWidth / data.numTilesX); CommaNL(); Indent(); jsonWriter.Write("\"cellHeight\":" + texHeight / data.numTilesY); if (data.startFrame.mode == ParticleSystemCurveMode.TwoConstants) { CommaNL(); Indent(); jsonWriter.Write("\"cellStartID\":" + data.startFrame.constantMin); CommaNL(); Indent(); jsonWriter.Write("\"cellEndID\":" + data.startFrame.constantMax); } else { CommaNL(); Indent(); jsonWriter.Write("\"cellStartID\":" + data.startFrame.constant); CommaNL(); Indent(); jsonWriter.Write("\"cellEndID\":" + (data.numTilesX * data.numTilesY - 1)); }; CommaNL(); Indent(); jsonWriter.Write("\"cellChangeSpeed\":" + data.cycleCount); jsonWriter.Write("\n"); IndentOut(); Indent(); jsonWriter.Write("}"); } }
protected override void ReadFromImpl(object obj) { base.ReadFromImpl(obj); ParticleSystem.TextureSheetAnimationModule uo = (ParticleSystem.TextureSheetAnimationModule)obj; enabled = uo.enabled; mode = uo.mode; numTilesX = uo.numTilesX; numTilesY = uo.numTilesY; animation = uo.animation; frameOverTime = uo.frameOverTime; frameOverTimeMultiplier = uo.frameOverTimeMultiplier; startFrame = uo.startFrame; startFrameMultiplier = uo.startFrameMultiplier; cycleCount = uo.cycleCount; rowIndex = uo.rowIndex; uvChannelMask = uo.uvChannelMask; timeMode = uo.timeMode; fps = uo.fps; speedRange = uo.speedRange; rowMode = uo.rowMode; }
protected override object WriteToImpl(object obj) { obj = base.WriteToImpl(obj); ParticleSystem.TextureSheetAnimationModule uo = (ParticleSystem.TextureSheetAnimationModule)obj; uo.enabled = enabled; uo.mode = mode; uo.numTilesX = numTilesX; uo.numTilesY = numTilesY; uo.animation = animation; uo.frameOverTime = frameOverTime; uo.frameOverTimeMultiplier = frameOverTimeMultiplier; uo.startFrame = startFrame; uo.startFrameMultiplier = startFrameMultiplier; uo.cycleCount = cycleCount; uo.rowIndex = rowIndex; uo.uvChannelMask = uvChannelMask; uo.timeMode = timeMode; uo.fps = fps; uo.speedRange = speedRange; uo.rowMode = rowMode; return(uo); }
private void CopyParticle(ParticleSystem part, ParticleSystem newPart) { ParticleSystem.MainModule main = part.main; main.duration = newPart.main.duration; main.startLifetime = newPart.main.startLifetime; main.startSpeed = newPart.main.startSpeed; main.startSize = newPart.main.startSize; main.startColor = newPart.main.startColor; ParticleSystem.EmissionModule emis = part.emission; emis.rateOverTime = newPart.emission.rateOverTime; emis.rateOverDistance = newPart.emission.rateOverDistance; emis.burstCount = newPart.emission.burstCount; emis.SetBurst(0, newPart.emission.GetBurst(0)); ParticleSystem.ShapeModule shape = part.shape; shape.shapeType = newPart.shape.shapeType; shape.radius = newPart.shape.radius; shape.radiusThickness = newPart.shape.radiusThickness; shape.arc = newPart.shape.arc; shape.arcMode = newPart.shape.arcMode; shape.arcSpeed = newPart.shape.arcSpeed; shape.position = newPart.shape.position; shape.rotation = newPart.shape.rotation; ParticleSystem.RotationOverLifetimeModule rot = part.rotationOverLifetime; rot.enabled = newPart.rotationOverLifetime.enabled; rot.z = newPart.rotationOverLifetime.z; ParticleSystem.TextureSheetAnimationModule tex = part.textureSheetAnimation; tex.enabled = newPart.textureSheetAnimation.enabled; if (tex.enabled) { tex.mode = newPart.textureSheetAnimation.mode; tex.SetSprite(0, newPart.textureSheetAnimation.GetSprite(0)); } ParticleSystem.SubEmittersModule sub = part.subEmitters; sub.enabled = newPart.subEmitters.enabled; if (sub.enabled) { sub.AddSubEmitter(newPart.subEmitters.GetSubEmitterSystem(0), newPart.subEmitters.GetSubEmitterType(0), newPart.subEmitters.GetSubEmitterProperties(0)); } }
private void Initialize() { if (initialized) { return; } var particleSystem = GetParticleSystem(); var mainModule = GetMainModule(); // limit max particles. mainModule.maxParticles = Mathf.Clamp(mainModule.maxParticles, 0, 10000); // automatically set scaling. mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; particles = new ParticleSystem.Particle[particleSystem.main.maxParticles]; // prepare texture sheet animation. textureSheetAnimation = particleSystem.textureSheetAnimation; textureSheetAnimationFrames = 0; textureSheetAnimationFrameSize = Vector2.zero; if (textureSheetAnimation.enabled) { textureSheetAnimationFrames = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY; textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY); } raycastTarget = false; // desable particle renderer. var particleSystemRenderer = GetParticleSystemRenderer(); particleSystemRenderer.enabled = false; initialized = true; }
public override object WriteTo(object obj) { obj = base.WriteTo(obj); if (obj == null) { return(null); } ParticleSystem.TextureSheetAnimationModule o = (ParticleSystem.TextureSheetAnimationModule)obj; if (m_sprites != null) { for (int i = 0; i < m_sprites.Length; ++i) { Sprite sprite = FromID <Sprite>(m_sprites[i]); if (sprite != null) { o.AddSprite(sprite); } } } return(obj); }
private void MapTextureSheetAnimationParameters(ParticleSystem pSystem, int i) { ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule = pSystem.textureSheetAnimation; try { textureSheetAnimationModule.enabled = GetBoolParam(i, "textureSheetAnimation_enabled"); } catch (NullReferenceException) { textureSheetAnimationModule.enabled = false; return; } textureSheetAnimationModule.mode = (ParticleSystemAnimationMode)GetIntParam(i, "textureSheetAnimation_mode"); textureSheetAnimationModule.animation = (ParticleSystemAnimationType)GetIntParam(i, "textureSheetAnimation_animation"); textureSheetAnimationModule.numTilesX = (int)GetVectorParam(i, "textureSheetAnimation_tiles")[0]; textureSheetAnimationModule.numTilesY = (int)GetVectorParam(i, "textureSheetAnimation_tiles")[1]; textureSheetAnimationModule.enabled = GetBoolParam(i, "textureSheetAnimation_enabled"); textureSheetAnimationModule.cycleCount = GetIntParam(i, "textureSheetAnimation_cycles"); textureSheetAnimationModule.flipU = GetFloatParam(i, "textureSheetAnimation_flipU"); textureSheetAnimationModule.flipV = GetFloatParam(i, "textureSheetAnimation_flipV"); textureSheetAnimationModule.frameOverTime = NodeFXUtilities.InterpretStringToCurve(GetStringParam(i, "textureSheetAnimation_frame")); textureSheetAnimationModule.startFrame = NodeFXUtilities.InterpretStringToCurve(GetStringParam(i, "textureSheetAnimation_startFrame")); }
static void WriteParticleSystemTextureSheetAnimation(ParticleSystem.TextureSheetAnimationModule module) { m_writer.Write(module.enabled); if (!module.enabled) { return; } m_writer.Write(module.numTilesX); m_writer.Write(module.numTilesY); m_writer.Write((int)module.animation); if (module.animation == ParticleSystemAnimationType.SingleRow) { m_writer.Write(module.useRandomRow); m_writer.Write(module.rowIndex); } WriteMinMaxCurve(module.frameOverTime); WriteMinMaxCurve(module.startFrame); m_writer.Write(module.cycleCount); m_writer.Write(module.flipU); m_writer.Write(module.flipV); m_writer.Write((int)module.uvChannelMask); }
protected bool Initialize() { // initialize members if (_transform == null) { _transform = transform; } if (pSystem == null) { pSystem = GetComponent <ParticleSystem>(); if (pSystem == null) { return(false); } #if UNITY_5_5_OR_NEWER mainModule = pSystem.main; if (pSystem.main.maxParticles > 14000) { mainModule.maxParticles = 14000; } #else if (pSystem.maxParticles > 14000) { pSystem.maxParticles = 14000; } #endif pRenderer = pSystem.GetComponent <ParticleSystemRenderer>(); if (pRenderer != null) { pRenderer.enabled = false; } if (material == null) { var foundShader = Shader.Find("UI Extensions/Particles/Additive"); if (foundShader) { material = new Material(foundShader); } } currentMaterial = material; if (currentMaterial && currentMaterial.HasProperty("_MainTex")) { currentTexture = currentMaterial.mainTexture; if (currentTexture == null) { currentTexture = Texture2D.whiteTexture; } } material = currentMaterial; // automatically set scaling #if UNITY_5_5_OR_NEWER mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; #else pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; #endif particles = null; } #if UNITY_5_5_OR_NEWER if (particles == null) { particles = new ParticleSystem.Particle[pSystem.main.maxParticles]; } #else if (particles == null) { particles = new ParticleSystem.Particle[pSystem.maxParticles]; } #endif imageUV = new Vector4(0, 0, 1, 1); // prepare texture sheet animation textureSheetAnimation = pSystem.textureSheetAnimation; textureSheetAnimationFrames = 0; textureSheetAnimationFrameSize = Vector2.zero; if (textureSheetAnimation.enabled) { textureSheetAnimationFrames = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY; textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY); } return(true); }
private static void CalculateUvs(ParticleSystem.Particle particle, ParticleSystem.MinMaxCurve frameOverTime, ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule, float timeAlive, out Vector2 uv0, out Vector2 uv1, out Vector2 uv2, out Vector2 uv3) { if (!textureSheetAnimationModule.enabled) { uv0 = new Vector2(0f, 0f); uv1 = new Vector2(0f, 1f); uv2 = new Vector2(1f, 1f); uv3 = new Vector2(1f, 0f); } else { float lifeTimePerCycle = particle.startLifetime / textureSheetAnimationModule.cycleCount; float timePerCycle = timeAlive % lifeTimePerCycle; float timeAliveAnim01 = timePerCycle / lifeTimePerCycle; // in percents var totalFramesCount = textureSheetAnimationModule.numTilesY * textureSheetAnimationModule.numTilesX; var frame01 = frameOverTime.Evaluate(timeAliveAnim01); var frame = 0f; switch (textureSheetAnimationModule.animation) { case ParticleSystemAnimationType.WholeSheet: { frame = Mathf.Clamp(Mathf.Floor(frame01 * totalFramesCount), 0, totalFramesCount - 1); break; } case ParticleSystemAnimationType.SingleRow: { frame = Mathf.Clamp(Mathf.Floor(frame01 * textureSheetAnimationModule.numTilesX), 0, textureSheetAnimationModule.numTilesX - 1); int row = textureSheetAnimationModule.rowIndex; if (textureSheetAnimationModule.useRandomRow) { Random.InitState((int)particle.randomSeed); row = Random.Range(0, textureSheetAnimationModule.numTilesY); } frame += row * textureSheetAnimationModule.numTilesX; break; } } int x = (int)frame % textureSheetAnimationModule.numTilesX; int y = (int)frame / textureSheetAnimationModule.numTilesX; var xDelta = 1f / textureSheetAnimationModule.numTilesX; var yDelta = 1f / textureSheetAnimationModule.numTilesY; y = textureSheetAnimationModule.numTilesY - 1 - y; var sX = x * xDelta; var sY = y * yDelta; var eX = sX + xDelta; var eY = sY + yDelta; uv0 = new Vector2(sX, sY); uv1 = new Vector2(sX, eY); uv2 = new Vector2(eX, eY); uv3 = new Vector2(eX, sY); } }
protected bool Initialize() { // initialize members if (_transform == null) { _transform = transform; } if (_particleSystem == null) { _particleSystem = GetComponent<ParticleSystem>(); if (_particleSystem == null) { return false; } // automatically set material to UI/Particles/Hidden shader, and get previous texture ParticleSystemRenderer renderer = _particleSystem.GetComponent<ParticleSystemRenderer>(); if (renderer == null) { renderer = _particleSystem.gameObject.AddComponent<ParticleSystemRenderer>(); } Material currentMaterial = renderer.sharedMaterial; if (currentMaterial && currentMaterial.HasProperty("_MainTex")) { particleTexture = currentMaterial.mainTexture; } Material material = new Material(Shader.Find("UI/Particles/Hidden")); // TODO - You should create this discard shader if (Application.isPlaying) { renderer.material = material; } #if UNITY_EDITOR else { material.hideFlags = HideFlags.DontSave; renderer.sharedMaterial = material; } #endif // automatically set scaling _particleSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; _particles = null; } if (_particles == null) { _particles = new ParticleSystem.Particle[_particleSystem.maxParticles]; } // prepare uvs if (particleTexture) { _uv = new Vector4(0, 0, 1, 1); } else if (particleSprite) { _uv = UnityEngine.Sprites.DataUtility.GetOuterUV(particleSprite); } // prepare texture sheet animation _textureSheetAnimation = _particleSystem.textureSheetAnimation; _textureSheetAnimationFrames = 0; _textureSheedAnimationFrameSize = Vector2.zero; if (_textureSheetAnimation.enabled) { _textureSheetAnimationFrames = _textureSheetAnimation.numTilesX * _textureSheetAnimation.numTilesY; _textureSheedAnimationFrameSize = new Vector2(1f / _textureSheetAnimation.numTilesX, 1f / _textureSheetAnimation.numTilesY); } return true; }