Пример #1
0
 private void OnGUI()
 {
     entity = EditorGUILayout.ObjectField(entity, typeof(ParticleGeneration), true) as ParticleGeneration;
     if (GUILayout.Button("Test 3D") && entity != null)
     {
         a3 = entity.Test3DTexutureWrite();
     }
     EditorGUILayout.ObjectField(a3, typeof(Texture), true);
 }
    public void MarchingParticle(Layers layer, int startTime, int endTime, int divisor, string spriteFile, ParticleGeneration particleGenType, ParticleDirection direction)
    {
        if (particleGenType == ParticleGeneration.Pool)
        {
            using (var pool = new OsbSpritePool(GetLayer(layer), spriteFile, OsbOrigin.Centre, (sprite, sTime, eTime) => {
                sprite.Fade(sTime, Random(0.2f, 0.9f));
                sprite.Scale(sTime, Random(20f, 80f));
                if (direction == ParticleDirection.Top || direction == ParticleDirection.Bottom)
                {
                    sprite.MoveX(sTime, Random(-107, 757));
                }
                else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                {
                    sprite.MoveY(sTime, Random(0, 512));
                }

                if (eTime > endTime - GetBeatDuration(startTime, divisor) * 4) //Hide sprites if they cross the end time
                {
                    sprite.Fade(endTime, 0f);
                }
            }))
            {
                for (var sTime = (double)startTime; sTime <= endTime - GetBeatDuration(startTime, 1) * 4; sTime += GetBeatDuration(startTime, 2))
                {
                    var baseSpeed = Random(40, 120);
                    var eTime     = sTime + Math.Ceiling(930f / baseSpeed) * GetBeatDuration(startTime, 1);


                    var sprite = pool.Get(sTime, eTime);

                    bool fromTop     = direction == ParticleDirection.Bottom || direction == ParticleDirection.Right;
                    var  moveSpeed   = baseSpeed * (fromTop ? 1 : -1);
                    var  currentTime = sTime + (sTime - GetOffset((int)sTime)) % GetBeatDuration(startTime, 1);

                    if (direction == ParticleDirection.Bottom || direction == ParticleDirection.Top)
                    {
                        sprite.MoveY(sTime, fromTop ? -60 : 540);
                    }
                    else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                    {
                        sprite.MoveX(sTime, fromTop ? -130 : 800);
                    }


                    if (direction == ParticleDirection.Bottom || direction == ParticleDirection.Top)
                    {
                        while (fromTop ? sprite.PositionAt(currentTime).Y <540 : sprite.PositionAt(currentTime).Y> -60)
                        {
                            var yPos = sprite.PositionAt(currentTime).Y;
                            var yRot = sprite.RotationAt(currentTime);

                            sprite.MoveY(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), yPos, yPos + moveSpeed);
                            sprite.Rotate(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), yRot, yRot + Math.PI * 0.25f);

                            currentTime += GetBeatDuration(startTime, 1);
                        }
                    }
                    else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                    {
                        while (fromTop ? sprite.PositionAt(currentTime).X <800 : sprite.PositionAt(currentTime).X> -120)
                        {
                            var xPos = sprite.PositionAt(currentTime).X;
                            var xRot = sprite.RotationAt(currentTime);

                            sprite.MoveX(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), xPos, xPos + moveSpeed);
                            sprite.Rotate(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), xRot, xRot + Math.PI * 0.25f);

                            currentTime += GetBeatDuration(startTime, 1);
                        }
                    }
                    //thx Darky
                    if (Random(0, 4) > 0) //HACK move the time back in order to increase the particle count without running into syncing issues
                    {
                        sTime -= GetBeatDuration(startTime, 2);
                    }
                }
            }
        }
    }