playMaker

Author Topic: GetMaterial ( only for beta 9 user ).  (Read 2464 times)

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
GetMaterial ( only for beta 9 user ).
« 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..

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3634
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: GetMaterial ( only for beta 9 user ).
« Reply #1 on: July 05, 2011, 08:00:16 AM »
Awesome! I'm going to swipe these for the update ;D

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: GetMaterial ( only for beta 9 user ).
« Reply #2 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