纳金网
标题:
闪烁灯光脚本
[打印本页]
作者:
狂风大尉
时间:
2014-6-26 17:03
标题:
闪烁灯光脚本
using UnityEngine;
using System.Collections;
[RequireComponent( typeof( Light ) )]
public class flickeringLight : 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;
}
}
}
复制代码
作者:
HIDEOKOJIMA
时间:
2014-6-26 18:08
Thanks for this !
作者:
hyui
时间:
2014-6-26 18:39
Good to know!
作者:
Kadina
时间:
2014-6-27 07:44
感谢分享
作者:
texfill
时间:
2014-6-27 09:53
Thanks for share !
作者:
wucnj
时间:
2014-6-27 14:18
感谢分享!!!
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5