Skip to content

Unity message receiver.

User created LBs

Unity message receiver.

Postby Neodrop » 24 Apr 2014, 11:05

Add this file to your project.
Select node "Smart Blocks/Unity Messages/ Unity Message Receiver" and add to your graph.
To receive Unity Message in your graph, call UnityMessage1(till 10) for message without parameters or UnityMessageData1(till 10) for message with some parameter by "Messaging/Unity Messages/SendMessage/Send Message" node or right from your code.
Example of usage here.

UniverseUnityMessageReceiver.cs
Add this file to your project.
(5.81 KiB) Downloaded 87 times


Syntax:
Using csharp Syntax Highlighting
// Created by Neodrop

using UnityEngine;
using Antares.Vizio.Runtime;

public class UniverseUnityMessageReceiver : MonoBehaviour {

    void UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName mName)
    {
        var vizio = GetComponent<VizioComponent>();
        foreach (var block in vizio.logicBlocks)
        {
            if (block.Value.GetType() == typeof (UniverseUnityMessageReceiverNode))
            {
                UniverseUnityMessageReceiverNode receiver = block.Value as UniverseUnityMessageReceiverNode;
                if(receiver.messageName == mName)
                    receiver.ActivateTrigger();
            }
        }
    }

    void UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName mName, object data)
    {
        var vizio = GetComponent<VizioComponent>();
        foreach (var block in vizio.logicBlocks)
        {
            if (block.Value.GetType() == typeof(UniverseUnityMessageReceiverNode))
            {
                UniverseUnityMessageReceiverNode receiver = block.Value as UniverseUnityMessageReceiverNode;
                if (receiver.messageName == mName)
                {
                    receiver.messageValue.Value = data;
                    receiver.ActivateTrigger(1);
                }
            }
        }
    }

    void UnityMessage1()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage1);
    }

    void UnityMessageData1(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData1, data);
    }

    void UnityMessage2()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage2);
    }

    void UnityMessageData2(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData2, data);
    }

    void UnityMessage3()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage3);
    }

    void UnityMessageData3(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData3, data);
    }

    void UnityMessage4()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage4);
    }

    void UnityMessageData4(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData4, data);
    }

    void UnityMessage5()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage5);
    }

    void UnityMessageData5(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData5, data);
    }

    void UnityMessage6()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage6);
    }

    void UnityMessageData6(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData6, data);
    }

    void UnityMessage7()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage7);
    }

    void UnityMessageData7(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData7, data);
    }

    void UnityMessage8()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage8);
    }

    void UnityMessageData8(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData8, data);
    }

    void UnityMessage9()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage9);
    }

    void UnityMessageData9(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData9, data);
    }

    void UnityMessage10()
    {
        UnityMessageEmpty(UniverseUnityMessageReceiverNode.MessageName.UnityMessage10);
    }

    void UnityMessageData10(object data)
    {
        UnityMessageParams(UniverseUnityMessageReceiverNode.MessageName.UnityMessageData10, data);
    }
}

[VisualLogicBlockDescription("To receive Unity Message in your graph, call UnityMessage1(till 10) for message without parameters or UnityMessageData1(till 10) for message with some parameter", Url = "http://forum.antares-universe.com/unity-message-receiver--t902.html")]
[VisualLogicBlock("Unity Message Receiver", "Unity Messages")]
public class UniverseUnityMessageReceiverNode : LogicBlock
{
    public enum MessageName
    {
        UnityMessage1,
        UnityMessage2,
        UnityMessage3,
        UnityMessage4,
        UnityMessage5,
        UnityMessage6,
        UnityMessage7,
        UnityMessage8,
        UnityMessage9,
        UnityMessage10,
        UnityMessageData1 = 101,
        UnityMessageData2 = 102,
        UnityMessageData3 = 103,
        UnityMessageData4 = 104,
        UnityMessageData5 = 105,
        UnityMessageData6 = 106,
        UnityMessageData7 = 107,
        UnityMessageData8 = 108,
        UnityMessageData9 = 109,
        UnityMessageData10 = 110
    }

    [Parameter(VariableType.In, typeof(MessageName))]
    public Variable messageType;

    [Parameter(VariableType.Out, typeof(object))]
    public Variable messageValue;

    public MessageName messageName;

    public override void OnInitializeDefaultData()
    {
        RegisterOutputTrigger("UnityMessageEmpty Received");
        RegisterOutputTrigger("UnityMessageParams Received");
        var receiver = this.Component.GetComponent<UniverseUnityMessageReceiver>();
        if(receiver == null)
            this.Component.gameObject.AddComponent<UniverseUnityMessageReceiver>();
    }

    public override void Awake()
    {
        messageName = (MessageName)messageType.Value;
    }
}

 
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: Unity message receiver.

Postby ren072 » 24 Apr 2014, 12:38

Working great!
Thanks a lot Neo for your SmartBlock.
Now, if you still have some spare time ( :lol: ), it would be nice to have the option to receive messages names other than "UnityMessage1", "UnityMessage2",...
Anyway, thanks a lot!
See here for visual exemple:
http://forum.antares-universe.com/-t254s15.html#p3145
ren072
 
Posts: 154
Joined: 21 Jun 2011, 14:00
Location: Belgium


Return to Smart Blocks

Who is online

Registered users: No registered users