Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: giyomu on July 04, 2011, 08:27:48 PM

Title: GetMaterial ( only for beta 9 user ).
Post by: giyomu on July 04, 2011, 08: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

Code: [Select]
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..
Title: Re: GetMaterial ( only for beta 9 user ).
Post by: Alex Chouls on July 05, 2011, 08:00:16 AM
Awesome! I'm going to swipe these for the update ;D
Title: Re: GetMaterial ( only for beta 9 user ).
Post by: giyomu on July 05, 2011, 10:29:08 PM
Awesome! I'm going to swipe these for the update ;D

no problem alex swipe as you want  ;D