SetParticles() private method

private SetParticles ( Particle particles, int size ) : void
particles Particle
size int
return void
Ejemplo n.º 1
0
    void Start()
    {
        particleSystem = gameObject.GetComponent<ParticleSystem>();

        const int maxParticle = 1000;
        particleSystem.maxParticles = maxParticle;
        particles = new ParticleSystem.Particle[maxParticle];
        particleData = new ParticleData[maxParticle];
        particleSystem.Emit(maxParticle);
        particleSystem.GetParticles(particles);

        for (int i = 0; i < maxParticle; i++)
        {
            particles[i].position = Vector3.zero;
            particles[i].velocity = Vector3.zero;
            particles[i].size = 0.1f;

            float rotateX = Random.value * 360;
            float rotateY = Random.value * 180;
            float rotateZ = Random.value * 360;

            Quaternion q = new Quaternion();
            q.eulerAngles = new Vector3(rotateX, rotateY, rotateZ);
            particleData[i].direction = q * Vector3.forward;
            particleData[i].speed = 1;
            particleData[i].cos = i / ((float)maxParticle / 10);
        }

        particleSystem.SetParticles(particles, maxParticle);
    }
	static public int SetParticles(IntPtr l) {
		try {
			#if DEBUG
			var method = System.Reflection.MethodBase.GetCurrentMethod();
			string methodName = GetMethodName(method);
			#if UNITY_5_5_OR_NEWER
			UnityEngine.Profiling.Profiler.BeginSample(methodName);
			#else
			Profiler.BeginSample(methodName);
			#endif
			#endif
			int argc = LuaDLL.lua_gettop(l);
			if(argc==2){
				UnityEngine.ParticleSystem self=(UnityEngine.ParticleSystem)checkSelf(l);
				UnityEngine.ParticleSystem.Particle[] a1;
				checkArray(l,2,out a1);
				self.SetParticles(a1);
				pushValue(l,true);
				return 1;
			}
			else if(argc==3){
				UnityEngine.ParticleSystem self=(UnityEngine.ParticleSystem)checkSelf(l);
				UnityEngine.ParticleSystem.Particle[] a1;
				checkArray(l,2,out a1);
				System.Int32 a2;
				checkType(l,3,out a2);
				self.SetParticles(a1,a2);
				pushValue(l,true);
				return 1;
			}
			else if(argc==4){
				UnityEngine.ParticleSystem self=(UnityEngine.ParticleSystem)checkSelf(l);
				UnityEngine.ParticleSystem.Particle[] a1;
				checkArray(l,2,out a1);
				System.Int32 a2;
				checkType(l,3,out a2);
				System.Int32 a3;
				checkType(l,4,out a3);
				self.SetParticles(a1,a2,a3);
				pushValue(l,true);
				return 1;
			}
			pushValue(l,false);
			LuaDLL.lua_pushstring(l,"No matched override function SetParticles to call");
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
		#if DEBUG
		finally {
			#if UNITY_5_5_OR_NEWER
			UnityEngine.Profiling.Profiler.EndSample();
			#else
			Profiler.EndSample();
			#endif
		}
		#endif
	}
	private void AlterParticle( ParticleSystem _ParticleSystem )
	{
		ParticleSystem.Particle [] parray = new ParticleSystem.Particle[ _ParticleSystem.particleCount ] ; 
		int num = _ParticleSystem.GetParticles( parray ) ;
		Debug.Log( "num" + num );
		for( int i = 0 ; i < num ; ++i )
		{
			parray[i].position = Vector3.zero ;
			parray[i].color = Color.red ;
			// Debug.Log( "parray[i].position=" + parray[i].position ) ;
		}
		_ParticleSystem.SetParticles( parray , parray.Length ) ;
	}
 static public int SetParticles__O_Particle(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
         UnityEngine.ParticleSystem.Particle[] a1;
         checkArray(l, 2, out a1);
         self.SetParticles(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int SetParticles(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
         UnityEngine.ParticleSystem.Particle[] a1;
         checkType(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         self.SetParticles(a1, a2);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 6
0
        public void Update()
        {
            system = GetComponent<ParticleSystem>();
            particles = new ParticleSystem.Particle[system.particleCount];
            system.GetParticles(particles);

            for (int i = 0; i < particles.Length; i++) {
                if (i % 4 == 0) {
                    ((Light)Instantiate(light, particles[i].position, Quaternion.identity))
                        .gameObject.transform.SetParent(root.transform, false);
                }
            }

            system.SetParticles(particles, system.particleCount);
        }
 static int QPYX_SetParticles_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 3);
         UnityEngine.ParticleSystem            QPYX_obj_YXQP  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.ParticleSystem));
         UnityEngine.ParticleSystem.Particle[] QPYX_arg0_YXQP = ToLua.CheckStructArray <UnityEngine.ParticleSystem.Particle>(L_YXQP, 2);
         int QPYX_arg1_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 3);
         QPYX_obj_YXQP.SetParticles(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
 static int SetParticles(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
         UnityEngine.ParticleSystem.Particle[] arg0 = ToLua.CheckObjectArray <UnityEngine.ParticleSystem.Particle>(L, 2);
         int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
         obj.SetParticles(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 9
0
	public static void MoveParticles(ParticleSystem ps, Vector3 moveAmount)
	{
		if (ps != null)
		{
			var parr = new ParticleSystem.Particle[ps.maxParticles];
			var totalParticles = ps.GetParticles(parr);

			//Debug.LogFormat("{0}: {1} / {2}", ps.name, totalParticles, parr.Length);
			//Debug.Break();

			for (var i = 0; i < totalParticles; i++)
			{
				parr[i].position += moveAmount;
			}
			ps.SetParticles(parr, parr.Length);
		}
	}
 static public int SetParticles(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 5)
         {
             UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
             UnityEngine.ParticleSystem.Particle[] a1;
             checkArray(l, 3, out a1);
             System.Int32 a2;
             checkType(l, 4, out a2);
             System.Int32 a3;
             checkType(l, 5, out a3);
             self.SetParticles(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
             UnityEngine.ParticleSystem.Particle[] a1;
             checkArray(l, 3, out a1);
             System.Int32 a2;
             checkType(l, 4, out a2);
             self.SetParticles(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
             UnityEngine.ParticleSystem.Particle[] a1;
             checkArray(l, 3, out a1);
             self.SetParticles(a1);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 11
0
 static public int SetParticles__O_Particle__Int32__Int32(IntPtr l)
 {
     try {
         UnityEngine.ParticleSystem            self = (UnityEngine.ParticleSystem)checkSelf(l);
         UnityEngine.ParticleSystem.Particle[] a1;
         checkArray(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         System.Int32 a3;
         checkType(l, 4, out a3);
         self.SetParticles(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 12
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);
    }
    static int SetParticles(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.ParticleSystem.SetParticles");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 3);
            UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
            UnityEngine.ParticleSystem.Particle[] arg0 = ToLua.CheckStructArray <UnityEngine.ParticleSystem.Particle>(L, 2);
            int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
            obj.SetParticles(arg0, arg1);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 14
0
    // Update is called once per frame
    public void CreateParticleObject(Vector3 pos)
    {
        Debug.Log("Create fab");
        m_PartSys = GameObject.Instantiate ( Resources.Load<ParticleSystem> ( "Prefabs/BaseParticle" ) , pos , Quaternion.identity ) as ParticleSystem;
        m_Points = new ParticleSystem.Particle [ m_NumberOfParticles ];

        float increment = 10f / ( m_NumberOfParticles - 1 );

        for ( int i = 0 ; i < m_NumberOfParticles ; i++ )
        {
            float x = i * increment;
            m_Points [ i ].position = new Vector3 ( x , 0f , 0f );
            m_Points [ i ].color = new Color ( x , 0f , 0f );
            m_Points [ i ].size = 1f;
            //Debug.Log ( m_Points [ i ].position );
        }

        m_PartSys.SetParticles(m_Points, m_Points.Length);
    }
    static int SetParticles(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle[] arg0 = null;
                obj.SetParticles(arg0);
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle[] arg0 = null;
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                obj.SetParticles(arg0, arg1);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle[] arg0 = null;
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                int arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
                obj.SetParticles(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.ParticleSystem.SetParticles"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 16
0
    void Update()
    {
        if(isInit == false)
        {
            isInit = true;

            particleSystem = GetComponent<ParticleSystem>();
            particlesArray = new ParticleSystem.Particle[particleSystem.maxParticles];

            for (int i = 0; i < particlesArray.Length; i++)
            {
                particlesArray[i].position = 1000.0f * Random.insideUnitSphere;
                particlesArray[i].size = 100.0f;

            }

            particleSystem.SetParticles(particlesArray, particlesArray.Length);

            print (particleSystem);
            print (particlesArray.Length);

        }
    }
Ejemplo n.º 17
0
        static int _m_SetParticles(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.ParticleSystem __cl_gen_to_be_invoked = (UnityEngine.ParticleSystem)translator.FastGetCSObj(L, 1);


            try {
                {
                    UnityEngine.ParticleSystem.Particle[] particles = (UnityEngine.ParticleSystem.Particle[])translator.GetObject(L, 2, typeof(UnityEngine.ParticleSystem.Particle[]));
                    int size = LuaAPI.xlua_tointeger(L, 3);

                    __cl_gen_to_be_invoked.SetParticles(particles, size);



                    return(0);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
Ejemplo n.º 18
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.º 19
0
        // Build voxel object
        public override float Build(Storage voxels, Bounds bounds, Informer informer, object parameter)
        {
            // Check for given array
            if (voxels != null)
            {
                int width = voxels.Width;
                int height = voxels.Height;
                int depth = voxels.Depth;
                int sides = voxels.FacesCount;
                int x, y, z;

                // Check for non-empty array
                if (width * height * depth * sides > 0)
                {
                    if (particles == null)
                    {
                        // Calculate total scaling for one block
                        globalScaling = new Vector3(2.0f * bounds.extents.x / (float)width, 2.0f * bounds.extents.y / (float)height, 2.0f * bounds.extents.z / (float)depth);

                        // Check for given template container containing a particle system and its renderer
                        if (template != null && template.GetComponent <UnityEngine.ParticleSystem>() != null && template.GetComponent <Renderer>() != null && template.GetComponent <Renderer>().GetType() == typeof(ParticleSystemRenderer) && ((ParticleSystemRenderer)template.GetComponent <Renderer>()).mesh != null)
                        {
                            // Calculate offset and scaling vector for a particle mesh
                            offset     = -((ParticleSystemRenderer)template.GetComponent <Renderer>()).mesh.bounds.center;
                            scaling.x  = 0.5f / ((ParticleSystemRenderer)template.GetComponent <Renderer>()).mesh.bounds.extents.x;
                            scaling.y  = 0.5f / ((ParticleSystemRenderer)template.GetComponent <Renderer>()).mesh.bounds.extents.y;
                            scaling.z  = 0.5f / ((ParticleSystemRenderer)template.GetComponent <Renderer>()).mesh.bounds.extents.z;
                            offset.x  *= scaling.x;
                            offset.y  *= scaling.y;
                            offset.z  *= scaling.z;
                            scaling.x *= globalScaling.x;
                            scaling.y *= globalScaling.y;
                            scaling.z *= globalScaling.z;
                        }
                        else
                        {
                            // Unset translation und scaling
                            offset  = Vector3.zero;
                            scaling = Vector3.one;
                        }

                        // Add offset for half voxel
                        offset += new Vector3(0.5f * globalScaling.x, 0.5f * globalScaling.y, 0.5f * globalScaling.z);

                        // Move to match position of the original object
                        offset += bounds.center - gameObject.transform.position - bounds.extents;

                        // Create array to store particles to
                        particles      = new UnityEngine.ParticleSystem.Particle[voxels.Count];
                        particlesCount = 0;

                        // Calculate size of one particle
                        particleSize = Mathf.Max(globalScaling.x, Mathf.Max(globalScaling.y, globalScaling.z)) * sizeFactor;
                    }

                    // Check for main container
                    if (particles != null)
                    {
                        // Process all voxels
                        z = currentDepth;
                        //for (z = currentDepth; z < currentDepth + 1; ++z)
                        {
                            y = currentHeight;
                            //for (y = currentHeight; y < currentHeight + 1; ++y)
                            {
                                for (x = 0; x < width; ++x)
                                {
                                    // Retrieve material for current coordinate
                                    Material material = voxels.GetMaterial(x, y, z);

                                    // Check for valid voxel
                                    if (material != null)
                                    {
                                        // Calculate current voxel position
                                        Vector3 currentPosition = new Vector3((float)x * globalScaling.x + offset.x, (float)y * globalScaling.y + offset.y, (float)z * globalScaling.z + offset.z);

                                        // Set particle properties
                                        particles[particlesCount].position          = currentPosition;
                                        particles[particlesCount].startColor        = material.color;
                                        particles[particlesCount].remainingLifetime = 1000;
                                        particles[particlesCount].startLifetime     = 0;
                                        particles[particlesCount].randomSeed        = 0;
                                        particles[particlesCount].rotation          = 0;
                                        particles[particlesCount].startSize         = particleSize;
                                        particles[particlesCount].velocity          = Vector3.zero;
                                        particles[particlesCount].angularVelocity   = 0;

                                        // Increase number of particles
                                        ++particlesCount;
                                    }
                                }
                            }

                            // Increase to next height line
                            if (++currentHeight >= height)
                            {
                                // Increase to next depth slice
                                ++currentDepth;
                                currentHeight = 0;
                            }
                        }

                        // Return current progress when building has not been finished
                        if (currentDepth < depth)
                        {
                            return((float)currentDepth / (float)depth);
                        }
                    }
                }
            }

            // Check for particles
            if (particles != null && particlesCount > 0)
            {
                GameObject particlesContainer;

                // Clone existing or create new container
                if (template != null)
                {
                    particlesContainer      = (GameObject)Instantiate(template);
                    particlesContainer.name = targetName;
                    particlesContainer.SetActive(true);
                }
                else
                {
                    particlesContainer = new GameObject(targetName);
                }

                if (particlesContainer != null)
                {
                    // Copy position and unset scale and rotation
                    particlesContainer.transform.localPosition = gameObject.transform.position;
                    particlesContainer.transform.localScale    = Vector3.one;
                    particlesContainer.transform.localRotation = Quaternion.identity;

                    // Add particles system
                    UnityEngine.ParticleSystem particleSystem = particlesContainer.GetComponent <UnityEngine.ParticleSystem>();
                    if (particleSystem == null)
                    {
                        particleSystem = particlesContainer.AddComponent <UnityEngine.ParticleSystem>();
                    }

                    if (particleSystem != null)
                    {
                        // Add particle system renderer, if there is none
                        ParticleSystemRenderer particleSystemRenderer = particlesContainer.GetComponent <ParticleSystemRenderer>();
                        if (particleSystemRenderer == null)
                        {
                            particleSystemRenderer = particlesContainer.AddComponent <ParticleSystemRenderer>();

                            // Set render properties
                            if (particleSystemRenderer != null)
                            {
                                particleSystemRenderer.cameraVelocityScale = 0;
                                particleSystemRenderer.lengthScale         = 0;
                                particleSystemRenderer.maxParticleSize     = 1000;
                                particleSystemRenderer.velocityScale       = 0;
                            }
                        }

                        UnityEngine.ParticleSystem.EmissionModule emission = particleSystem.emission;
                        emission.rateOverTime = new UnityEngine.ParticleSystem.MinMaxCurve(10, new AnimationCurve());
                        emission.enabled      = true;

                        // Set properties for static particles
                        var mainModule = particleSystem.main;
                        mainModule.playOnAwake     = false;
                        mainModule.maxParticles    = particlesCount;
                        mainModule.simulationSpeed = 1;
                        mainModule.startSpeed      = 0;
                        mainModule.startLifetime   = 1;
                        mainModule.startSize       = bounds.extents.magnitude * 2;
                        mainModule.startDelay      = 0;
                        mainModule.gravityModifier = 0;
                        mainModule.simulationSpace = ParticleSystemSimulationSpace.Local;

                        // Force a simulation to calculate boundaries
                        particleSystem.Simulate(particleSystem.main.startLifetime.constant);

                        // Set particles
                        particleSystem.SetParticles(particles, particlesCount);

                        // Stop automatic simulation
                        particleSystem.Stop();
                        emission.enabled = false;
                    }

#if UNITY_EDITOR
                    // Add object creation undo operation
                    if (!Application.isPlaying)
                    {
                        UnityEditor.Undo.RegisterCreatedObjectUndo(particlesContainer, "\"" + targetName + "\" Creation");
                    }
#endif

                    // Execute informer callback
                    if (informer != null)
                    {
                        informer(new UnityEngine.Object[] { particlesContainer }, parameter);
                    }
                }
            }

            // Reset current processing data
            currentDepth  = 0;
            currentHeight = 0;
            particles     = null;

            return(1);
        }
Ejemplo n.º 20
0
    private void CreatePoints(string ks)
    {
        if (click1) m_System.SetParticles(points, points.Length);
        click1 = true;
        int counter = 0;
        string line;
        using (StreamReader reader = new StreamReader(ks))
        {
            while ((line = reader.ReadLine()) != null)
            {
                float k;
                float.TryParse(line, out k);
                mas.Add(k);
                line = null;
                counter++;

            }
            Debug.Log(counter);
        }

        if (resolution < 1 || resolution > 100)
        {
            Debug.LogWarning("Grapher resolution out of bounds, resetting to minimum.", this);
            resolution = 1;
        }
        currentResolution = resolution;
        int count = 0; while ((mas[count] != -1000))
        {

            for (int i = 0; i < resolution; i++)
            {
                try
                {

                    int il = count * resolution / 2 + i;
                    float x = 2 * 256 * count / counter;
                    float a = mas[count] + (mas[count + 2] - mas[count]) * i / resolution;
                    float b = mas[count + 1] + (mas[count + 3] - mas[count + 1]) * i / resolution;
                    points[il].position = new Vector3(a, b, 0);
                    points[il].color = new Color(a / 10, b / 10, 0f);
                    points[il].size = 0.1f;

                }

                catch (System.IndexOutOfRangeException)
                { Debug.Log("Ошибка IndexOutOfRangeException"); }

            }
            count += 2;
        }

        m_System = GetComponent<ParticleSystem>();
        if (currentResolution != resolution)
        {
            CreatePoints(ks);
        }
        m_System.SetParticles(points, points.Length);
        for (int i = 0; i < (int)points.Length; i++) points[i].position = new Vector3(0f, 0f, 0f);
        mas.Clear();
    }
    static int SetParticles(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 = ToLua.ToStructArray <UnityEngine.ParticleSystem.Particle>(L, 2);
                obj.SetParticles(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> >(L, 2))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> arg0 = StackTraits <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> > .To(L, 2);

                obj.SetParticles(arg0);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.ParticleSystem.Particle[], int>(L, 2))
            {
                UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle[] arg0 = ToLua.ToStructArray <UnityEngine.ParticleSystem.Particle>(L, 2);
                int arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                obj.SetParticles(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle>, int>(L, 2))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> arg0 = StackTraits <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> > .To(L, 2);

                int arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                obj.SetParticles(arg0, arg1);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.ParticleSystem.Particle[], int, int>(L, 2))
            {
                UnityEngine.ParticleSystem            obj  = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                UnityEngine.ParticleSystem.Particle[] arg0 = ToLua.ToStructArray <UnityEngine.ParticleSystem.Particle>(L, 2);
                int arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                int arg2 = (int)LuaDLL.lua_tonumber(L, 4);
                obj.SetParticles(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle>, int, int>(L, 2))
            {
                UnityEngine.ParticleSystem obj = (UnityEngine.ParticleSystem)ToLua.CheckObject(L, 1, typeof(UnityEngine.ParticleSystem));
                Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> arg0 = StackTraits <Unity.Collections.NativeArray <UnityEngine.ParticleSystem.Particle> > .To(L, 2);

                int arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                int arg2 = (int)LuaDLL.lua_tonumber(L, 4);
                obj.SetParticles(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.ParticleSystem.SetParticles"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 22
0
 public static ParticleSystem setParticles(ParticleSystem psys, ParticleSystem.Particle[] particles)
 {
     psys.SetParticles(particles, particles.Length);
     return psys;
 }
Ejemplo n.º 23
0
    void Start()
    {
        //get the particle system from the GameObject containing it
        system = systemHolder.GetComponent<ParticleSystem>();

        //create the specified count of particles
        system.Emit(emitCount);

        //create an array to hold the particles
        particleArray = new ParticleSystem.Particle[systemHolder.GetComponent<ParticleSystem>().particleCount];

        //fill particle array with system's particles so they can be manipulated
        system.GetParticles(particleArray);

        //the spacing between particles y value
        float offset = 2.0f / emitCount;

        //how much to increment the phi angle of the particles
        float increment = Mathf.PI * (3.0f - Mathf.Sqrt(5.0f));
        float x, y, z, r;

        //set the initial velocity and position of each of the particles in radial pattern using fibonnacci spiral
        //the fibonnacci spiral method prevents bunching of particles near the poles of the sphere (lat and long method)
        for (float i = 0; i < system.particleCount; i++)
        {
            //get the y value of current particle
            y = ((i * offset) - 1) + (offset / 2.0f);

            //find rotation along spiral based on y value
            r = Mathf.Sqrt(1 - Mathf.Pow(y, 2.0f));

            //calculate an approximation of phi for current particle
            float phi = ((i + 1) % emitCount) * increment;

            //use rotation along spiral r, and phi to calculate x and z coords
            x = Mathf.Cos(phi) * r;
            z = Mathf.Sin(phi) * r;

            //set particle position and velocity
            //initial postion of all particles is set to the center since they are meant to explode outwards
            particleArray[(int)i].position = new Vector3(0, 0, 0);
            //allow initial velocity to be tweaked with the speedFactor
            particleArray[(int)i].velocity = new Vector3(x / speedFactor, y / speedFactor, z / speedFactor);

        }
        //set the position and velocity of the particles in the system based on array
        system.SetParticles(particleArray, system.particleCount);
    }
Ejemplo n.º 24
0
    public void FixedUpdate()
    {
        // Solve collisions only for obbs (not particles)
        collisionSolver.Solve();

        // Update particle system
        particleSystem.Update(Constants.TimeStepSeconds);

        // Solve collisions only for particles
        collisionSolver.Solve(ref particleSystem.Particles);

        // Do simulation
        fluidSim.Calculate(ref particleSystem.Particles, lGravity, Constants.TimeStepSeconds);

        if (fillTypeIndex == 1)
        {
            renderer.GetComponent <MeshRenderer>().enabled = true;
            Mesh mesh = generator.GenerateMesh(fluidSim.m_grid.getFluidMapCount(), Constants.CellSpace / 3);
            filter.mesh = mesh;
        }
        else if (fillTypeIndex == 0)
        {
            renderer.GetComponent <MeshRenderer>().enabled = false;
            // align Unity Particles with simulated Particles ...
            int d = particleSystem.Particles.Count - ps.particleCount;
            if (d > 0)
            {
                ps.Emit(d);
            }

            ps.GetParticles(particles);
            mParticle p;
            for (int i = 0; i < particleSystem.Particles.Count; i++)
            {
                p = particleSystem.Particles[i];
                particles[i].position          = new Vector3(p.Position.x, p.Position.y, 0);
                particles[i].remainingLifetime = 1f;
            }
            ps.SetParticles(particles, particleSystem.MaxParticles);
        }
        else
        {
            //update particle buffer
            smallParticle[] particleArray = new smallParticle[particleSystem.Particles.Count];
            for (int i = 0; i < particleSystem.Particles.Count; i++)
            {
                particleArray[i] = particleSystem.Particles[i].toE();
            }
            particleBuffer.SetData(particleArray);
            // Bind the ComputeBuffer to the shader and the compute shader
            computeShader.SetBuffer(mComputeShaderKernelID, "particleBuffer", particleBuffer);
            computeShader.SetInt("particle_length", particleSystem.Particles.Count);
            int mWarpCount = Mathf.CeilToInt((float)fluidSim.m_grid.GPUVoxel / Constants.WARP_SIZE);
            computeShader.Dispatch(mComputeShaderKernelID, mWarpCount, 1, 1);
            grid[] gridArray = new grid[fluidSim.m_grid.GPUVoxel];
            gridBuffer.GetData(gridArray);
            int[] field = new int[gridArray.GetLength(0)];
            for (int i = 0; i < gridArray.GetLength(0); i++)
            {
                if (gridArray[i].value > 0)
                {
                    field[i] = 1;
                }
            }

            int[,] f = Helper.Make2DArray <int>(field, fluidSim.m_grid.Width * Constants.resolution + 1, fluidSim.m_grid.Height * Constants.resolution + 1);
            renderer.GetComponent <MeshRenderer>().enabled = true;
            Mesh mesh = generator.GenerateMesh(f, Constants.CellSpace / Constants.resolution);
            mesh        = mattatz.MeshSmoothingSystem.MeshSmoothing.LaplacianFilter(mesh);
            filter.mesh = mesh;
        }
    }
Ejemplo n.º 25
0
    // Use this for initialization
    void Start()
    {
        flockParticleEmitter = this.gameObject.GetComponentInChildren<ParticleSystem>();

        //--------------- Gather all colliders --------------------
        colliders = GetColliders();
        //--------------- Gather all colliders --------------------

        //--------------- Gather all Destination points --------------------
        destinationPoints = GetDestinationPoints();
        destinationPoints.Shuffle();
        //--------------- Gather all Destination points --------------------

        //--------------- Spawn Flocks --------------------
        flockers = new FlockData[FlockingSpawnCount];
        int i = FlockingSpawnCount;

        Vector3 center = this.transform.position;
        while (--i > -1)
            SpawnRandomFlockSpherical(center, flockers, i);
        //--------------- Spawn Flocks --------------------

        //--------------- For each Flock, spawn a Particle--------------------
        if (flockParticleEmitter != null)
        {
            ParticleSystem.Particle[] particles = new ParticleSystem.Particle[FlockingSpawnCount];
            i = FlockingSpawnCount;
            while (--i > -1)
                SpawnNewParticle(particles, i);

            flockParticleEmitter.SetParticles(particles, particles.Length);
            flockParticleEmitter.Play();
        }
        //--------------- For each Flock, spawn a Particle --------------------

        InitThreadPool();
    }
Ejemplo n.º 26
0
 public void ToParticleSystem(ParticleSystem ps)
 {
     ps.SetParticles(this.particles.ToArray(), this.particles.Count);
 }