Skip to content

Simple BitGUI Integration

Easy way to connect with other extensions

Simple BitGUI Integration

Postby pax » 16 Apr 2011, 07:58

Today I spent an hour on the study bit-gui and wrote a simple Smart Block receiving mouse events from the any bit-gui control.
bit-gui link: http://code.google.com/p/bitverse-unity-gui/

SmartBlock code (Create new C# script and place it somewhere in the project or use attached file):
Syntax:
Using csharp Syntax Highlighting
using Antares.Vizio.Runtime;
using Bitverse.Unity.Gui;
using UnityEngine;

[VisualLogicBlock("Mouse Events","Bit GUI", ParentName = "Control")]
public class BitGUIMouseEventsBlock : LogicBlock
{
    [Parameter(VariableType.In, typeof(BitControl), Name = "Control")]
    public Variable control;

    [Parameter(VariableType.Out, typeof(int), Name = "Mouse Button")]
    public Variable mouseButton;

    [Parameter(VariableType.Out, typeof(Vector2), Name = "Mouse Position")]
    public Variable mousePosition;

    public override void OnInitializeDefaultData()
    {
        RegisterOutputTrigger("MouseClick");      //0
        RegisterOutputTrigger("MouseDoubleClick");//1
        RegisterOutputTrigger("MouseDown");       //2
        RegisterOutputTrigger("MouseDrag");       //3
        RegisterOutputTrigger("MouseEnter");      //4
        RegisterOutputTrigger("MouseExit");       //5
        RegisterOutputTrigger("MouseMove");       //6
        RegisterOutputTrigger("MouseStartDrag");  //7
        RegisterOutputTrigger("MouseUp");         //8
    }

    public override void Awake()
    {
        if (control.Value != null)
        {
            var bc = (BitControl)control.Value;
            bc.MouseClick += MouseClick;
            bc.MouseDoubleClick += MouseDoubleClick;
            bc.MouseDown += MouseDown;
            bc.MouseDrag += MouseDrag;
            bc.MouseEnter += MouseEnter;
            bc.MouseExit += MouseExit;
            bc.MouseMove += MouseMove;
            bc.MouseStartDrag += MouseStartDrag;
            bc.MouseUp += MouseUp;
        }
        else
        {
            BrokenBlocks.Add(this, "Control == null");
        }
    }


    public override void OnDestroy()
    {
        if (control.Value != null)
        {
            var bc = (BitControl)control.Value;
            bc.MouseClick -= MouseClick;
            bc.MouseDoubleClick -= MouseDoubleClick;
            bc.MouseDown -= MouseDown;
            bc.MouseDrag -= MouseDrag;
            bc.MouseEnter -= MouseEnter;
            bc.MouseExit -= MouseExit;
            bc.MouseMove -= MouseMove;
            bc.MouseStartDrag -= MouseStartDrag;
            bc.MouseUp -= MouseUp;
        }
    }

    public void MouseClick(object sender, MouseEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(0);
    }

    public void MouseDoubleClick(object sender, MouseEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(1);
    }

    public void MouseDown(object sender, MouseEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(2);
    }

    public void MouseDrag(object sender, MouseDragEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(3);
    }

    public void MouseEnter(object sender, UnityEngine.Vector2 mousePos)
    {
        mouseButton.Value = -1;
        mousePosition.Value = mousePos;
        ActivateTrigger(4);
    }

    public void MouseExit(object sender, UnityEngine.Vector2 mousePos)
    {
        mouseButton.Value = -1;
        mousePosition.Value = mousePos;
        ActivateTrigger(5);
    }

    public void MouseMove(object sender, UnityEngine.Vector2 mousePos)
    {
        mouseButton.Value = -1;
        mousePosition.Value = mousePos;
        ActivateTrigger(6);
    }

    public void MouseStartDrag(object sender, MouseDragEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(7);
    }

    public void MouseUp(object sender, MouseEventArgs e)
    {
        mouseButton.Value = e.MouseButton;
        mousePosition.Value = e.MousePosition;
        ActivateTrigger(8);
    }
   
}
 
Parsed in 0.028 seconds, using GeSHi 1.0.8.4



Usage:
  1. Import bit-gui and Universe packages.
  2. Add SB script to project.
  3. Create your GUI with bit-gui.
  4. Place SB to Universe graph.
  5. Drag any bit-gui control from hierarchy to SB input parameter
  6. Create event processing chunk

it generates next control events:
  • MouseClick
  • MouseDoubleClick
  • MouseDown
  • MouseDrag
  • MouseEnter
  • MouseExit
  • MouseMove
  • MouseStartDrag
  • MouseUp


If you like it - I will continue integration

upd: class name changed
Attachments
BitControlEvents.cs
(3.96 KiB) Downloaded 177 times
bit-gui-mouseEvents.png
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: Simple BitGUI Integration

Postby pSupaNova » 17 May 2011, 20:33

Just tried this with a button on a window worked like magic.
User avatar
pSupaNova
 
Posts: 15
Joined: 20 Feb 2011, 15:10

Re: Simple BitGUI Integration

Postby faarizamar » 14 Jan 2015, 04:38

Combining Antares Universe and Photon Unity Networking with VizioPUN, you will have a tool to create, see and understand how your network games function
faarizamar
 
Posts: 1
Joined: 14 Jan 2015, 04:37

Re: Simple BitGUI Integration

Postby Neodrop » 14 Jan 2015, 16:05

User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18


Return to Bridges

Who is online

Registered users: Bing [Bot]