// Custom Light Effects Scripts | |
// Adds custom light effects to props. | |
// Multiple effects can be added, including vanilla ones. | |
// The mod is not required to run the scripts or save the asset. | |
// It's only required for loading them. | |
// | |
// Custom Light Effects - Main Script | |
// Adds custom light effects to props in asset editor, visible in realtime, saves data in the prop mesh name. | |
// DO NOT save with these effects visible! | |
// YOU MUST run the presave script as well (below) before saving the prop asset! | |
var slot = 0; // light effect slot, start with 0, continue adding more if needed | |
// if you have multiple slots used, you can overwrite any of them | |
var type = "spot"; // spot or point | |
var intensity = 1.0f; // brightness 1-8 | |
var range = 10.0f; // distance and glow size | |
var bloom = 0.5f; // strength of additional spotlight glow effect | |
var angle = 60.0f; // angle of spotlight beam | |
var color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // main color of the lightRGBA | |
var variations = false; // set to true to use color variations | |
Color variation1 = new Color(1.0f, 1.0f, 1.0f, 1.0f); // random color variations | |
Color variation2 = new Color(1.0f, 1.0f, 1.0f, 1.0f); // final color appears somewhere between | |
Color variation3 = new Color(1.0f, 1.0f, 1.0f, 1.0f); // main color and one of the variations | |
var position = new Vector3(0.0f, 10.0f, 0.0f); // position of the light effect | |
var direction = new Vector3(0.0f, 1.0f, 0.0f); // direction of the light effect | |
var off = 15.0f; // amount of hours the light is turned off during the day (15 max) (0 means always on) | |
var random = 0.3f; // adds randomness to time lights turn on/off, if 0 then all lights turn on/off at the same time | |
var blink = "none"; // none, blink, fade, pulse | |
var rotation = new Vector3(0.0f, 0.0f, 0.0f); // enable rotation on X Y Z, confusing once direction is changed | |
var rpm = 0; // rotations per minute | |
// Light Effect Processing | |
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo; asset.m_hasEffects = true; | |
var existingLightEffect = EffectCollection.FindEffect("Flood Light Orange") as LightEffect; | |
LightEffect lightEffect = LightEffect.Instantiate(existingLightEffect); | |
lightEffect.transform.parent = existingLightEffect.transform; | |
Light light = lightEffect.gameObject.GetComponent<Light>(); | |
light.color = color; light.intensity = intensity; light.range = range; light.spotAngle = angle; | |
if(type=="spot") light.type = LightType.Spot; | |
else light.type = LightType.Point; | |
if(blink=="blink") lightEffect.m_blinkType = LightEffect.BlinkType.Blink_050_050; | |
else if(blink=="fade") lightEffect.m_blinkType = LightEffect.BlinkType.MediumFade_500_500; | |
else if(blink=="pulse") lightEffect.m_blinkType = LightEffect.BlinkType.StrongBlaze_0125_0125; | |
else lightEffect.m_blinkType = LightEffect.BlinkType.None; | |
lightEffect.m_rotationAxis = rotation; lightEffect.m_rotationSpeed = rpm; lightEffect.m_spotLeaking = bloom; | |
lightEffect.m_offRange.x = 6*Convert.ToSingle(Math.Pow(Convert.ToDouble((6-off/2.5)/6), Convert.ToDouble(1/1.09))); | |
lightEffect.m_offRange.y = Mathf.Clamp(6*Convert.ToSingle(Math.Pow(Convert.ToDouble((6-off/2.5)/6), Convert.ToDouble(1/1.09)))-random, 0, 6); | |
if(variations==true) { | |
lightEffect.m_variationColors[0] = variation1; | |
lightEffect.m_variationColors[1] = variation2; | |
lightEffect.m_variationColors[2] = variation3; } | |
else { | |
lightEffect.m_variationColors[0] = color; variation1 = color; | |
lightEffect.m_variationColors[1] = color; variation2 = color; | |
lightEffect.m_variationColors[2] = color; variation3 = color; } | |
lightEffect.m_batchedLight = false; var inf = false; | |
typeof(EffectInfo).GetField("m_refCount", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(lightEffect, 0); | |
lightEffect.InitializeEffect(); | |
if(asset.m_effects.Length<slot+1) Array.Resize(ref asset.m_effects, slot+1); | |
asset.m_effects[slot] = new PropInfo.Effect {m_effect = lightEffect, m_position = position, m_direction = direction }; | |
// Data Storage | |
var data = "LightEffect " + inf.ToString() + " " + type + " " + | |
color.r.ToString("R") + " " + color.g.ToString("R") + " " + color.b.ToString("R") + " " + | |
intensity.ToString("R") + " " + range.ToString("R") + " " + bloom.ToString("R") + " " + angle.ToString("R") + " " + blink + " " + | |
rotation.x.ToString("R") + " " + rotation.y.ToString("R") + " " + rotation.z.ToString("R") + " " + rpm.ToString() + " " + | |
variation1.r.ToString("R") + " " + variation1.g.ToString("R") + " " + variation1.b.ToString("R") + " " + | |
variation2.r.ToString("R") + " " + variation2.g.ToString("R") + " " + variation2.b.ToString("R") + " " + | |
variation3.r.ToString("R") + " " + variation3.g.ToString("R") + " " + variation3.b.ToString("R") + " " + | |
position.x.ToString("R") + " " + position.y.ToString("R") + " " + position.z.ToString("R") + " " + | |
direction.x.ToString("R") + " " + direction.y.ToString("R") + " " + direction.z.ToString("R") + " " + | |
off.ToString("R") + " " + random.ToString("R") + " "; | |
if(asset.m_lodMesh.name.Contains("LightEffect") == true) { | |
string[] slots = (asset.m_lodMesh.name+"#").Split('#'); slots[slot] = data; | |
asset.m_lodMesh.name = string.Join("#", slots); | |
if(asset.m_lodMesh.name[asset.m_lodMesh.name.Length-2].ToString()=="#") asset.m_lodMesh.name = asset.m_lodMesh.name.Remove(asset.m_lodMesh.name.Length-2); | |
else if(asset.m_lodMesh.name[asset.m_lodMesh.name.Length-1].ToString()=="#") asset.m_lodMesh.name = asset.m_lodMesh.name.Remove(asset.m_lodMesh.name.Length-1); } | |
else asset.m_lodMesh.name = data+" "; | |
// | |
// | |
// Custom Light Effects - Vanilla Script | |
// Adds vanilla light effects to props in asset editor, visible in realtime, saves data in the prop mesh name. | |
// DO NOT save with these effects visible! | |
// YOU MUST run the presave script as well (below) before saving the prop asset! | |
var slot = 0; // light effect slot | |
// it seems that a vanilla light effect is only visible when in slot 0 | |
var name = "Flood Light Blue"; // name of the vanilla light effect | |
var position = new Vector3(0.0f, 10.0f, 0.0f); // position of the light effect | |
var direction = new Vector3(0.0f, 0.0f, 0.0f); // direction of the light effect | |
// Light Effect Processing | |
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo; asset.m_hasEffects = true; | |
var vanillaLE = EffectCollection.FindEffect(name) as LightEffect; | |
if(asset.m_effects.Length<slot+1) Array.Resize(ref asset.m_effects, slot+1); | |
asset.m_effects[slot] = new PropInfo.Effect {m_effect = vanillaLE, m_position = position, m_direction = direction }; | |
// Data Storage | |
name = name.Replace(' ', '_'); | |
var data = "LightEffect " + name + " " + position.x.ToString("R") + " " + position.y.ToString("R") + " " + position.z.ToString("R") + " " + | |
direction.x.ToString("R") + " " + direction.y.ToString("R") + " " + direction.z.ToString("R") + " "; | |
if(asset.m_lodMesh.name.Contains("LightEffect") == true) { | |
string[] slots = (asset.m_lodMesh.name+"#").Split('#'); slots[slot] = data; | |
asset.m_lodMesh.name = string.Join("#", slots); | |
if(asset.m_lodMesh.name[asset.m_lodMesh.name.Length-2].ToString()=="#") asset.m_lodMesh.name = asset.m_lodMesh.name.Remove(asset.m_lodMesh.name.Length-2); | |
else if(asset.m_lodMesh.name[asset.m_lodMesh.name.Length-1].ToString()=="#") asset.m_lodMesh.name = asset.m_lodMesh.name.Remove(asset.m_lodMesh.name.Length-1); } | |
else asset.m_lodMesh.name = data+" "; | |
// | |
// | |
// Custom Light Effects - Presave Script | |
// Removes custom light effect previews for correct saving. | |
// Run after you've added the light effects you want, then save the prop asset. | |
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo; | |
Array.Resize(ref asset.m_effects, 0); asset.m_hasEffects=false; | |
// | |
// | |
// Prop LOD Mesh Name Reader | |
// Allows reading the prop lod mesh name in the console. | |
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo; | |
Debug.Log(asset.m_lodMesh.name); | |
// | |
// | |
// Data Reference | |
// Shows how the data is stored for each light effect. | |
// Custom Light Effects | |
data[0] = "LightEffect"; | |
data[1] = infinite; | |
data[2] = type; | |
data[3] = color.r; | |
data[4] = color.g; | |
data[5] = color.b; | |
data[6] = intensity; | |
data[7] = range; | |
data[8] = bloom; | |
data[9] = angle; | |
data[10] = blink; | |
data[11] = rotation.x; | |
data[12] = rotation.y; | |
data[13] = rotation.z; | |
data[14] = rpm; | |
data[15] = variation1.r; | |
data[16] = variation1.g; | |
data[17] = variation1.b; | |
data[18] = variation2.r; | |
data[19] = variation2.g; | |
data[20] = variation2.b; | |
data[21] = variation3.r; | |
data[22] = variation3.g; | |
data[23] = variation3.b; | |
data[24] = position.x; | |
data[25] = position.y; | |
data[26] = position.z; | |
data[27] = direction.x; | |
data[28] = direction.y; | |
data[29] = direction.z; | |
data[30] = off; | |
data[31] = random; | |
// Vanilla Light Effects | |
data[0] = "LightEffect"; | |
data[1] = name; | |
data[2] = position.x; | |
data[3] = position.y; | |
data[4] = position.z; | |
data[5] = direction.x; | |
data[6] = direction.y; | |
data[7] = direction.z; | |
// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment