Ejemplo n.º 1
0
    IEnumerator EmitSwordEffectParticles()
    {
        Vector3 pos = transform.position;
        Vector3 movement = pos - lastPos;
        float movementSpeed = movement.magnitude;
        lastPos = pos;

        float particlesPerSecond = movementSpeed * 25f;

        if (movementSpeed != 0)
            elapsedTime += Time.deltaTime;

        if (ps != null)
        {
            while (elapsedTime > 1f / particlesPerSecond)
            {
                ps.Emit(1); //view overloads
                elapsedTime -= 1f / particlesPerSecond;
            }

            Particle[] particles = new Particle[ps.particleCount];
            ps.GetParticles(particles);
            //Debug.Log(particles.Length);
            for (int i = 0; i < particles.Length; i++)
            {
                Vector3 velocity = particles[i].velocity;
                velocity.y += 10f * Time.deltaTime;
                particles[i].velocity = velocity;
            }
        }

        

        //Vector2 pos = transform.position;
        //if (ps != null)
        //{
        //    for (int j = 0; j < numberOfParticles; j++)
        //    {
        //        ps.Emit(transform.position, Vector3.zero * 1f, 0.1f, 1f, Color.red);

        //        ps.Emit(numberOfParticles);
        //    }

        //    Particle[] particles = new Particle[ps.particleCount];
        //    ps.GetParticles(particles);

        //    for (int i = 0; i < particles.Length; i++)
        //    {
        //        Vector3 velocity = particles[i].velocity;
        //        velocity.z -= 10f * (i + 1) * Time.deltaTime;
        //        particles[i].velocity = velocity;
        //    }

        //    ps.SetParticles(particles, particles.Length);
        //}

        //yield return new WaitForSeconds(1f);
        ////StartCoroutine(EmitSwordEffectParticles());
        yield return null;
    }
Ejemplo n.º 2
0
    private void CreatePoints()
    {
        var lines = dataSet.text.Split('\n');

        points = new Particle[lines.Length - 2];//lines.Length - 1];
        data = new Quaternion[lines.Length - 2];//lines.Length - 1];

        for (int i = 1; i < lines.Length - 1; ++i)
        {
            var line = lines[i].Split(' ');

            var normal = new Vector4(float.Parse(line[2]), float.Parse(line[3]), float.Parse(line[4]), float.Parse(line[5]));

            normal.Normalize();


            data[i - 1] = new Quaternion(normal.x, normal.y, normal.z, normal.w);
            

            var particle = new Particle()
            {
                position = StereographicProjection(normal),
                size = ParticleSize,//Mathf.Abs(ParticleSize * float.Parse(line[2])),
                color = Color.white
            };

            points[i - 1] = particle;
        }

        ps.SetParticles(points, points.Length);
    }
Ejemplo n.º 3
0
 public static int GetParticlesInLargetArray(this ParticleSystem shuriken, ref ParticleSystem.Particle[] particles)
 {
     if (particles == null || particles.Length < shuriken.particleCount) {
         particles = new ParticleSystem.Particle[shuriken.particleCount * 2];
     }
     return shuriken.GetParticles(particles);
 }
Ejemplo n.º 4
0
		public ParticleSystem.Particle[] CloneAsParticles ()
		{
			ParticleSystem.Particle[] p = new ParticleSystem.Particle[particles.Length];
			for (int i = 0; i<p.Length; i++)
			{
				p[i] = particles[i].CloneAsParticle();
			}
			return p;
		}
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.ParticleSystem.Particle o;
			o=new UnityEngine.ParticleSystem.Particle();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Ejemplo n.º 6
0
    void FillHole(int index)
    {
        Particle temp = particles[index];

        for (int i = 0; i < pS.GetParticles(particles); i++)
        {
            if (i > index)
            {
                particles[i] = particles[i - 1];
            }
        }
        particles[particles.Length - 1] = temp;
    }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem.Particle o;
         o = new UnityEngine.ParticleSystem.Particle();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem.Particle o;
         o = new UnityEngine.ParticleSystem.Particle();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem.Particle o;
         o=new UnityEngine.ParticleSystem.Particle();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
    static bool Particle_GetCurrentSize__ParticleSystem(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.ParticleSystem          arg0    = (UnityEngine.ParticleSystem)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.ParticleSystem.Particle argThis = (UnityEngine.ParticleSystem.Particle)vc.csObj;                JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(argThis.GetCurrentSize(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
 static void Particle_color(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         var result = _this.color;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Color32 arg0 = (UnityEngine.Color32)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         _this.color = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 static void Particle_randomSeed(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         var result = _this.randomSeed;
         JSApi.setUInt32((int)JSApi.SetType.Rval, (System.UInt32)(result));
     }
     else
     {
         System.UInt32 arg0 = (System.UInt32)JSApi.getUInt32((int)JSApi.GetType.Arg);
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         _this.randomSeed = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 static void Particle_velocity(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         var result = _this.velocity;
         JSApi.setVector3S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector3 arg0 = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         _this.velocity = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 static void Particle_startLifetime(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         var result = _this.startLifetime;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.ParticleSystem.Particle _this = (UnityEngine.ParticleSystem.Particle)vc.csObj;
         _this.startLifetime = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
		private void ParticlePull()
		{
			float _sqrAttractRadius = AttractRadius * AttractRadius;
		
			ParticleSystem.Particle[] x = new ParticleSystem.Particle[gameObject.particleSystem.particleCount + 1]; 
			int y = particleSystem.GetParticles(x);
		

			for(int i = 0; i < y; i++)
			{
				Vector3 _distance = MagnetPoint.position - x[i].position;
				float _sqrDistance = _distance.sqrMagnitude;
			
				if(_sqrDistance <= _sqrAttractRadius)
				{

					float _lifeTime = x[i].lifetime;
					float _velocity = x[i].velocity.magnitude;
         

					if((_lifeTime < this.AttractTime) && (_lifeTime > 0.0f))
					{
						Vector3 _vec = MagnetPoint.position - x[i].position;
						_vec = _vec.normalized * 2000.0f;//(1500.0f - offset.magnitude);

						//x[i].velocity = Vector3.Slerp(x[i].velocity, _vec, Mathf.SmoothStep(0, 1.0f, (Time.deltaTime / 0.1F)));
						//x[i].velocity = Vector3.Slerp(x[i].velocity, _vec, (1.75f - _lifeTime)  );
						x[i].velocity = Vector3.Slerp(x[i].velocity, _vec, this.AttractTime - _lifeTime);

						if((x[i].position - MagnetPoint.position).magnitude <= 30.0f)
						{
							x[i].lifetime = 0;
						}
					}

					Quaternion _rot = Quaternion.LookRotation(this.transform.position - x[i].position);
					Vector3 _axis;
					float _angle;
					_rot.ToAngleAxis(out _angle, out _axis);
					x[i].axisOfRotation = _axis;
					x[i].rotation = _angle;
				}
			}
		
			gameObject.particleSystem.SetParticles(x, y);
			return;
		}
    public static void SetCurrentParticleColor(ParticleSystem particleSystem, Color color)
    {
        UnityEngine.ParticleSystem.Particle[] particles = new UnityEngine.ParticleSystem.Particle[particleSystem.maxParticles];
        int particleCount = particleSystem.GetParticles(particles);

        Color temp;

        for (int i = 0; i < particleCount; i++)
        {
            temp               = particles[i].color;
            temp.r             = color.r;
            temp.g             = color.g;
            temp.b             = color.b;
            particles[i].color = temp;
        }
        particleSystem.SetParticles(particles, particleCount);
    }
Ejemplo n.º 17
0
    public IEnumerator absorbParticles(ParticleSystem collidedPS)
    {
        Particle[] particles =
            new Particle[collidedPS.main.maxParticles];
        int numAlive = collidedPS.GetParticles(particles);

        float maxTime     = 2f;
        float currentTime = 0f;

        while (currentTime < maxTime)
        {
            //print(numAlive);

            if (currentTime == 0)
            {
                for (int i = 0; i < numAlive; i++)
                {
                    Vector3 parentPos = collidedPS.transform.position;
                    Vector3 pVel      = (transform.position - parentPos) - particles[i].position;
                    particles[i].velocity = pVel.normalized * 12;
                }
                collidedPS.SetParticles(particles, numAlive);
                yield return(new WaitForSeconds(0.5f));

                currentTime += Time.deltaTime;
                continue;
            }

            for (int i = 0; i < numAlive; i++)
            {
                Vector3 parentPos = collidedPS.transform.position;
                particles[i].position = Vector3.Lerp(                 // Particles using local parent space coords
                    particles[i].position,
                    transform.position - parentPos,
                    .1f
                    );
            }

            currentTime += Time.deltaTime;
            collidedPS.SetParticles(particles, numAlive);
            yield return(0);
        }

        Destroy(collidedPS.gameObject);
    }
Ejemplo n.º 18
0
    void LateUpdate()
    {
        // update all Position & render
        Vector3 offset  = new Vector3(P5Setting.SCREEN_W / 2, P5Setting.SCREEN_H / 2, 0);
        Vector3 minSize = new Vector3(1, 1, 0) * PARTICLE_MINMUM_SIZE;

        for (int i = 0; i < maxParticles; i++)
        {
            UnityEngine.ParticleSystem.Particle particle = renderParticles[i];
            P5Particle pObj = particles[i];            // processing

            float pSize = pObj.isStay ? PARTICLE_STAY_SIZE : PARTICLE_SIZE;

            // StretchedBillboardを使っているのでvelocityが0になると表示されなくなるのを回避
            Vector3 t_velocity = new Vector3(pObj.vx, pObj.vy, 0);
            if (pObj.vMagnitude < MIN_MAGNITUDE)
            {
                t_velocity = minSize;
            }

            float z = -0.5f * pObj.vMagnitude;
            particle.position = new Vector3(pObj.x, pObj.y, z) - offset;

            //Stretched Billboardを使用しているときに上部MIN_MAGNITUDEの処理をするときに、
            //レンダリング位置がずれるのを回避する為にスムージング処理。
            //PARTICLE_MINMUM_SIZEを小さくする必要もある。

            float smooth = pObj.isStay ? 0.0025f : 0.5f;
            particle.velocity += (t_velocity - particle.velocity) * smooth;

            //renderParticle.velocity = t_velocity;
            //renderParticle.velocity = pObj.renderV;
            particle.size = pSize * pObj.mass * UPSCALE_SIZE;


            Color color = pObj.color;
            color.a        = pObj.alpha;
            particle.color = color;

            renderParticles[i] = particle;
        }
        //
        psys.SetParticles(renderParticles, maxParticles);
    }
Ejemplo n.º 19
0
    static int TriggerSubEmitter1(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            var obj  = (UnityEngine.ParticleSystem)ToLua.ToObject(L, 1);
            int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
            UnityEngine.ParticleSystem.Particle arg1 = StackTraits <UnityEngine.ParticleSystem.Particle> .To(L, 3);

            obj.TriggerSubEmitter(arg0, ref arg1);
            ToLua.PushValue(L, arg1);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 20
0
    static int Emit(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <UnityEngine.ParticleSystem.Particle>(L, 2))
            {
                UnityEngine.ParticleSystem          obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle arg0 = StackTraits <UnityEngine.ParticleSystem.Particle> .To(L, 2);

                obj.Emit(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <int>(L, 2))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                obj.Emit(arg0);
                return(0);
            }
            else if (count == 6)
            {
                UnityEngine.ParticleSystem obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.Vector3        arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3        arg1 = ToLua.ToVector3(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 5);
                UnityEngine.Color32 arg4 = StackTraits <UnityEngine.Color32> .Check(L, 6);

                obj.Emit(arg0, arg1, arg2, arg3, arg4);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.ParticleSystem.Emit"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 21
0
 // Update is called once per frame
 void Update()
 {
     if (emitting)
     {
         Particle[] parts = new Particle[ps.main.maxParticles];
         ps.GetParticles(parts);
         if (parts.GetUpperBound(0) > 0)
         {
             for (int i = 0; i < parts.GetUpperBound(0); i++)
             {
                 parts[i].position = Vector3.Lerp(parts[i].position, target.position + Vector3.up / 4.0f, Time.deltaTime * 4.0f);
             }
         }
         else
         {
             emitting = false;
         }
         ps.SetParticles(parts, parts.GetLength(0));
     }
 }
    static int TriggerSubEmitter(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                obj.TriggerSubEmitter(arg0);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.ParticleSystem.Particle>(L, 3))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.ParticleSystem.Particle arg1 = StackTraits <UnityEngine.ParticleSystem.Particle> .To(L, 3);

                obj.TriggerSubEmitter(arg0, ref arg1);
                ToLua.PushValue(L, arg1);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <System.Collections.Generic.List <UnityEngine.ParticleSystem.Particle> >(L, 3))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                System.Collections.Generic.List <UnityEngine.ParticleSystem.Particle> arg1 = (System.Collections.Generic.List <UnityEngine.ParticleSystem.Particle>)ToLua.ToObject(L, 3);
                obj.TriggerSubEmitter(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.ParticleSystem.TriggerSubEmitter"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 23
0
 public void AddCluster(Vector3 point, float size, float angle, bool refresh = true)
 {
     for(int k = 0; k < density; k++){
         var part = new SParticle();
         part.color = color;
         part.size = Random.Range(size * (1f - sizeRangePercentVeriance), size * (1f + sizeRangePercentVeriance));
         part.position = point +
             new Vector3(
                 (2f*maxDistance)*Random.value - maxDistance,
                 (2f*maxDistance)*Random.value - maxDistance,
                 (2f*maxDistance)*Random.value - maxDistance)
                 + offset;
         if(useAngle){
             part.rotation = angle;
         }
         particles.Add(part);
     }
     if(refresh) {
         Apply();
     }
 }
Ejemplo n.º 24
0
    static int Emit(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        Type[] types0 = { typeof(ParticleSystem), typeof(UnityEngine.ParticleSystem.Particle) };
        Type[] types1 = { typeof(ParticleSystem), typeof(int) };

        if (count == 2 && LuaScriptMgr.CheckTypes(L, types0, 1))
        {
            ParticleSystem obj = LuaScriptMgr.GetNetObject <ParticleSystem>(L, 1);
            UnityEngine.ParticleSystem.Particle arg0 = LuaScriptMgr.GetNetObject <UnityEngine.ParticleSystem.Particle>(L, 2);
            obj.Emit(arg0);
            return(0);
        }
        else if (count == 2 && LuaScriptMgr.CheckTypes(L, types1, 1))
        {
            ParticleSystem obj  = LuaScriptMgr.GetNetObject <ParticleSystem>(L, 1);
            int            arg0 = (int)LuaScriptMgr.GetNumber(L, 2);
            obj.Emit(arg0);
            return(0);
        }
        else if (count == 6)
        {
            ParticleSystem obj  = LuaScriptMgr.GetNetObject <ParticleSystem>(L, 1);
            Vector3        arg0 = LuaScriptMgr.GetNetObject <Vector3>(L, 2);
            Vector3        arg1 = LuaScriptMgr.GetNetObject <Vector3>(L, 3);
            float          arg2 = (float)LuaScriptMgr.GetNumber(L, 4);
            float          arg3 = (float)LuaScriptMgr.GetNumber(L, 5);
            Color32        arg4 = LuaScriptMgr.GetNetObject <Color32>(L, 6);
            obj.Emit(arg0, arg1, arg2, arg3, arg4);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: ParticleSystem.Emit");
        }

        return(0);
    }
Ejemplo n.º 25
0
Archivo: N22.cs Proyecto: skymeson/IVS3
    private void CreatePoints()
    {
        var lines = dataSet.text.Split('\n');

        points = new Particle[lines.Length - 2];   //lines.Length - 1];
        data   = new Quaternion[lines.Length - 2]; //lines.Length - 1];
        words  = new string[lines.Length - 2];     //lines.Length - 1];
        types  = new int[lines.Length - 2];        //lines.Length - 1];

        for (int i = 1; i < lines.Length - 1; ++i)
        {
            var line = lines[i].Split(' ');

            var normal = new Vector4(float.Parse(line[3]), float.Parse(line[4]), float.Parse(line[5]), float.Parse(line[6]));

            normal.Normalize();


            data[i - 1]  = new Quaternion(normal.x, normal.y, normal.z, normal.w);
            words[i - 1] = line[0];
            int type = int.Parse(line[1]);
            types[i - 1] = type;
            float length   = ParticleSize * Mathf.Pow((1 / float.Parse(line[2])), 1.2f);
            var   particle = new Particle()
            {
                position = StereographicProjection(normal),
                size     = length,//Mathf.Abs(ParticleSize * float.Parse(line[2])),
                color    = type == 0 ? Color.red :
                           type == 1 ? Color.green :
                           type == 2 ? Color.blue :
                           type == 3 ? Color.yellow :
                           Color.magenta
            };

            points[i - 1] = particle;
        }

        ps.SetParticles(points, points.Length);
    }
Ejemplo n.º 26
0
        protected override IEnumerator Behave()
        {
            while (true)
            {
                // For each found particle system in current scene ...
                foreach (ParticleSystem pS in FindObjectsOfType<ParticleSystem>())
                {
                    // ... get attached particles and their count
                    ParticleSystem.Particle[] particles = new ParticleSystem.Particle[pS.particleCount];
                    int ptCount = pS.GetParticles(particles);

                    // For each particle in current particle system ...
                    for (int i = 0; i < ptCount; i++)
                    {
                        // ... get vector to that particle ...
                        Vector3 toParticleVect = particles[i].position - transform.position;
                        // ... distance ...
                        float dist = toParticleVect.magnitude;
                        // ... and normalized vector
                        Vector3 n = toParticleVect.normalized;

                        particles[i].velocity = -n * Force / (dist * dist + Range / 10);

                        // If particle is in range for applying tangential acceleration to it ...
                        if (dist <= ParticlesCircleRange)
                        {
                            // ... then set velocity of that particle so it moves around this gameobject
                            particles[i].velocity = Force * new Vector3(n.y, -n.x, 0) / (dist + ParticlesCircleRange);
                        }
                    }

                    // Set new particles to current particle system
                    pS.SetParticles(particles, ptCount);
                }

                yield return null;
            }
        }
    static bool ParticleSystem_GetParticles__Particle_Array(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.ParticleSystem.Particle[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.ParticleSystem.Particle[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.ParticleSystem.Particle[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.ParticleSystem.Particle)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(((UnityEngine.ParticleSystem)vc.csObj).GetParticles(arg0)));
        }

        return(true);
    }
Ejemplo n.º 28
0
    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();
    }
Ejemplo n.º 29
0
    public void CreatePoints(string filePath)
    {
        _infoText.text = "Hit Me 1";
        _dataPlot      = LoadJson.Instance.LoadFromFile(filePath);
        _particles     = new Particle[_dataPlot.Particles.Length];

        for (int index = 0; index < _dataPlot.Particles.Length; index++)
        {
            var p = _dataPlot.Particles[index];

            var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
            normal.Normalize();

            _particles[index] = new Particle()
            {
                position = normal.StereographicProjection(),
                color    = p.Color,
                size     = p.Size
            };
        }

        _particleSystem.SetParticles(_particles, _particles.Length);
    }
Ejemplo n.º 30
0
    private void SetParticles()
    {
        int i = 0;

        for (int x = 0; x < 5; x++)
        {
            for (int y = 0; y < 5; y++)
            {
                for (int z = 0; z < 5; z++)
                {
                    particles[i] = new Particle()
                    {
                        position   = new Vector3(x, y, z) * 0.05f,
                        startSize  = 0.1f,
                        startColor = Color.cyan
                    };
                    i++;
                }
            }
        }

        ps.SetParticles(particles.ToArray(), particles.Length);
    }
Ejemplo n.º 31
0
    public void Start()
    {
        _dataPlot = LoadJson.Instance.Load(_jsonData.text);
        _particles = new Particle[_dataPlot.Particles.Length];
        _particleSystem = GetComponent<ParticleSystem>();
        _camT = Camera.main.transform;
        _baseRotation = Quaternion.identity;
        _rotations = new[] {Quaternion.identity, Quaternion.identity};

        _inV = Vector3.zero;

        _sizeSlider.value = ParticleSize;

        //Create Points
        for (int index = 0; index < _dataPlot.Particles.Length; index++)
        {
            var p = _dataPlot.Particles[index];
            
            var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
            normal.Normalize();

            _particles[index] = new Particle()
            {
                position = normal.StereographicProjection(),
                color = p.Color,
                size = p.Size
            };
        }

        _particleSystem.SetParticles(_particles, _particles.Length);

        //SelectFile.Instance.FileSelected += CreatePoints;

        _xPos.text = "0";
        _yPos.text = "0";
        _zPos.text = "0";
    }
Ejemplo n.º 32
0
    public void Start()
    {
        _dataPlot       = LoadJson.Instance.Load(_jsonData.text);
        _particles      = new Particle[_dataPlot.Particles.Length];
        _particleSystem = GetComponent <ParticleSystem>();
        _camT           = Camera.main.transform;
        _baseRotation   = Quaternion.identity;
        _rotations      = new[] { Quaternion.identity, Quaternion.identity };

        _inV = Vector3.zero;

        _sizeSlider.value = ParticleSize;

        //Create Points
        for (int index = 0; index < _dataPlot.Particles.Length; index++)
        {
            var p = _dataPlot.Particles[index];

            var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
            normal.Normalize();

            _particles[index] = new Particle()
            {
                position = normal.StereographicProjection(),
                color    = p.Color,
                size     = p.Size
            };
        }

        _particleSystem.SetParticles(_particles, _particles.Length);

        //SelectFile.Instance.FileSelected += CreatePoints;

        _xPos.text = "0";
        _yPos.text = "0";
        _zPos.text = "0";
    }
Ejemplo n.º 33
0
        protected void PullParticles()
        {
            foreach (ParticleSystem pS in FindObjectsOfType<ParticleSystem>())
            {
                ParticleSystem.Particle[] particles = new ParticleSystem.Particle[pS.particleCount];
                int ptCount = pS.GetParticles(particles);

                for (int i = 0; i < ptCount; i++)
                {
                    Vector3 vect = transform.position - particles[i].position;
                    float dist = vect.magnitude;
                    Vector3 n = vect.normalized;

                    particles[i].velocity = ParticlesForce * n / (dist * dist + 4);

                    if (dist <= ParticlesCircleRange)
                    {
                        particles[i].velocity = ParticlesForce * new Vector3(n.z, 0, -n.x) / (dist + ParticlesCircleRange);
                    }
                }

                pS.SetParticles(particles, ptCount);
            }
        }
        /// <summary>
        /// Update world position of particle effects with offset.
        /// </summary>
        /// <param name="offset"></param>
        /// 
        void UpdateParticles(Vector3 offset)
        {
            ParticleSystem[] particleSystems;
            particleSystems = transform.GetComponentsInChildren<ParticleSystem>();
            for (int i = 0; i < particleSystems.Length; i++)
            {
                ParticleSystem ps = particleSystems[i];

                if (ps == null)
                    continue;
                else if (ps.simulationSpace == ParticleSystemSimulationSpace.Local)
                    continue;

                ParticleSystem.Particle[] particles;
                particles = new ParticleSystem.Particle[ps.particleCount];
                int n = ps.GetParticles(particles);

                for (int j = 0; j < n; j++)
                {
                    particles[j].position += offset;
                }
                ps.SetParticles(particles, n);
            }
        }
Ejemplo n.º 35
0
        void Update()
        {
            float spawnDistance = 200;
            float fade = 50;

            if (isReady){
            ParticleSystem.Particle[] particles = new ParticleSystem.Particle[cacheCosmosParticle.particleCount];
            cacheCosmosParticle.GetParticles(particles);

            for (int i = 0; i < particles.Length; i++) {

                float dist = Vector3.Distance( cacheTransform.position, particles[i].position);

                if (dist>spawnDistance){
                    particles[i].position = cacheTransform.position + Random.onUnitSphere * spawnDistance;
                    particles[i].size = Random.Range(minSize, maxSize );
                    particles[i].rotation = Random.Range(-180,180);
                    particles[i].color = color.Evaluate( Random.Range(0f,1f));

                    if (enableDrift){
                        particles[i].velocity  =new Vector3( Random.Range(-1f,1f),Random.Range(-1f,1f),0) * driftSpeed;
                    }
                    else{
                        particles[i].velocity = Vector3.zero;
                    }
                }

                // Fade
                float alpha = Mathf.Clamp01(1.0f - ((dist - fade) / (spawnDistance - fade)));
                particles[i].color = new Color( particles[i].color.r/255f,particles[i].color.g/255f,particles[i].color.b/255f, alpha);

                if (enableRotation){
                    particles[i].rotation += rotationSpeed * Mathf.Sign(particles[i].rotation)  * Time.deltaTime;
                }
            }

            cacheCosmosParticle.SetParticles(particles, cacheCosmosParticle.particleCount);
            }
        }
		public void Stop(float time) {
			
			var particles = new ParticleSystem.Particle[this.particleSystem.particleCount];
			var count = this.particleSystem.GetParticles(particles);
			for (int p = 0; p < count; ++p) {

				particles[p].lifetime = Random.Range(0f, time);

			}
			this.particleSystem.SetParticles(particles, count);
			this.particleSystem.Stop();

		}
		private void SetColor_PARTICLES(Color color) {

			var particles = new ParticleSystem.Particle[this.particleSystem.particleCount];
			var count = this.particleSystem.GetParticles(particles);
			for (int p = 0; p < count; ++p) {

				particles[p].startColor = color;

			}
			this.particleSystem.SetParticles(particles, count);

		}
Ejemplo n.º 38
0
 public void Emit(ParticleSystem.Particle particle)
 {
     EmitOld_Internal(ref particle);
 }
 static public int get_angularVelocity(IntPtr l)
 {
     UnityEngine.ParticleSystem.Particle o = (UnityEngine.ParticleSystem.Particle)checkSelf(l);
     pushValue(l, o.angularVelocity);
     return(1);
 }
 private static void RenderCollisionBounds(ParticleSystem system, GizmoType gizmoType)
 {
   if (CollisionModuleUI.s_LastInteractedEditor == null || !CollisionModuleUI.s_LastInteractedEditor.m_VisualizeBounds || (Object) CollisionModuleUI.s_LastInteractedEditor.m_ParticleSystemUI.m_ParticleSystem != (Object) system)
     return;
   ParticleSystem.Particle[] particles1 = new ParticleSystem.Particle[system.particleCount];
   int particles2 = system.GetParticles(particles1);
   Color color = Gizmos.color;
   Gizmos.color = Color.green;
   Matrix4x4 matrix4x4 = Matrix4x4.identity;
   if (system.simulationSpace == ParticleSystemSimulationSpace.Local)
     matrix4x4 = system.transform.localToWorldMatrix;
   for (int index = 0; index < particles2; ++index)
   {
     ParticleSystem.Particle particle = particles1[index];
     Gizmos.DrawWireSphere(matrix4x4.MultiplyPoint(particle.position), particle.GetCurrentSize(system) * 0.5f * CollisionModuleUI.s_LastInteractedEditor.m_RadiusScale.floatValue);
   }
   Gizmos.color = color;
 }
Ejemplo n.º 41
0
    public void CreatePoints(string filePath)
    {
        _infoText.text = "Hit Me 1";
        _dataPlot = LoadJson.Instance.LoadFromFile(filePath);
        _particles = new Particle[_dataPlot.Particles.Length];

        for (int index = 0; index < _dataPlot.Particles.Length; index++)
        {
            var p = _dataPlot.Particles[index];

            var normal = new Vector4(p.Position.x, p.Position.y, p.Position.z, p.Position.w);
            normal.Normalize();

            _particles[index] = new Particle()
            {
                position = normal.StereographicProjection(),
                color = p.Color,
                size = p.Size
            };
        }

        _particleSystem.SetParticles(_particles, _particles.Length);
    }
        private IEnumerator Do_Text_And_Audio( ParticleSystem particle_system, float amount, float text_size, AudioClip audio_clip, float pitch )
        {
            // Wait for the initial particle to be fired off
            while( particle_system.particleCount == 0 )
            {
                yield return null;
            }

            // Track it's position until it detonates
            ParticleSystem.Particle[] particle = new ParticleSystem.Particle[1];

            while( particle_system.particleCount > 0 )
            {
                particle_system.GetParticles( particle );
                yield return null;
            }

            // Create text/audio
            GameObject text_and_audio_gameobject = GameObject.Instantiate( this.amount_text_prefab ) as GameObject;

            // Set up text
            TextMesh text_mesh = text_and_audio_gameobject.GetComponentInChildren<TextMesh>();
            text_mesh.text = this.AmountToText( amount );
            text_mesh.fontSize = Mathf.RoundToInt( text_size );
            text_and_audio_gameobject.transform.position = particle_system.transform.TransformPoint( particle[0].position ) + new Vector3( 0f, 25f, 0f );
            text_and_audio_gameobject.transform.LookAt( this.camera.transform );

            // Set up audio
            AudioSource audio_source = text_and_audio_gameobject.GetComponent<AudioSource>();
            audio_source.clip = audio_clip;
            audio_source.pitch = pitch;
            audio_source.Play();

            // Animate in using scale
            float t = 0f;
            while( t < 1f )
            {
                t += Time.deltaTime;
                text_and_audio_gameobject.transform.localScale = Vector3.one * this.EaseOut( 0f, 1f, t );
                yield return null;
            }

            // Animate out
            Vector3 from_position = text_and_audio_gameobject.transform.position;
            Vector3 to_position = from_position + new Vector3( 0f, 10f, 0f );
            Color from_colour = new Color( 1f, 1f, 1f, 1f );
            Color to_colour = new Color( 1f, 1f, 1f, 0f );
            t = 0f;
            while( t < 1f )
            {
                t += Time.deltaTime / 2f;
                text_and_audio_gameobject.transform.position = Vector3.Lerp( from_position, to_position, t );
                text_and_audio_gameobject.transform.LookAt( this.camera.transform );
                text_mesh.color = Color.Lerp( from_colour, to_colour, t );
                yield return null;
            }

            Object.Destroy( text_and_audio_gameobject );
        }
Ejemplo n.º 43
0
 // Update is called once per frame
 void Update()
 {
     UnityEngine.ParticleSystem.Particle[] particles = new UnityEngine.ParticleSystem.Particle[particleSystem.maxParticles];
     particleSystem.GetParticles(particles);
 }
 static public int get_size(IntPtr l)
 {
     UnityEngine.ParticleSystem.Particle o = (UnityEngine.ParticleSystem.Particle)checkSelf(l);
     pushValue(l, o.size);
     return(1);
 }
Ejemplo n.º 45
0
 private static void RenderCollisionBounds(ParticleSystem system, GizmoType gizmoType)
 {
     if (system.trigger.enabled && s_VisualizeBounds)
     {
         ParticleSystem.Particle[] particles = new ParticleSystem.Particle[system.particleCount];
         int num = system.GetParticles(particles);
         Color color = Gizmos.color;
         Gizmos.color = Color.green;
         Matrix4x4 identity = Matrix4x4.identity;
         if (system.main.simulationSpace == ParticleSystemSimulationSpace.Local)
         {
             identity = system.GetLocalToWorldMatrix();
         }
         Matrix4x4 matrix = Gizmos.matrix;
         Gizmos.matrix = identity;
         for (int i = 0; i < num; i++)
         {
             ParticleSystem.Particle particle = particles[i];
             Vector3 vector = particle.GetCurrentSize3D(system);
             Gizmos.DrawWireSphere(particle.position, (Math.Max(vector.x, Math.Max(vector.y, vector.z)) * 0.5f) * system.trigger.radiusScale);
         }
         Gizmos.color = color;
         Gizmos.matrix = matrix;
     }
 }
Ejemplo n.º 46
0
		public ParticleSystem.Particle CloneAsParticle (bool includeVelocity = false)
		{
			ParticleSystem.Particle particle = new ParticleSystem.Particle();
			particle.position = position;
			particle.rotation = rotation;
			particle.lifetime = lifetime;
			particle.startLifetime = startLifetime;
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
			particle.size = size;
			particle.color = color;
#else
			particle.startSize = size;
			particle.startColor = color;
#endif

			if (includeVelocity)
				particle.velocity = velocity;

			return particle;
		}
Ejemplo n.º 47
0
 void AcquireParticleArray()
 {
     ParticleSystem.Particle[] systemParticles = new ParticleSystem.Particle[particles.particleCount];
     particles.GetParticles(systemParticles);
     //Debug.Log("Acquire " + systemParticles.Length);
     tempParticles.AddRange(systemParticles);
 }
 extern internal int GetParticleMeshIndex(ref ParticleSystem.Particle particle);
 static public int get_axisOfRotation(IntPtr l)
 {
     UnityEngine.ParticleSystem.Particle o = (UnityEngine.ParticleSystem.Particle)checkSelf(l);
     pushValue(l, o.axisOfRotation);
     return(1);
 }
 public PathParticleTracker()
 {
     this.particle = new ParticleSystem.Particle();
     this.particle.lifetime = 0.0f;
 }
 static public int get_randomSeed(IntPtr l)
 {
     UnityEngine.ParticleSystem.Particle o = (UnityEngine.ParticleSystem.Particle)checkSelf(l);
     pushValue(l, o.randomSeed);
     return(1);
 }
 public void TriggerSubEmitter(int subEmitterIndex, ref ParticleSystem.Particle particle)
 {
     TriggerSubEmitterForParticle(subEmitterIndex, particle);
 }
Ejemplo n.º 53
0
    public void UpdateSpritParticles()
    {
        if(spiritParticleSystem == null)
            return;

        int pcount = maxSpiritParticles;//spiritParticleSystem.particleCount;
        UnityEngine.ParticleSystem.Particle[] particles = new UnityEngine.ParticleSystem.Particle[pcount];
        //spiritParticleSystem.GetParticles(particles);

        Vector3 centerOfScreen = camcam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
        float minLineDist = 75.0f;

        int pIdx = 1;
        int numConnectedParticles = 0;

        float dt = Time.deltaTime;

        for(int i = 0; i < pcount; ++i)
        {
            SpiritParticle sp = spiritParticles[i];
            Vector3 ppos = sp.position;
            Vector3 screenPos = camcam.WorldToViewportPoint(ppos);
            int xCell = (int)(screenPos.x * N);
            int yCell = (int)(screenPos.y * N);

            sp.initTime -= dt;
            if(sp.initTime > 0.0f)
            {
                sp.mass = 1.0f - sp.initTime;
            }
            else
            {
                sp.velocity *= 1.0f - (0.5f*dt);

                if(xCell >= 1 && xCell < N-1 && yCell >= 1 && yCell < N-1)
                {
                    ppos.x += u[xCell,yCell] * SpirtParticlesEffectedByGridVelocity;
                    ppos.y += v[xCell,yCell] * SpirtParticlesEffectedByGridVelocity;
                    //this.densityField[xCell,yCell] += 0.01f;
                }
                else //bring em back towards the center of the screen
                {
                    Vector3 sub = centerOfScreen-ppos;
                    float len = sub.magnitude;
                    sub.Normalize();
                    sub *= ((SpiritGravity * (sp.mass * 100) / len));
                    sp.velocity.x += sub.x;
                    sp.velocity.y += sub.y;
                }

                //gravy towards player-finger-downs
                for(int m = 0; m < 2; ++m)
                {
                    if(ownerPlayerMouseInfo[m].player == null)
                        continue;
                    if(ownerPlayerMouseInfo[m].playerScript.MouseFingerDown() != PlayerScript.FingerState.None)
                    {
                        Vector3 sub = ownerPlayerMouseInfo[m].player.transform.position-ppos;
                        float len = sub.magnitude;
                        sub.Normalize();
                        sub *= ((SpiritToPlayerAttraction * (sp.mass * 400) / len));
                        sp.velocity.x += sub.x;
                        sp.velocity.y += sub.y;
                    }
                }

                //Do N-Body gravitations!
                for(int j = pIdx; j < pcount; ++j)
                {
                    SpiritParticle sp2 = spiritParticles[j];
                    Vector3 ppos2 = sp2.position;
                    Vector3 sub = ppos2-ppos;
                    float len = sub.magnitude;

                    if(len < minLineDist)
                    {
                        //Add a line between all these guys!
                        float alpha = 1-(len / minLineDist);
                        Color col = new Color(1.0f, 1.0f, 1.0f, alpha);
                        linesToDraw.Add(new LineToDraw(ppos, ppos2, col, col));
                        ++numConnectedParticles;
                    }

                    sub.Normalize();
                    sub *= ((SpiritGravity * (sp.mass * sp2.mass) / len)) * 0.25f;

                    if(len < SpritParticleSeperationDistance)
                    {
                        sp.velocity.x -= sub.x;
                        sp.velocity.y -= sub.y;
                    }
                    else
                    {
                        sp.velocity.x += sub.x;
                        sp.velocity.y += sub.y;
                    }
                }
            }

            ++pIdx;

            ppos.x += sp.velocity.x * dt;
            ppos.y += sp.velocity.y * dt;

            sp.position = ppos;
            particles[i].startLifetime = 2.5f;
            particles[i].lifetime = 5.0f;
            particles[i].position = ppos;
            particles[i].size = sp.mass * 20;
            particles[i].color = new Color32(248, 168, 255, 255);
        }

        //DebugStreamer.message = "maxSpiritParticles: " + maxSpiritParticles.ToString();
        spiritParticlesAllConnected = numConnectedParticles == maxSpiritParticles;
        spiritParticleSystem.SetParticles(particles, maxSpiritParticles);
    }
 extern internal void TriggerSubEmitterForParticle(int subEmitterIndex, ParticleSystem.Particle particle);