/// <summary>
        ///  Request new tracker results when new frame is available.
        /// </summary>
        public virtual void OnPostRender()
        {
            if (colorTrackerPanel != null && colorTrackerPanel.GetColorTracker() != null)
            {
                ColorTracker tracker = colorTrackerPanel.GetColorTracker();
                if (tracker == null)
                {
                    return;
                }

                List <TrackerResult> colorTrackerResults = tracker.Compute();

                CreateObjectsIfNeeded(colorTrackerResults.Count);

                for (var t = 0; t < colorTrackerResults.Count; t++)
                {
                    TrackerResult r = colorTrackerResults[t];

                    if (r.state == TrackingState.Tracked)
                    {
                        CoordinateMapper.ConvertInputToScreen(tracker.input, r.center, ref _reusablePosition);
                        _reusablePosition.z = perspectiveCamera.nearClipPlane + _scaleRatio - Mathf.Clamp(_reusablePosition.z, 0.0f, 0.8f);

                        _targets[t].transform.position = perspectiveCamera.ScreenToWorldPoint(_reusablePosition);
                        _targets[t].SetActive(true);
                    }
                    else
                    {
                        _targets[t].SetActive(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Activate(Color[] pixels)
 {
     tracker = new ColorTracker[pixels.Length];
     for (int i = 0; i < tracker.Length; ++i)
     {
         tracker[i] = new ColorTracker(35 * i);
     }
 }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        if (tracker != null)
        {
            basecolor = (ColorTracker)tracker.GetComponent(typeof(ColorTracker));
        }

        Recolor(color);
    }
Ejemplo n.º 4
0
    void Start()
    {
        shift = false;

        if (tracker != null)
        {
            basecolor = (ColorTracker)tracker.GetComponent(typeof(ColorTracker));
        }

        Create(color);
    }
Ejemplo n.º 5
0
    void Start()
    {
        ready = true;

        if (tracker != null)
        {
            basecolor = (ColorTracker)tracker.GetComponent(typeof(ColorTracker));
        }

        Create(color);
    }
        void OnPostRender()
        {
            if (!trackerPanel)
            {
                return;
            }

            _tracker = trackerPanel.GetColorTracker();

            if (_tracker == null || Camera.main == null)
            {
                return;
            }

            if (!_tracker.isRunning)
            {
                DestroyPreviousGraphics();
                return;
            }

            List <TrackerResult> result = _tracker.Compute();

            if (_graphics.Count != result.Count)
            {
                DestroyPreviousGraphics();
                CreateNewGraphics(result.Count);
            }

            for (var i = 0; i < result.Count; i++)
            {
                GameObject    actual = _graphics[i];
                TrackerResult target = result[i];
                if (target.state == TrackingState.Tracked)
                {
                    CoordinateMapper.ConvertInputToScreen(_tracker.input, target.center, ref _reusableScreenPosition);
                    CoordinateMapper.ConvertScreenToUI(_reusableScreenPosition, actual.GetComponent <RectTransform>());
                    actual.SetActive(true);
                }
                else
                {
                    actual.SetActive(false);
                }
            }
        }
Ejemplo n.º 7
0
        void Awake()
        {
            switch (inputType)
            {
            case InputType.WebCam: _selectedInput = new WebCamInput(); break;

            case InputType.Screen: _selectedInput = new ScreenInput(); break;
            }

            _tracker = new ColorTracker(_selectedInput);
            _tracker.colorTargets = colorTargets;
            _tracker.accuracy     = accuracy;
            _tracker.listener     = this;

            if (playOnAwake)
            {
                _tracker.Start();
            }
        }
        private void UpdateEventsAndRaycast()
        {
            if (colorTrackerPanel == null)
            {
                return;
            }
            ColorTracker tracker = colorTrackerPanel.GetColorTracker();

            if (tracker == null)
            {
                return;
            }

            List <TrackerResult> colorTrackerResults = tracker.GetLatestResult();

            AllocatePointerDataIfNeeded(colorTrackerResults);

            for (var t = 0; t < colorTrackerResults.Count; t++)
            {
                PointerEventData current = _pointerData[t];
                current.Reset();
                TrackerResult r = colorTrackerResults[t];

                if (r.state == TrackingState.Tracked)
                {
                    CoordinateMapper.ConvertInputToScreen(tracker.input, r.center, ref _reusablePosition);
                }
                else
                {
                    _reusablePosition.Set(-150, -150, 0);
                }

                current.position = _reusablePosition;
                current.delta    = r.linearVelocity;
                eventSystem.RaycastAll(current, m_RaycastResultCache);
                current.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache);
                UpdateHoverAndExit(current);
                HandleTrigger(current);
                m_RaycastResultCache.Clear();
            }
        }
Ejemplo n.º 9
0
 public void Activate(Color[] pixels)
 {
     tracker = new ColorTracker[pixels.Length];
     for (int i = 0; i < tracker.Length; ++i)
         tracker[i] = new ColorTracker(35 * i);
 }
Ejemplo n.º 10
0
    public override void OnInspectorGUI()
    {
        //DrawDefaultInspector();
        _targetsChanged = 0;
        _content        = (ColorTrackerPanel)target;
        _colorTargets   = _content.colorTargets;

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Options", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();

        GUI.enabled        = !Application.isPlaying;
        _content.inputType = (InputType)EditorGUILayout.EnumPopup("Input", _content.inputType);
        _content.accuracy  = (TrackerAccuracy)EditorGUILayout.EnumPopup("Accuracy", _content.accuracy);

        GUI.enabled = true;
        _content.enableColorTrack = EditorGUILayout.Toggle(enableColorTrackDescription, _content.enableColorTrack);

        if (_content.enableColorTrack)
        {
            _content.useKalmanFilter = EditorGUILayout.Toggle(kalmanDescription, _content.useKalmanFilter);
        }

        _content.enableColorMap = EditorGUILayout.Toggle(enableColorMapDescription, _content.enableColorMap);

        if (_content.enableColorMap)
        {
            _content.colorMapPointSpacing = EditorGUILayout.IntField(pointSpacingDescription, _content.colorMapPointSpacing);
        }

        GUI.enabled          = (_content.enableColorTrack || _content.enableColorMap);
        _content.playOnAwake = EditorGUILayout.Toggle(playOnAwakeDescription, _content.playOnAwake);

        EditorGUILayout.Separator();

        serializedObject.Update();
        list.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.LabelField("Controls", EditorStyles.boldLabel);

        GUILayout.BeginHorizontal();

        ColorTracker tracker         = _content.GetColorTracker();
        bool         controlsEnabled = tracker != null;

        GUI.enabled = controlsEnabled && !tracker.isRunning;
        if (GUILayout.Button("Start", GUILayout.Height(30)))
        {
            _content.StartColorTracker();
        }

        GUI.enabled = controlsEnabled && tracker.isRunning;
        if (GUILayout.Button("Stop", GUILayout.Height(30)))
        {
            _content.StopColorTracker();
        }

        GUI.enabled = _colorTargets.Count > 0;
        if (GUILayout.Button("Remove all targets", GUILayout.Height(30)))
        {
            _colorTargets.Clear();
            OnChangedHandler(null);
        }

        if (_targetsChanged > 0 && Application.isPlaying)
        {
            _content.UpdateColorTargets();
        }

        GUILayout.EndHorizontal();
        GUI.enabled = true;
        EditorGUILayout.Separator();

        if (_colorTargets.Count == 0)
        {
            EditorGUILayout.HelpBox("You must add at least one target!", MessageType.Error);
        }

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(target);
        }
    }
Ejemplo n.º 11
0
    public virtual void Start()
    {
        time   = 0;
        locked = true;

        m_Animator = gameObject.GetComponent <Animator>();


        if (tracker != null)
        {
            basecolor = (ColorTracker)tracker.GetComponent(typeof(ColorTracker));
            if (basecolor == null)
            {
                Debug.Log("not in color");
            }
        }

        if (master != null)
        {
            puzzleboss = (PuzzleSystem)master.GetComponent(typeof(PuzzleSystem));
            if (puzzleboss == null)
            {
                Debug.Log("why though");
            }
        }



        if (square1 != null)
        {
            script1 = (TerrainSystem)square1.GetComponent(typeof(TerrainSystem));
        }
        if (square2 != null)
        {
            script2 = (TerrainSystem)square2.GetComponent(typeof(TerrainSystem));
        }
        if (square3 != null)
        {
            script3 = (TerrainSystem)square3.GetComponent(typeof(TerrainSystem));
        }
        if (square4 != null)
        {
            script4 = (TerrainSystem)square4.GetComponent(typeof(TerrainSystem));
        }
        if (square5 != null)
        {
            script5 = (TerrainSystem)square5.GetComponent(typeof(TerrainSystem));
        }
        if (square6 != null)
        {
            script6 = (TerrainSystem)square6.GetComponent(typeof(TerrainSystem));
        }
        if (square7 != null)
        {
            script7 = (TerrainSystem)square7.GetComponent(typeof(TerrainSystem));
        }
        if (square8 != null)
        {
            script8 = (TerrainSystem)square8.GetComponent(typeof(TerrainSystem));
        }

        //Additional();
    }
Ejemplo n.º 12
0
 /// <summary>
 /// Implements <see cref="ITrackerEventListener.WhenNewResultAvailable(ColorTracker)"/> interface.
 /// </summary>
 public void WhenNewResultAvailable(ColorTracker tracker)
 {
     // do something here
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Implements <see cref="ITrackerEventListener.TrackerDidStop(ColorTracker)"/> interface.
 /// </summary>
 public void TrackerDidStop(ColorTracker tracker)
 {
     // do something here
 }