// Update is called once per frame
    void Update()
    {
        if (!_texture)
        {
            _texture = videoRenderer.getWebCamTexture();
            //            Debug.Log(_texture.width);
        }
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit   hit;
            MeshCollider collie = videoRenderer.gameObject.GetComponentInChildren <MeshCollider>();

            if (!collie.Raycast(Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z)), out hit, 2000f))
            {
                return;
            }

            Renderer     rend         = hit.transform.GetComponent <Renderer>();
            MeshCollider meshCollider = hit.collider as MeshCollider;

            if (rend == null || meshCollider == null)
            {
                return;
            }

            Vector2 pixelUV = hit.textureCoord;
            pixelUV.x *= 1280f;
            pixelUV.y *= 720f;

            Color32 color = (Color32)_texture.GetPixel((int)pixelUV.x, (int)pixelUV.y);
            ctp.colorTargets.Add(new Vexpot.ColorTarget(color, tolerance));
            ctp.StopColorTracker();
            ctp.UpdateColorTargets();
            ctp.StartColorTracker();

            _factory.CreateUnit(color);
            _constructor.ColorSelected(color);
        }

        if (Input.GetMouseButtonDown(0))
        {
            UnitGroup ug = null;
            if (_gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))) != null)
            {
                ug = _gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)));
            }
            if (ug != null)
            {
                _constructor.SetActiveUnit(ug.gameObject, true);
                _logController.updateStats(ug.info);
            }
        }
    }
Ejemplo n.º 2
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);
        }
    }