Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: KirbyRawr on October 20, 2013, 06:01:11 AM

Title: Enable or disable shadows on a gameObject
Post by: KirbyRawr on October 20, 2013, 06:01:11 AM
Hi, i saw there isn't any action like this so i wrote a new one, this is my first custom action ^w^.

(https://dl.dropboxusercontent.com/s/x5mah0t54zi81bx/CastShadows.png?token_hash=AAFf7NsWBahlCeETIoX3pOXFwrMoDxkMpMFgUQ7K824wPg&dl=1)
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
// CastShadows.cs
// Custom Action made by KirbyRawr from OverflowingStudios.com

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Lights)]
[Tooltip("Enable or disable shadows")]
public class CastShadows : FsmStateAction
{
public FsmGameObject gameObject;
public FsmBool skinnedMesh;
[Tooltip("Cast Shadows")]
public FsmBool castShadows;
[Tooltip("Receive Shadows")]
public FsmBool receiveShadows;

public override void Reset()
{
gameObject = null;
castShadows = false;
receiveShadows = false;

}

public override void OnEnter()
{
if(skinnedMesh.Value==true){
gameObject.Value.GetComponent<SkinnedMeshRenderer>().castShadows = castShadows.Value;
gameObject.Value.GetComponent<SkinnedMeshRenderer>().receiveShadows = receiveShadows.Value;
}

if(skinnedMesh.Value==false){
gameObject.Value.GetComponent<MeshRenderer>().castShadows = castShadows.Value;
gameObject.Value.GetComponent<MeshRenderer>().receiveShadows = receiveShadows.Value;
}
}

    }
}
Title: Re: Enable or disable shadows on a gameObject
Post by: jeanfabre on October 21, 2013, 02:10:26 AM
Hi,

 Very good! Also, don't forget that you can access all these publich properties using the "Set property" action. Simply Drag the "mesh renderer" component onto the action stack and you will be able to pick the various properties, including shadow casting and receiving.

bye,

 Jean

Title: Re: Enable or disable shadows on a gameObject
Post by: KirbyRawr on October 21, 2013, 07:53:31 AM
Hi,

 Very good! Also, don't forget that you can access all these publich properties using the "Set property" action. Simply Drag the "mesh renderer" component onto the action stack and you will be able to pick the various properties, including shadow casting and receiving.

bye,

 Jean
Oh, thanks Jean i didn't know it ^^!
Title: Re: Enable or disable shadows on a gameObject
Post by: jeanfabre on October 21, 2013, 08:08:24 AM
Hi,

 That's fine! It's anyway more advantagous to use proper custom action, as it doesn't use reflection and therefore, more performant. So it's good that you have the skills to procude custom actions! not everything is accessible via Get/set property, especially, anything static.


bye,

 Jean
Title: Re: Enable or disable shadows on a gameObject
Post by: KirbyRawr on October 21, 2013, 08:09:40 AM
Added support for Skinned Mesh Renderer!  :)

PD: i just saw your another reply haha, thanks anyways! ^^
Title: Re: Enable or disable shadows on a gameObject
Post by: misterlee on January 06, 2017, 06:23:25 PM
This is just what I was looking for.... except 'castShadows' is deprecated now and we have to use ShadowCastingMode instead.

I made a modification, it works but I don't know if it's the best way of doing it. I'm not much of a programmer (hence using PlayMaker!)

Code: [Select]
public override void OnEnter()
{
if(skinnedMesh.Value==true){

gameObject.Value.GetComponent<SkinnedMeshRenderer>().receiveShadows = receiveShadows.Value;

if (castShadows.Value == true) {
gameObject.Value.GetComponent<SkinnedMeshRenderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
} else {
gameObject.Value.GetComponent<SkinnedMeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
if(skinnedMesh.Value==false){

gameObject.Value.GetComponent<MeshRenderer>().receiveShadows = receiveShadows.Value;

if (castShadows.Value == true) {
gameObject.Value.GetComponent<SkinnedMeshRenderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
} else {
gameObject.Value.GetComponent<SkinnedMeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
}



p.s. Just discovered you need to put Finish(); at the end too, otherwise it gets stuck in that state and doesn't move on.