示例#1
0
    private void Connect()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (_tuioServer != null)
        {
            Disconnect();
        }
        if (Instance != null)
        {
            throw new UnityException("不允许多个单例");
        }
        Instance = this;

        _tuioServer = new TuioServer(port);

        _waitForEndOfFrame = new WaitForEndOfFrame();
        _coroutine         = StartCoroutine(EndFrame());
        Debug.Log("TUIO Port" + port);
        _tuioServer.Connect();
        Debug.Log("TUIO Connect");
    }
示例#2
0
 private void Disconnect()
 {
     if (_tuioServer != null)
     {
         _tuioServer.RemoveAllDataProcessors();
         _tuioServer.Disconnect();
         _tuioServer        = null;
         _waitForEndOfFrame = null;
         if (_coroutine != null)
         {
             StopCoroutine(_coroutine);
         }
         _coroutine = null;
         Instance   = null;
     }
 }
示例#3
0
    void Start()
    {
        m_tokenPosition = TokenPosition.Instance;
        m_settings      = Settings.Instance;

        markersOnGrid = new List <int>();

        redMarkers   = new List <GameObject>();
        greenMarkers = new List <GameObject>();
        blueMarkers  = new List <GameObject>();

        red   = m_settings.red;
        blue  = m_settings.blue;
        green = m_settings.green;
        grey  = m_settings.grey;

        addedTuioObjects   = new List <TuioObject>();
        removedTuioObjects = new List <TuioObject>();
        updatedTuioObjects = new List <TuioObject>();

        addedTuioObjectsI   = new List <TuioObject>();
        removedTuioObjectsI = new List <TuioObject>();
        updatedTuioObjectsI = new List <TuioObject>();

        activeMarkersOnGrid      = new GameObject[m_settings.beats];
        activeREDMarkersOnGrid   = new GameObject[m_settings.beats];
        activeGREENMarkersOnGrid = new GameObject[m_settings.beats];
        activeBLUEMarkersOnGrid  = new GameObject[m_settings.beats];

        //add this class to the callback list of the client
        m_tuiomanager = TuioManager.Instance;
        TuioClient m_tuioClient = m_tuiomanager.GetTuioClient();

        m_tuioClient.addTuioListener(this);

        //get all markers in the game
        GameObject[] markersArray = GameObject.FindGameObjectsWithTag(m_settings.markerTag);
        //fills dictionary with markers for later easier access (MarkerID as key)
        markers      = new Dictionary <int, GameObject>();
        currentTunes = new Dictionary <int, int>();
        foreach (GameObject marker in markersArray)
        {
            int id = marker.GetComponent <FiducialController>().MarkerID;
            markers.Add(id, marker);
            currentTunes.Add(id, 0);
        }
    }
    void Start()
    {
        m_settings = Settings.Instance;
        GameObject[] loopMarkers = GameObject.FindGameObjectsWithTag(m_settings.loopMarkerTag);
        int          counter     = 0;

        foreach (GameObject loopMarker in loopMarkers)
        {
            if (loopMarker.GetComponent <LoopController>().startMarker)
            {
                counter++;
            }

            //save other LoopMarker
            if (loopMarker.GetComponent <LoopController>().startMarker != this.startMarker)
            {
                otherLoopMarker = loopMarker;
            }

            if (counter > 1)
            {
                Debug.LogError("More than one Loop Start Gameobject defined. Must be exactely one.");
                break;
            }
        }
        if (counter == 0)
        {
            Debug.LogError("No Loop Start GameObject defined. Must be exactely one.");
        }

        if (ghostPrefab == null)
        {
            Debug.LogError("No ghost prefab defined.");
        }

        m_tuioManager        = TuioManager.Instance;
        m_tokenPosition      = TokenPosition.Instance;
        m_locationBar        = FindObjectsOfType <LocationBar>()[0];
        m_fiducialController = this.GetComponent <FiducialController>();
        transform.position   = new Vector3(startMarker ? m_tokenPosition.GetXPosForBeat(0) : m_tokenPosition.GetXPosForBeat(16), transform.position.y, transform.position.z);
        newPos = transform.position;
    }
    public TokenPosition()
    {
        if (m_Instance != null)
        {
            Debug.LogError("Trying to create two instances of singleton.");
            return;
        }

        m_Instance = this;

        //init variables
        m_tuioManager       = TuioManager.Instance;
        m_settings          = Settings.Instance;
        m_lastComeLastServe = GameObject.FindObjectOfType <LastComeLastServe>();
        m_MainCamera        = GameObject.FindGameObjectWithTag(m_settings.mainCameraTag).GetComponent <Camera>();

        beats = m_settings.beats;
        tunes = m_settings.tunes;

        //variables in world coordinates
        widthOffsetInPx         = m_settings.widthOffSetInPx;
        heightOffsetInPx_top    = m_settings.heightOffSetInPx_top;
        heightOffsetInPx_bottom = m_settings.heightOffSetInPx_bottom;
        minWorldCoords          = m_settings.minWorldCoords;
        maxWorldCoords          = m_settings.maxWorldCoords;
        worldDiff = m_settings.worldDiff;

        //calculate snapping grid
        gridHeightInPx = m_settings.gridHeightInPx;
        gridWidthInPx  = m_settings.gridWidthInPx;
        cellHeightInPx = m_settings.cellHeightInPx;
        cellWidthInPx  = m_settings.cellWidthInPx;
        cellSizeWorld  = m_settings.cellSizeWorld;

        movementThreshold = m_settings.movementThreshold;
    }