Beispiel #1
0
    private void Spawn()
    {
        var waterDrop = WaterDropPool.Instance.Get();

        if (waterDrop == null)
        {
            // darn, out of water drops, try next time...
            return;
        }

        m_activeDropAnims.Add(new Tuple <WaterColorDrop, WaterColorDropAnimation>(waterDrop, waterDrop.gameObject.GetComponent <WaterColorDropAnimation>()));

        // find a position
        var randX = (float)(m_Random.NextGaussian() + 3) / 6f;
        var randY = (float)(m_Random.NextGaussian() + 3) / 6f;

        var worldPos = Camera.main.ViewportToWorldPoint(new Vector3(randX + spawnOffset.x, randY + spawnOffset.y, 0));

        worldPos.z = 0;

        // get color
        var color = colorPool[Random.Range(0, colorPool.Count)];

        // get a size
        var size = Random.Range(sizeSpan.x, sizeSpan.y);

        waterDrop.transform.position = worldPos;
        waterDrop.Color = color;
        var anim = waterDrop.GetComponent <WaterColorDropAnimation>();

        anim.maxScale = size;
        anim.AnimationFinishedEvent += OnAnimationEventFinished;
        anim.Animate();
    }
Beispiel #2
0
    public List <Point> GeneratePoints(int amount, double maxX, double maxY, GenerationType generationType)
    {
        MaxX = maxX;
        MaxY = maxY;

        var point0 = new Point(0, 0);
        var point1 = new Point(0, MaxY);
        var point2 = new Point(MaxX, MaxY);
        var point3 = new Point(MaxX, 0);

        var points = new List <Point>(amount + 1)
        {
            point0, point1, point2, point3
        };

        tri1 = new Triangle(point0, point1, point2);
        tri2 = new Triangle(point0, point2, point3);

        border = new List <Triangle>()
        {
            tri1, tri2
        };

        var random = new System.Random();

        switch (generationType)
        {
        case GenerationType.Guassian:
            for (int i = 0; i < amount - 4; i++)
            {
                var pointXG = Math.Abs(random.NextGaussian(0, 0.3f) * MaxX);
                var pointYG = Math.Abs(random.NextGaussian(0, 0.3f) * MaxY);

                points.Add(new Point(pointXG, pointYG));
            }

            break;

        case GenerationType.Random:
            for (int i = 0; i < amount - 4; i++)
            {
                var pointX = random.NextDouble() * MaxX;
                var pointY = random.NextDouble() * MaxY;
                points.Add(new Point(pointX, pointY));
            }

            break;

        case GenerationType.Circle:
            for (int i = 0; i < amount - 4; i++)
            {
                var point = random.InCircleGetPoint(1500);
                points.Add(point);
            }

            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(generationType), generationType, null);
        }

        return(points);
    }