I'm trying to do some basic code testing here with the new UI and Makinom.

(On UI button click, start schematic) is what I want to accomplish.

This is how I picture it being set up, but this does not work.
using UnityEngine;
using Makinom;
using UnityEngine.UI;
using System.Collections;

public class ClickExample : MonoBehaviour
{
public Button yourButton;
public MakinomSchematicAsset schematicAsset; //define schematic

void Start()
{
Schematic schematic = new Schematic(this.schematicAsset); //load schematic
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}

void TaskOnClick()
{
Debug.Log("You have clicked the button!");
schematic.PlaySchematic(null, machineObject, startObject, false, MachineUpdateType.Update); //execute schematic
}
}
I'm familiar with doing things in just Makinom, but I'm new to coding with Makinom so any help is greatly appreciated.

Thanks,
-Nate =]
Awesome Website - Portfolio
Support me on Patreon - Support site
  • AFAIK this can be done using an interaction machine component within Makinom.
    It has the capabilities to initialize the local variables of the schematic it starts to defined values.
    I see you'd wish to do this in raw code instead, however I'd like to know what the advantages are in coding it versus utilizing an interaction machine (Setting them in the machine allows reusing the schematic with different start variables, doing different things or behaving differently.) Is it because you'd wish to have minimal bloat at runtime?

    Will Makinom discard unused code from machines during a build, else include everything when compiled even though its not fully in use resulting in bloated code?
  • The best machine to use with events coming from new UI components (e.g. a button) would be the animation machine, which e.g. has the UI game object start type, but you can also use any of the animation event start types.

    As for starting a schematic via code, what you're doing seems to be correct :)


    @kwiknip
    All of Makinom's code will be included when building the game, i.e. all code for the different nodes as well.
    However, the schematics aren't code, they're just saved settings for the nodes they use - and since schematics are assets, Unity will only add those to your build that are actually used somewhere (e.g. in a scene or in the Makinom project).
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
  • @gamingislove
    1. I did not know the animation machine had the new UI game object start type.
    That helps a bunch.
    Guess I won't have to hard code after all. lol
    But just for a learning experience would it be possible to make a simple short tutorial on starting a schematic with code?
    In the example code I originally posted it is giving me errors.
    If you could make a real short example in this Starting a Schematic via Script tutorial section that would be really awesome.

    2. Is there a Node to check if a UI button was pressed?


    @kwiknip
    I'm just trying something new with Makinom and I really want to dive more into the coding side of things. Makinom is already powerful as is but there is so much more I'd like to learn.

    Cheers,
    -Nate =]
    Awesome Website - Portfolio
    Support me on Patreon - Support site
  • @gamingislove, @relenting_1, Very informative and good to know, thanks!
  • 1) Well, you'll naturally need a machineObject and startingObject when you're using them to call PlaySchematic. Or pass null for them if you don't need them.

    2) No, and there isn't even anything on the Button component to check that, you'll have to hook up to the button's on click event (e.g. with an animation machine).
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.