Skip to content

My First Smart Block - Set Material Color

User created LBs

My First Smart Block - Set Material Color

Postby SamSam » 06 Apr 2011, 16:02

Hello,
Thanks to Pax, here is the code of a simple Vizio LogicBlock that will act as a "Set Material Color" action.

Using Universe blocks you can change the material color of an object this way :
Image


With the following Vizio LogicBlock script all the operation done above are done in a single LogicBlock
Image


This script will create a "My Actions" section in the "Smart Blocks" toolbar.
Under "My Actions" you'll find the "My Set Color" LogicBlock.
Image

Please refer to the Vizio LogicBlock Programming Guide in the Documentation section of this board for further explanation on how to make your own Vizio LogicBlock.

Now we need to make a lot of scripts like this one to make the Universe more friendly to non coder, artist etc.

Syntax:
Using csharp Syntax Highlighting
using UnityEngine;
using Antares.Vizio.Runtime;

[VisualLogicBlock("My Set Color", "My Actions")]
public class MySetColor : LogicBlock
{


    [Parameter(VariableType.In, typeof(Color))]
    public Variable c;

    [Parameter(VariableType.Out, typeof(string))]
    public Variable error;

    public override void OnInitializeDefaultData()
    {
        RegisterOutputTrigger("Exit");
        RegisterOutputTrigger("Error");
    }

    [EntryTrigger]
    public void In()
    {
        //Check if GameObject has Renderer component
        if (Component.renderer == null)
        {
            error.Value = "This GameObject has no Renderer Component";
            ActivateTrigger("Error");
            return;
        }


        //Check if GameObject Renderer has material
        if (Component.renderer.material == null)
        {
            error.Value = "This GameObject has no Material applied";
            ActivateTrigger("Error");
            return;
        }


        //Set Material Color
        Component.renderer.material.color = (Color)c.Value;

        //Output Trigger
        ActivateTrigger("Exit");
    }
}
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
SamSam
 
Posts: 25
Joined: 06 Apr 2011, 15:24

Re: My First Smart Block - Set Material Color

Postby pax » 06 Apr 2011, 16:14

@SamSam
Thanks!
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: My First Smart Block - Set Material Color

Postby Viziopleasure » 06 Apr 2011, 19:55

Cool!
Yesterday I started working on my own Blocks too. It is for basic integration with PlayMaker.
Soon I post something too :)

Still learning both tools and what they can and "can't" to do.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08


Return to Smart Blocks

Who is online

Registered users: No registered users