Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: giyomu on July 04, 2011, 11:27:48 PM
-
Hi all , just wanted to add couple action i see missing with the new addition of material and texture variable.
So first one is get a material ^^ and store it
here we go
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Material)]
[Tooltip("Get a material at index on a gameObject and store it in a variable")]
public class GetMaterial : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Renderer))]
public FsmOwnerDefault gameObject;
public FsmInt materialIndex;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmMaterial material;
[Tooltip("either pick an instance of the mat or not")]
public bool getSharedMaterial;
public override void Reset()
{
gameObject = null;
material = null;
materialIndex = 0;
getSharedMaterial = false;
}
public override void OnEnter ()
{
DoGetMaterial();
Finish();
}
void DoGetMaterial()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
return;
if (go.renderer == null)
{
LogError("Missing Renderer!");
return;
}
if (materialIndex.Value == 0 && !getSharedMaterial)
material.Value = go.renderer.material;
else if(materialIndex.Value == 0 && getSharedMaterial)
material.Value = go.renderer.sharedMaterial;
else if (go.renderer.materials.Length > materialIndex.Value && !getSharedMaterial)
{
var materials = go.renderer.materials;
material.Value = materials[materialIndex.Value];
go.renderer.materials = materials;
}
else if (go.renderer.materials.Length > materialIndex.Value && getSharedMaterial)
{
var materials = go.renderer.sharedMaterials;
material.Value = materials[materialIndex.Value];
go.renderer.sharedMaterials = materials;
}
}
}
note that without using sharedMaterial you will get an instance of it , so regarding what you want to do check that option on or off.
more to come..
-
Awesome! I'm going to swipe these for the update ;D
-
Awesome! I'm going to swipe these for the update ;D
no problem alex swipe as you want ;D