示例#1
0
 public void UpdateAllClouds(Color lightColor, Vector3 lightDirection)
 {
     for (int i = 0; i < clouds.Count; i++)
     {
         SilverLiningCumulusCloud cloud = (SilverLiningCumulusCloud)clouds[i];
         cloud.UpdateLighting(lightColor, lightDirection);
         cloud.GetRenderer().material.SetFloat("fade", cloudAlpha * cloud.GetAlpha());
     }
 }
示例#2
0
    public void UpdateOneCloud(Color lightColor, Vector3 lightDirection)
    {
        SilverLiningCumulusCloud cloud = (SilverLiningCumulusCloud)clouds[lastCloudUpdated];

        cloud.UpdateLighting(lightColor, lightDirection);
        cloud.GetRenderer().material.SetFloat("fade", cloudAlpha * cloud.GetAlpha());
        cloud.Update();

        lastCloudUpdated++;
        if (lastCloudUpdated == clouds.Count)
        {
            lastCloudUpdated = 0;
        }
    }
示例#3
0
    public void WrapAndUpdateClouds(bool cloudWrap, bool cull, Color lightColor, Vector3 lightDir)
    {
        Vector3 anchor = center;

        float halfWidth  = dimensions.x * 0.5f;
        float halfLength = dimensions.z * 0.5f;

        for (int i = 0; i < clouds.Count; i++)
        {
            SilverLiningCumulusCloud c = (SilverLiningCumulusCloud)clouds[i];

            Vector3 newCloudPos = c.GetPosition();

            Vector3 delta = newCloudPos - c.lightingWorldPos;
            if (delta.magnitude > (100.0 * SilverLining.unitScale))
            {
                c.lightingWorldPos = newCloudPos;
                Material m = c.GetRenderer().material;
                m.SetVector("cloudPos", newCloudPos);
            }

#if UNITY_3_5
            if (cull)
            {
                if (c.shuriken)
                {
                    bool wasActive = c.cloudObject.active;
                    c.cloudObject.active = TestInEllipse(newCloudPos);
                    if (c.cloudObject.active == true && !wasActive)
                    {
                        c.particleSystem.Simulate(0.1f);
                    }
                }
                else
                {
                    c.cloudObject.GetComponent <ParticleRenderer> ().enabled = TestInEllipse(newCloudPos);
                }
            }
            if (!cloudWrap || !c.cloudObject.active)
            {
                continue;
            }
#else
            if (cull)
            {
                if (c.shuriken)
                {
                    bool wasActive = c.cloudObject.activeSelf;
                    c.cloudObject.SetActive(TestInEllipse(newCloudPos));
                    if (c.cloudObject.activeSelf == true && !wasActive)
                    {
                        c.particleSystem.Simulate(0.1f);
                    }
                }
                else
                {
                    c.cloudObject.GetComponent <ParticleRenderer> ().enabled = TestInEllipse(newCloudPos);
                }
            }

            if (!cloudWrap || !c.cloudObject.activeSelf)
            {
                continue;
            }
#endif
            // Iterate until it's in bounds.
            bool adj;
            bool changed = false;

            do
            {
                adj = false;

                if (newCloudPos.x > anchor.x + halfWidth)
                {
                    newCloudPos.x = (anchor.x - halfWidth) + (newCloudPos.x - (anchor.x + halfWidth));
                    adj           = changed = true;
                }
                if (newCloudPos.x < anchor.x - halfWidth)
                {
                    newCloudPos.x = (anchor.x + halfWidth) - ((anchor.x - halfWidth) - newCloudPos.x);
                    adj           = changed = true;
                }
                if (newCloudPos.z > anchor.z + halfLength)
                {
                    newCloudPos.z = (anchor.z - halfLength) + (newCloudPos.z - (anchor.z + halfLength));
                    adj           = changed = true;
                }
                if (newCloudPos.z < anchor.z - halfLength)
                {
                    newCloudPos.z = (anchor.z + halfLength) - ((anchor.z - halfLength) - newCloudPos.z);
                    adj           = changed = true;
                }
            } while (adj);

            if (changed)
            {
                c.SetPosition(newCloudPos);
            }

            float minDist = halfWidth * 2.0f + halfLength * 2.0f;
            float dist    = Math.Abs(newCloudPos.x - (anchor.x + halfWidth)) / halfWidth;
            if (dist < minDist)
            {
                minDist = dist;
            }
            dist = Math.Abs(newCloudPos.x - (anchor.x - halfWidth)) / halfWidth;
            if (dist < minDist)
            {
                minDist = dist;
            }
            dist = Math.Abs(newCloudPos.z - (anchor.z + halfLength)) / halfLength;
            if (dist < minDist)
            {
                minDist = dist;
            }
            dist = Math.Abs(newCloudPos.z - (anchor.z - halfLength)) / halfLength;
            if (dist < minDist)
            {
                minDist = dist;
            }

            float t = 1.0f - minDist;
            if (t < 0)
            {
                t = 0;
            }
            if (t > 1.0f)
            {
                t = 1.0f;
            }

            float fade = 1.0f - (t * t * t * t * t);

            float epsilon = 0.01f;
            if (Math.Abs(c.GetAlpha() - fade) > epsilon)
            {
                c.SetAlpha(fade);
            }
        }
    }