playMaker

Author Topic: [SOLVED]Set procedural skybox parameters during runtime  (Read 1671 times)

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
[SOLVED]Set procedural skybox parameters during runtime
« on: April 28, 2020, 03:55:37 AM »
Hey!

I want to change the skybox properties in runtime with an action. I found one shared in 2015 on this forum, but I can't get it to work. I also looked in the Ecosystem.

https://hutonggames.com/playmakerforum/index.php?topic=11310.0
« Last Edit: April 28, 2020, 08:43:31 AM by Caro »

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
Re: Set procedural skybox parameters during runtime
« Reply #1 on: April 28, 2020, 08:42:22 AM »
Okay I solved it. The script was missing a few things. It works for me now.

Set procedural skybox settings

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("Skybox")]
[Tooltip("Sets the material settings of a procedural skybox")]
public class SetProceduralSkyboxProperties : FsmStateAction
{
public Material ProceduralSkyBox;
[UIHint(UIHint.Variable)]
public FsmFloat SunSize;
[UIHint(UIHint.Variable)]
public FsmFloat AtmosphereThickness;
[UIHint(UIHint.Variable)]
public FsmColor SkyTint;
[UIHint(UIHint.Variable)]
public FsmColor GroundColor;
[UIHint(UIHint.Variable)]
public FsmFloat exposure;
public bool everyFrame;

public override void Reset()
{
ProceduralSkyBox = null;
everyFrame = false;
SunSize = null;
AtmosphereThickness = null;
SkyTint = null;
GroundColor = null;
exposure = null;
}

public override void OnEnter()
{

if (RenderSettings.skybox.shader.name != "Skybox/Procedural")
Finish ();

ProceduralSkyBox = RenderSettings.skybox;


if (ProceduralSkyBox != null)
{
if(!SunSize.IsNone)
{
ProceduralSkyBox.SetFloat("_SunSize",SunSize.Value);
}
if(!AtmosphereThickness.IsNone)
{
ProceduralSkyBox.SetFloat("_AtmosphereThickness",AtmosphereThickness.Value);
}
if(!SkyTint.IsNone)
{
ProceduralSkyBox.SetColor("_SkyTint",SkyTint.Value);
}
if(!GroundColor.IsNone)
{
ProceduralSkyBox.SetColor("_GroundColor",GroundColor.Value);
}
if(!exposure.IsNone)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure.Value);
}
}

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
if (ProceduralSkyBox != null)
{
if(!SunSize.IsNone)
{
ProceduralSkyBox.SetFloat("_SunSize",SunSize.Value);
}
if(!AtmosphereThickness.IsNone)
{
ProceduralSkyBox.SetFloat("_AtmosphereThickness",AtmosphereThickness.Value);
}
if(!SkyTint.IsNone)
{
ProceduralSkyBox.SetColor("_SkyTint",SkyTint.Value);
}
if(!GroundColor.IsNone)
{
ProceduralSkyBox.SetColor("_GroundColor",GroundColor.Value);
}
if(!exposure.IsNone)
{
ProceduralSkyBox.SetFloat("_Exposure",exposure.Value);
}
}
}

}
}