多米诺 发表于 2012-6-11 22:56

闪光灯源码 拖到脚本即可

<pre> using UnityEngine;
using System.Collections;

public classshanguangdeng: MonoBehaviour
{
   // Flickering Styles
    public enum flickerinLightStyles { CampFire = 0, Fluorescent = 1 };
   public flickerinLightStyles flickeringLightStyle = flickerinLightStyles.CampFire;
   // Campfire Methods
   public enum campfireMethods { Intensity = 0, Range = 1, Both = 2 };
   public campfireMethods campfireMethod = campfireMethods.Intensity;
   // Intensity Styles
   public enum campfireIntesityStyles { Sine = 0, Random = 1 };
   public campfireIntesityStyles campfireIntesityStyle = campfireIntesityStyles.Random;
   // Range Styles
      public enum campfireRangeStyles { Sine = 0, Random = 1 };
      public campfireRangeStyles campfireRangeStyle = campfireRangeStyles.Random;
      // Base Intensity Value
      public float CampfireIntensityBaseValue = 0.5f;
      // Intensity Flickering Power
      public float CampfireIntensityFlickerValue = 0.1f;
      // Base Range Value
      public float CampfireRangeBaseValue = 10.0f;
      // Range Flickering Power
      public float CampfireRangeFlickerValue = 2.0f;
      
      // If Style is Sine
      private float CampfireSineCycleIntensity = 0.0f;
      private float CampfireSineCycleRange = 0.0f;
      // "Glow" Speeds
      public float CampfireSineCycleIntensitySpeed = 5.0f;
      public float CampfireSineCycleRangeSpeed = 5.0f;
      public float FluorescentFlickerMin = 0.4f;
      public float FluorescentFlickerMax = 0.5f;
      public float FluorescentFlicerPercent = 0.95f;
      // NOT IMPLEMENTED YET !!!!
      public bool FluorescentFlickerPlaySound = false;
      public AudioClip FluorescentFlickerAudioClip;
      // ------------------------
   
      // Use this for initialization
      void Start () {
      
      }
      
      // Update is called once per frame
      void Update () {
          switch( flickeringLightStyle )
          {
            // If Flickering Style is Campfire
            case flickerinLightStyles.CampFire:
                  // If campfire method is Intesity OR Both
                  if( campfireMethod == campfireMethods.Intensity || campfireMethod == campfireMethods.Both )
                  {
                      // If Intensity style is Sine
                      if( campfireIntesityStyle == campfireIntesityStyles.Sine )
                      {
                        // Cycle the Campfire angle
                        CampfireSineCycleIntensity += CampfireSineCycleIntensitySpeed;
                        if( CampfireSineCycleIntensity > 360.0f ) CampfireSineCycleIntensity = 0.0f;
                        // Base + Values
                        light.intensity = CampfireIntensityBaseValue + ( ( Mathf.Sin( CampfireSineCycleIntensity * Mathf.Deg2Rad ) * ( CampfireIntensityFlickerValue / 2.0f ) ) + ( CampfireIntensityFlickerValue / 2.0f ) );
                      }
                      else light.intensity = CampfireIntensityBaseValue + Random.Range( 0.0f, CampfireIntensityFlickerValue );
                  }
                  // If campfire method is Range OR Both
                  if( campfireMethod == campfireMethods.Range || campfireMethod == campfireMethods.Both )
                  {
                      // If Range style is Sine
                      if( campfireRangeStyle == campfireRangeStyles.Sine )
                      {
                        // Cycle the Campfire angle
                        CampfireSineCycleRange += CampfireSineCycleRangeSpeed;
                        if( CampfireSineCycleRange > 360.0f ) CampfireSineCycleRange = 0.0f;
                        // Base + Values
                        light.range = CampfireRangeBaseValue + ( ( Mathf.Sin( CampfireSineCycleRange * Mathf.Deg2Rad ) * ( CampfireSineCycleRange / 2.0f ) ) + ( CampfireSineCycleRange / 2.0f ) );
                      }
                      else light.range = CampfireRangeBaseValue + Random.Range( 0.0f, CampfireRangeFlickerValue );
                  }
                  break;
            // If Flickering Style is Fluorescent
            case flickerinLightStyles.Fluorescent:
                  if( Random.Range( 0.0f, 1.0f ) > FluorescentFlicerPercent )
                  {
                      light.intensity = FluorescentFlickerMin;
                      // Check Audio - NOT IMPLEMENTED YET
                      if( FluorescentFlickerPlaySound )
                      {
                      }
                  }
                  else light.intensity = FluorescentFlickerMax;
                  break;
            default:
                  // You should not be here.
                  break;
          }
      
      }
}</pre>

aaabbbsss12345 发表于 2014-5-8 14:18

好东西 学习学习

星空雪舞 发表于 2017-2-23 16:59

很不错

心境 发表于 2017-2-23 17:02

顶顶多好

liuww 发表于 2017-2-23 16:32

真心顶

liuww 发表于 2017-2-23 16:22

很好哦

李孟超 发表于 2017-2-23 17:01

不错不错

不再用Q,请电联 发表于 2017-7-3 16:49

楼主是超人

铁血战舰 发表于 2017-7-3 17:05

真心顶

mxjma 发表于 2017-7-3 17:18

难得一见的好帖
页: [1]
查看完整版本: 闪光灯源码 拖到脚本即可