// public void InstantiateParticle (PARTICLE_TYPE type, Vector3 position, float waitTime = 0f) // { // if (PhotonNetwork.offlineMode) // StartCoroutine (IEInstantiateParticle (type, position, waitTime)); // else { // _pv.RPC ("RPCInstantiateParticle", PhotonTargets.All, type, position, waitTime); // } // } // // [PunRPC] // void RPCInstantiateParticle (PARTICLE_TYPE type, Vector3 position, float waitTime = 0f) // { // StartCoroutine (IEInstantiateParticle (type, position, waitTime)); // } // // IEnumerator IEInstantiateParticle (PARTICLE_TYPE type, Vector3 position, float waitTime = 0f) // { // yield return new WaitForSeconds (waitTime); // //// if (_particlePrefab) { // foreach (var p in _particles) { // if (p.TYPE == type) { // GameObject particleInstance = (GameObject)Instantiate (p.Prefab); // particleInstance.transform.position = position; // yield break; // } // } // // Debug.Log ("Particle type not found"); //// } // } public void InstantiateParticle(PARTICLE_TYPE type, Vector3 position, float waitTime = 0f, float duration = 0f, Transform followTarget = null) { if (PhotonNetwork.offlineMode) { StartCoroutine(IEInstantiateParticle(type, position, waitTime, duration, followTarget)); } else { _pv.RPC("RPCInstantiateParticle", PhotonTargets.All, type, position, waitTime, duration, followTarget); } }
ParticleSystem MakeNewParticle(PARTICLE_TYPE particleType) { var newParticleObj = Instantiate(particlePrefabs[particleType.ToString()]); //이름으로 종류를 구분하므로 이름셋팅 newParticleObj.name = particleType.ToString(); //풀에 등록 var newParticle = newParticleObj.GetComponent <ParticleSystem>(); particlePool.Add(newParticle); return(newParticle); }
ParticleSystem GetParticleFromPool(PARTICLE_TYPE particleType) { //풀에서 파티클을 가져온다 for (int i = 0; i < particlePool.Count; i++) { if (particlePool[i].isPlaying == false && particlePool[i].gameObject.name == particleType.ToString()) { return(particlePool[i]); } } //풀에서 재생가능한 파티클을 찾지 못했으면 새로 할당한다 return(MakeNewParticle(particleType)); }
void AddParticle(PARTICLE_TYPE pt, int x, int y) { int id = UnityEngine.Random.Range(1, int.MaxValue); Vector3 position = new Vector3(x, y, 0); ParticleProperties pp = GetProperties(pt); ParticleData data = new ParticleData { id = id, position = position, color = pp.color, properties = pp.properties }; particleData.Add(id, data); ids.Add(id); }
IEnumerator IEInstantiateParticle(PARTICLE_TYPE type, Vector3 position, float waitTime = 0f, float duration = 0f, Transform followTarget = null) { yield return(new WaitForSeconds(waitTime)); // if (_particlePrefab) { GameObject particleInstance = null; foreach (var p in _particles) { if (p.TYPE == type) { particleInstance = (GameObject)Instantiate(p.Prefab); particleInstance.transform.position = position; // if (followTarget != null) { // particleInstance.transform.SetParent (followTarget); // } break; } } if (particleInstance == null) { Debug.Log("Particle type not found"); } else { float timer = Time.time + duration; while (timer > Time.time) { particleInstance.transform.position = followTarget.position; Destroy(particleInstance, duration); yield return(null); } } // } }
ParticleProperties GetProperties(PARTICLE_TYPE pt) { Color color = new Color(1, 0, 0, 1); // Grav + (Solid|0, Liquid|2, Gas|4, Plasma|6) + ... // 1 + (2 + 4) + 8 int properties = 0; switch (pt) { case PARTICLE_TYPE.SAND: color = new Color(1, .99f, .86f, 1); properties = 1 + 0; break; case PARTICLE_TYPE.WATER: color = new Color(.1f, .1f, 1, 1); properties = 1 + 2; break; case PARTICLE_TYPE.FIRE: color = new Color(.82f, 0, .11f, 1); properties = 1 + 4; break; case PARTICLE_TYPE.WALL: color = new Color(1, 0, 1, 1); properties = 0 + 0; break; } return(new ParticleProperties { color = color, properties = properties }); }
public void Play(PARTICLE_TYPE pType, Vector3 position) { ParticleSystem ps = GetParticle(pType); Play(ps, position); }
public ParticleSystem GetParticle(PARTICLE_TYPE pType) { return(GetParticleFromPool(pType)); }
void RPCInstantiateParticle(PARTICLE_TYPE type, Vector3 position, float waitTime = 0f, float duration = 0f, Transform followTarget = null) { StartCoroutine(IEInstantiateParticle(type, position, waitTime, duration, followTarget)); }
public ParticleEmitter2(BinaryReader br) { TotalSize = br.ReadUInt32(); long end = br.BaseStream.Position + TotalSize; ObjSize = br.ReadUInt32(); Name = br.ReadCString(Constants.SizeName); ObjectId = br.ReadInt32(); ParentId = br.ReadInt32(); Flags = (GENOBJECTFLAGS)br.ReadUInt32(); LoadTracks(br); NodeSize = br.ReadInt32(); Type = (PARTICLE_EMITTER_TYPE)br.ReadInt32(); Speed = br.ReadSingle(); Variation = br.ReadSingle(); Latitude = br.ReadSingle(); Longitude = br.ReadSingle(); Gravity = br.ReadSingle(); ZSource = br.ReadSingle(); Lifespan = br.ReadSingle(); EmissionRate = br.ReadSingle(); Length = br.ReadSingle(); Width = br.ReadSingle(); Rows = br.ReadInt32(); Cols = br.ReadInt32(); ParticleType = (PARTICLE_TYPE)br.ReadInt32(); if (ParticleType > 0 && !Enum.IsDefined(typeof(PARTICLE_TYPE), ParticleType)) { throw new Exception("Unknown PARTICLE_TYPE"); } TailLength = br.ReadSingle(); MiddleTime = br.ReadSingle(); StartColor = new CVector3(br); MiddleColor = new CVector3(br); EndColor = new CVector3(br); StartAlpha = br.ReadByte() / 255f; MiddleAlpha = br.ReadByte() / 255f; EndAlpha = br.ReadByte() / 255f; StartScale = br.ReadSingle(); MiddleScale = br.ReadSingle(); EndScale = br.ReadSingle(); LifespanUVAnimStart = br.ReadUInt32(); LifespanUVAnimEnd = br.ReadUInt32(); LifespanUVAnimRepeat = br.ReadUInt32(); DecayUVAnimStart = br.ReadUInt32(); DecayUVAnimEnd = br.ReadUInt32(); DecayUVAnimRepeat = br.ReadUInt32(); TailUVAnimStart = br.ReadUInt32(); TailUVAnimEnd = br.ReadUInt32(); TailUVAnimRepeat = br.ReadUInt32(); TailDecayUVAnimStart = br.ReadUInt32(); TailDecayUVAnimEnd = br.ReadUInt32(); TailDecayUVAnimRepeat = br.ReadUInt32(); BlendMode = (PARTICLE_BLEND_MODE)br.ReadUInt32(); TextureId = br.ReadUInt32(); PriorityPlane = br.ReadInt32(); ReplaceableId = br.ReadUInt32(); GeometryMdl = br.ReadCString(Constants.SizeFileName); RecursionMdl = br.ReadCString(Constants.SizeFileName); TwinkleFPS = br.ReadSingle(); TwinkleOnOff = br.ReadSingle(); TwinkleScaleMin = br.ReadSingle(); TwinkleScaleMax = br.ReadSingle(); IvelScale = br.ReadSingle(); TumbleX = new CVector2(br); TumbleY = new CVector2(br); TumbleZ = new CVector2(br); Drag = br.ReadSingle(); Spin = br.ReadSingle(); WindVector = new CVector3(br); WindTime = br.ReadSingle(); FollowSpeed1 = br.ReadSingle(); FollowScale1 = br.ReadSingle(); FollowSpeed2 = br.ReadSingle(); FollowScale2 = br.ReadSingle(); NrOfSplines = br.ReadInt32(); for (int i = 0; i < NrOfSplines; i++) { Splines.Add(new CVector3(br)); } Squirts = br.ReadUInt32(); // 1 for footsteps and impact spell effects while (br.BaseStream.Position < end && !br.AtEnd()) { string tagname = br.ReadString(4); switch (tagname) { case "KP2S": SpeedKeys = new Track <float>(br); break; case "KP2R": VariationKeys = new Track <float>(br); break; case "KP2G": GravityKeys = new Track <float>(br); break; case "KP2W": WidthKeys = new Track <float>(br); break; case "KP2N": LengthKeys = new Track <float>(br); break; case "KVIS": VisibilityKeys = new Track <float>(br); break; case "KP2E": EmissionRateKeys = new Track <float>(br); break; case "KP2L": LatitudeKeys = new Track <float>(br); break; case "KLIF": LifespanKeys = new Track <float>(br); break; case "KPLN": LongitudeKeys = new Track <float>(br); break; case "KP2Z": ZSourceKeys = new Track <float>(br); break; default: br.BaseStream.Position -= 4; return; } } }
public ParticleEmitter2(BinaryReader br) { long end = br.BaseStream.Position + (TotalSize = br.ReadUInt32()); ObjSize = br.ReadUInt32(); Name = br.ReadCString(Constants.SizeName); ObjectId = br.ReadInt32(); ParentId = br.ReadInt32(); Flags = (GENOBJECTFLAGS)br.ReadUInt32(); LoadTracks(br); Speed = br.ReadSingle(); Variation = br.ReadSingle(); Latitude = br.ReadSingle(); Gravity = br.ReadSingle(); Lifespan = br.ReadSingle(); EmissionRate = br.ReadSingle(); Length = br.ReadSingle(); Width = br.ReadSingle(); BlendMode = (PARTICLE_BLEND_MODE)br.ReadUInt32(); Rows = br.ReadInt32(); Cols = br.ReadInt32(); ParticleType = (PARTICLE_TYPE)br.ReadInt32(); TailLength = br.ReadSingle(); MiddleTime = br.ReadSingle(); StartColor = new CVector3(br); MiddleColor = new CVector3(br); EndColor = new CVector3(br); StartAlpha = br.ReadByte() / 255f; MiddleAlpha = br.ReadByte() / 255f; EndAlpha = br.ReadByte() / 255f; StartScale = br.ReadSingle(); MiddleScale = br.ReadSingle(); EndScale = br.ReadSingle(); LifespanUVAnimStart = br.ReadUInt32(); LifespanUVAnimEnd = br.ReadUInt32(); LifespanUVAnimRepeat = br.ReadUInt32(); DecayUVAnimStart = br.ReadUInt32(); DecayUVAnimEnd = br.ReadUInt32(); DecayUVAnimRepeat = br.ReadUInt32(); TailUVAnimStart = br.ReadUInt32(); TailUVAnimEnd = br.ReadUInt32(); TailUVAnimRepeat = br.ReadUInt32(); TailDecayUVAnimStart = br.ReadUInt32(); TailDecayUVAnimEnd = br.ReadUInt32(); TailDecayUVAnimRepeat = br.ReadUInt32(); TextureId = br.ReadUInt32(); Squirts = br.ReadUInt32(); // 1 for footsteps and impact spell effects PriorityPlane = br.ReadInt32(); ReplaceableId = br.ReadUInt32(); while (br.BaseStream.Position < end && !br.AtEnd()) { string tagname = br.ReadString(4); switch (tagname) { case "KP2S": SpeedKeys = new Track <float>(br); break; case "KP2R": VariationKeys = new Track <float>(br); break; case "KP2G": GravityKeys = new Track <float>(br); break; case "KP2W": WidthKeys = new Track <float>(br); break; case "KP2N": LengthKeys = new Track <float>(br); break; case "KP2V": VisibilityKeys = new Track <float>(br); break; case "KP2E": EmissionRateKeys = new Track <float>(br); break; case "KP2L": LatitudeKeys = new Track <float>(br); break; default: br.BaseStream.Position -= 4; return; } } }