Ejemplo n.º 1
0
    IEnumerator Wait(float atLeast = 0.5f, float step = 0.1f, int rndMax = 20, Action callBack = null)
    {
        float elapsed = 0f;

        while (elapsed < atLeast)
        {
            elapsed += Time.deltaTime;
            yield return(null);
        }

        while (RainDropTools.Random(0, rndMax) != 0)
        {
            elapsed = 0f;
            while (elapsed < step)
            {
                elapsed += Time.deltaTime;
                yield return(null);
            }
        }

        if (callBack != null)
        {
            callBack();
        }
        yield break;
    }
Ejemplo n.º 2
0
    private void InitializeDrawer(FlowRainDrawerContainer dc)
    {
        dc.TimeElapsed             = 0f;
        dc.lifetime                = RainDropTools.Random(Variables.LifetimeMin, Variables.LifetimeMax);
        dc.fluctuationRate         = RainDropTools.Random(Variables.fluctuationRateMin, Variables.fluctuationRateMax);
        dc.acceleration            = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax);
        dc.transform.localPosition = RainDropTools.GetSpawnLocalPos(this.transform, camera, 0f, Variables.SpawnOffsetY);
        dc.startPos                = dc.transform.localPosition;

        dc.acceleration = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax);
        Material mat = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue);

        RainDropTools.ApplyRainMaterialValue(
            mat,
            ShaderType,
            Variables.NormalMap,
            Variables.OverlayTexture,
            Variables.DistortionValue,
            Variables.OverlayColor,
            Variables.ReliefValue,
            Variables.Blur,
            Variables.Darkness
            );
        dc.Drawer.lifeTime        = dc.lifetime;
        dc.Drawer.vertexDistance  = 0.01f;
        dc.Drawer.angleDivisions  = 20;
        dc.Drawer.material        = mat;
        dc.Drawer.widthCurve      = Variables.TrailWidth;
        dc.Drawer.widthMultiplier = RainDropTools.Random(Variables.SizeMinX, Variables.SizeMaxX);
        dc.Drawer.textureMode     = LineTextureMode.Stretch;
        dc.Drawer.vertexDistance  = (1f * this.Distance * RainDropTools.GetCameraOrthographicSize(this.camera).y) / (Variables.Resolution * 10f);
        dc.Drawer.Clear();
        dc.Drawer.enabled = false;
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Get an element from a weighted KeyValuePair list
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <param name="list"></param>
    /// <returns></returns>

    public static KeyValuePair <T1, T2> GetWeightedElement <T1, T2>(List <KeyValuePair <T1, T2> > list) where T2 : IComparable
    {
        if (list.Count == 0)
        {
            return(list.FirstOrDefault());
        }

        float totalweight = (float)list.Sum(t => Convert.ToDouble(t.Value));
        float choice      = RainDropTools.Random(0f, totalweight);
        float sum         = 0;

        foreach (var obj in list)
        {
            for (float i = sum; i < Convert.ToDouble(obj.Value) + sum; i++)
            {
                if (i >= choice)
                {
                    return(obj);
                }
            }
            sum += (float)Convert.ToDouble(obj.Value);
        }

        return(list.First());
    }
Ejemplo n.º 4
0
    private void Shuffle <T>(List <T> list)
    {
        int cnt = list.Count;

        while (cnt > 1)
        {
            cnt--;
            int k     = RainDropTools.Random(0, cnt + 1);
            T   value = list[k];
            list[k]   = list[cnt];
            list[cnt] = value;
        }
    }
Ejemplo n.º 5
0
 private void InitializeDrawer(SimpleRainDrawerContainer dc)
 {
     dc.TimeElapsed             = 0f;
     dc.lifetime                = RainDropTools.Random(Variables.LifetimeMin, Variables.LifetimeMax);
     dc.transform.localPosition = RainDropTools.GetSpawnLocalPos(this.transform, camera, 0f, Variables.SpawnOffsetY);
     dc.startPos                = dc.transform.localPosition;
     dc.startSize               = new Vector3(
         RainDropTools.Random(Variables.SizeMinX, Variables.SizeMaxX),
         RainDropTools.Random(Variables.SizeMinY, Variables.SizeMaxY),
         1f
         );
     dc.transform.localEulerAngles += Vector3.forward * (Variables.AutoRotate ? UnityEngine.Random.Range(0f, 179.9f) : 0f);
     dc.Drawer.NormalMap            = Variables.NormalMap;
     dc.Drawer.ReliefTexture        = Variables.OverlayTexture;
     dc.Drawer.Darkness             = Variables.Darkness;
     dc.Drawer.Hide();
 }
Ejemplo n.º 6
0
    private void UpdateTransform(FlowRainDrawerContainer dc)
    {
        Action initRnd = () =>
        {
            dc.rnd1   = RainDropTools.Random(-0.1f * Variables.Amplitude, 0.1f * Variables.Amplitude);
            dc.posXDt = 0f;
        };

        if (dc.posXDt == 0f)
        {
            StartCoroutine(
                Wait(
                    0.01f,
                    0.01f,
                    (int)(1f / dc.fluctuationRate * 100),
                    () =>
            {
                initRnd();
            }
                    )
                );
        }

        dc.posXDt += 0.01f * Variables.Smooth * Time.deltaTime;

        if (dc.rnd1 == 0f)
        {
            initRnd();
        }

        float t = dc.TimeElapsed;

        Vector3 downward = RainDropTools.GetGForcedScreenMovement(this.camera.transform, this.GForceVector);

        downward = -downward.normalized;

        Vector3 nextPos = new Vector3(
            Vector3.Slerp(dc.transform.localPosition, dc.transform.localPosition + downward * dc.rnd1, dc.posXDt).x,
            dc.startPos.y - downward.y * (1 / 2f) * t * t * dc.acceleration - Variables.InitialVelocity * t,
            0.001f // TODO: Work around
            );

        dc.transform.localPosition = nextPos;

        dc.transform.localPosition += GetProgress(dc) * new Vector3(GlobalWind.x, GlobalWind.y, 0f);
    }
Ejemplo n.º 7
0
    private void CheckSpawnTime()
    {
        if (interval == 0f)
        {
            interval = Variables.Duration / RainDropTools.Random(Variables.EmissionRateMin, Variables.EmissionRateMax);
        }

        timeElapsed += Time.deltaTime;
        if (timeElapsed >= interval)
        {
            int spawnNum = (int)Mathf.Min((timeElapsed / interval), Variables.MaxRainSpawnCount - drawers.FindAll(x => x.currentState == DrawState.Playing).Count());
            for (int i = 0; i < spawnNum; i++)
            {
                Spawn();
            }
            interval    = Variables.Duration / RainDropTools.Random(Variables.EmissionRateMin, Variables.EmissionRateMax);
            timeElapsed = 0f;
        }
    }