Calling scripts with VisualizerStudio

Calling scripts with VisualizerStudio

PostPosted by joms » Sat Feb 11, 2012 8:48 am

Hello,

When e.g. the bass hits, I want VisualizerStudio to call a script, or even better; a function within a script connected to a gameobject, for instance a camera.

I've been told that I have to use Message Trigger or Target Trigger to do this, but I cannot figure out how they work.

Any tips?

-JoMs
joms
 
Posts: 5
Joined: Sat Feb 11, 2012 8:39 am

Re: Calling scripts with VisualizerStudio

PostPosted by AlteredReality » Sat Feb 11, 2012 2:03 pm

First off, I want to apologize, as apparently there was a bug preventing VisTargetTrigger from working correctly. This was caused by a bug in VisTargetTriggerEditor.cs. A new version of the file is below...

Code: Select all
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System;

[CustomEditor(typeof(VisTargetTrigger))]
public class VisTargetTriggerEditor : VisBaseTriggerEditor
{
    public VisTargetTriggerEditor()
    {
        showAutomaticInspectorGUI = false;
    }

    protected override void CustomInspectorGUI()
    {
        base.CustomInspectorGUI();

        VisTargetTrigger trigger = target as VisTargetTrigger;
        if (trigger == null)
            return;

        int currentSize = trigger.targetGameObjects.Count;
        int newSize = Math.Abs(EditorGUILayout.IntField("\tNum Targets", currentSize));

        //remove excess or add new slots
        if (newSize == 0)
        {
            trigger.targetGameObjects.Clear();
        }
        else if (newSize < currentSize)
        {
            while (trigger.targetGameObjects.Count != newSize)
            {
                trigger.targetGameObjects.RemoveAt(trigger.targetGameObjects.Count - 1);
            }
        }
        else if (newSize > currentSize)
        {
            while (trigger.targetGameObjects.Count != newSize)
            {
                trigger.targetGameObjects.Add(null);
            }
        }

        //loop through all and edit
        for (int i = 0; i < trigger.targetGameObjects.Count; i++)
        {
            trigger.targetGameObjects[i] = (GameObject)EditorGUILayout.ObjectField("\t\tTarget #" + (i + 1).ToString(), trigger.targetGameObjects[i], typeof(GameObject), true);
        }
    }
}


Please replace your version of the file. I will also be pushing out an update for this shortly.

Once you have that new file, this is how you use it. Here is an example of a class implementing IVisTriggerTarget, which is needed to allow a VisTargetTrigger to interact with it.

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class TestTriggerTarget : IVisTriggerTarget
{   
    public void OnTriggered(float current, float previous, float difference, float adjustedDifference)
    {
        DoSomething();
    }

    public void DoSomething()
    {
        Debug.Log("I did something!");
    }
}


You will need to customize that class to do whatever you need it to do. Then you need to add that script to which ever game object that you want Visualizer Studio to trigger.

You will then need to create a "Target Trigger", and configure it to point at the proper Manager and Controller. And also make it point at your target game object as follows...

Image

And now whenever that trigger is "Triggered", it will call the "OnTriggered" function of TestTriggerTarget (it will find all IVisTriggerTarget interfaces on the game object or any children). There is where you need to do whatever it is you want to do.

Let me know if that helps you figure out your issue! Good luck!
Andy - Altered Reality
AlteredReality
Site Admin
 
Posts: 118
Joined: Fri Jan 06, 2012 8:31 pm

Re: Calling scripts with VisualizerStudio

PostPosted by joms » Sun Feb 12, 2012 7:29 am

I've set up everything like I have understood it. But still nothing's logged.

Firstly I updated the script, so that should be okey.
Then I added Vis Target Trigger to a cube, and set the same cube as the object to trigger.

I think the problem's in my script though. Tried to make one called TestTriggerTarget, so I could reuse your code 100% and then edit it from there. But when I pasted the code, it whined about class having to derive from MonoBehaviour (or something like that). Then I just added your class to the existing code, and called it TestTriggerTarget2 : IVisTriggerTarget.

Still nothing happens.

If you could make a samplescene, that would maybe be helpful, as I could use that for comparison.

-JoMs
joms
 
Posts: 5
Joined: Sat Feb 11, 2012 8:39 am

Re: Calling scripts with VisualizerStudio

PostPosted by AlteredReality » Sun Feb 12, 2012 2:11 pm

You are right, the script needs to also derive from MonoBehaviour as well, that was a mistake on my end. Here is the updated script...

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class TestTriggerTarget : MonoBehaviour, IVisTriggerTarget
{
    public void OnTriggered(float current, float previous, float difference, float adjustedDifference)
    {
        DoSomething();
    }

    public void DoSomething()
    {
        Debug.Log("I did something!");
    }
}


Just to verify I was able to get it to work, I went ahead and setup a simple game object to make sure this works, and it works fine for me. Here is a screen shot of the setup...

Image

For this example, I set the "Num Targets" to 1, and I selected "Target #1" as itself "TriggerTest". You can make it point to any game object that has the "Test Trigger Target" script on it, and it should call the OnTriggered function. Running this example on my machine, prints "I did something!" to the log every time the bass pulses.

Let me know if that helps.
Andy - Altered Reality
AlteredReality
Site Admin
 
Posts: 118
Joined: Fri Jan 06, 2012 8:31 pm

Re: Calling scripts with VisualizerStudio

PostPosted by joms » Sun Feb 12, 2012 4:12 pm

Seemed the code was wrong, your updated code fixed it :) Thanks!
joms
 
Posts: 5
Joined: Sat Feb 11, 2012 8:39 am


Return to Questions and Discussion

Who is online

Users browsing this forum: No registered users and 0 guests


Style by Gokinstudio | Free forum hosting by ProphpBB | Software by phpBB | Report Abuse | Privacy
cron