Example #1
0
 public int GetParticleCount()
 {
     if (Initialised)
     {
         return(LPAPIParticleGroups.GetParticlesInGroupCount(this.GetPtr()));
     }
     return(0);
 }
Example #2
0
    /// <summary>Get the position of particle group Note: only works with rigid groups</summary>
    public Vector2 GetPosition()
    {
        IntPtr particlesPointer = LPAPIParticleGroups.GetParticleGroupPosition(ThingPtr);

        float[] particlesArray = new float[2];
        Marshal.Copy(particlesPointer, particlesArray, 0, 2);

        return(new Vector2(particlesArray[0], particlesArray[1]));
    }
Example #3
0
 /// <summary>Create this particle group in the simulation with a shape pointer you already have
 /// Note: Used for concave fixtures or fixtures with more than 8 vertices
 /// They are broken up into several fixtures </summary>
 protected override void InitialiseWithShape(IntPtr shape)
 {
     SubPtrs.Add(LPAPIParticleGroups.CreateParticleGroup(sys.GetPtr(), getPartNum(), getGroupNum(), 0f, Strenght, AngularVelocity
                                                         , LinearVelocity.x, LinearVelocity.y
                                                         , shape
                                                         , (int)(_Color.r * 255f), (int)(_Color.g * 255f), (int)(_Color.b * 255f), (int)(_Color.a * 255f)
                                                         , Stride, LifeTime, UserData)
                 );
 }
    IEnumerator SplitGroup()
    {
        // Splitting a group can be costly so do not perform this operation each frame
        while (LPAPIParticleSystems.GetNumberOfParticles(sys.GetPtr()) > 0)
        {
            LPAPIParticleGroups.SplitParticleGroup(FindObjectOfType <LPManager>().ParticleSystems[0].GetPtr(), FindObjectOfType <LPParticleGroup>().GetPtr());

            IntPtr largestGroup = sys.GetLargestGroupDataFromPlugin();
            GetComponent <LPParticleGroup>().SetThingPtr(largestGroup);
            yield return(new WaitForSeconds(1f));
        }
    }
Example #5
0
    /// <summary>Get the center of particle group</summary>
    public Vector2 GetCenter()
    {
        if (ThingPtr == IntPtr.Zero)
        {
            return(new Vector2(999, 999));
        }
        IntPtr particlesPointer = LPAPIParticleGroups.GetParticleGroupCentroid(ThingPtr);

        float[] particlesArray = new float[2];
        Marshal.Copy(particlesPointer, particlesArray, 0, 2);

        return(new Vector2(particlesArray[0], particlesArray[1]));
    }
    private void MoveGroupToMousePosition()
    {
        // Move towards the mouse position
        if (Input.touchCount > 0 || Input.GetMouseButton(0))
        {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            Vector3 diff = mousePos - transform.position;
            diff.Normalize();
            diff.Scale(new Vector3(10000, 10000, 10000));
            LPAPIParticleGroups.ApplyForceToParticleGroup(GetComponent <LPParticleGroup>().GetPtr(), diff.x, diff.y);
        }
    }
Example #7
0
    private IEnumerator Melt()
    {
        yield return(new WaitForSeconds(waittime));

        if (mat != null)
        {
            LPAPIParticleGroups.SetParticleFlagsInGroup(sys.GetPtr(), group.GetPtr(), mat.GetInt());
        }
        else
        {
            LPAPIParticleGroups.SetParticleFlagsInGroup(sys.GetPtr(), group.GetPtr(), 0);
        }

        Debug.Log("flags set");
    }
Example #8
0
    /// <summary>Create this particle group in the simulation</summary>
    public void Initialise(LPParticleSystem s)
    {
        sys = s;
        IntPtr shape = GetShape();

        ThingPtr = LPAPIParticleGroups.CreateParticleGroup(sys.GetPtr(), getPartNum(), getGroupNum(), 0f, Strenght, AngularVelocity
                                                           , LinearVelocity.x, LinearVelocity.y
                                                           , shape
                                                           , (int)(_Color.r * 255f), (int)(_Color.g * 255f), (int)(_Color.b * 255f), (int)(_Color.a * 255f)

                                                           , Stride, LifeTime, UserData);
        LPAPIUtility.ReleaseShape(shape);

        if (SubPtrs != null && ParticlesMaterial != null && (ParticlesMaterial.elastic || ParticlesMaterial.spring))
        {
            foreach (IntPtr groupptr in SubPtrs)
            {
                LPAPIParticleGroups.JoinParticleGroups(sys.GetPtr(), ThingPtr, groupptr);
            }
        }
    }
Example #9
0
    protected override void DoSpawn()
    {
        Vector3 diff = getdiff();

        if (!SpawnOnlyOneParticle)
        {
            pg.LinearVelocity = new Vector2(diff.x, diff.y);
            pg.Initialise(lpman.ParticleSystems[pg.ParticleSystemImIn]);


            if (JoinGroups)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    LPAPIParticleGroups.JoinParticleGroups(lpman.ParticleSystems[pg.ParticleSystemImIn].GetPtr()
                                                           , lastgroup, pg.GetPtr());
                }
                lastgroup = pg.GetPtr();
            }
        }
        else
        {
            int mat = 0;
            if (pg.ParticlesMaterial != null)
            {
                mat = pg.ParticlesMaterial.GetInt();
            }

            LPAPIParticles.CreateParticleInSystem(lpman.ParticleSystems[pg.ParticleSystemImIn].GetPtr()
                                                  , mat, transform.position.x, transform.position.y, diff.x, diff.y
                                                  , (int)(pg._Color.r * 255f), (int)(pg._Color.g * 255f), (int)(pg._Color.b * 255f), (int)(pg._Color.a * 255f)
                                                  , pg.LifeTime);
        }
    }
Example #10
0
 /// <summary>Delete this particle group. In the simulation and in unity</summary>
 public override void Delete()
 {
     LPAPIParticleGroups.DeleteParticlesInGroup(ThingPtr);
     Destroy(this);
 }