public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        _stylusSelector = (ZSStylusSelector)this.target;
        bool isSceneObject = !EditorUtility.IsPersistent(_stylusSelector);
        _stylusSelector.activeStylus = (ZSStylusShape)EditorGUILayout.ObjectField("Active Stylus", _stylusSelector.activeStylus, typeof(ZSStylusShape), isSceneObject);
        EditorUtility.SetDirty(_stylusSelector);
    }
 // Use this for initialization
 void Start()
 {
     if (!GameData.zSpace)
     {
         stylus = null;
         GameObject core = GameObject.FindGameObjectWithTag("zscore");
         Destroy(core);
     }
 }
 void Start()
 {
     resetting = false;
     firstTurn = true;
     oldPos    = 0;
     if (!GameData.zSpace)
     {
         stylus = null;
         GameObject core = GameObject.FindGameObjectWithTag("zscore");
         Destroy(core);
     }
 }
Exemple #4
0
    /// <summary>
    /// This function is called by ZSCore after each input update.
    /// </summary>
    private void OnCoreUpdated(ZSCore sender)
    {
        if (sender != _zsCore)
        {
            return;
        }

        //Update stylus button states.
        for (int i = 0; i < numButtons; ++i)
        {
            _wasStylusButtonPressed [i] = _isStylusButtonPressed [i];
            _wasMouseButtonPressed [i]  = _isMouseButtonPressed [i];

            //Have to combine mouse state down here so asynchronous clients see it at the right time.
            _isStylusButtonPressed [i] = !_zsCore.IsMouseEmulationEnabled() && _zsCore.IsTrackerTargetButtonPressed(ZSCore.TrackerTargetType.Primary, i);
            _isMouseButtonPressed [i]  = Input.GetMouseButton(i);
        }

        bool useMousePointer = false;

        if (_useTracking && !_zsCore.IsMouseEmulationEnabled())
        {
            Matrix4x4 pose = _zsCore.GetTrackerTargetWorldPose(_targetType);
            if (pose != _previousStylusPose)
            {
                _timeSinceStylusMoved = 0f;
            }
            else
            {
                _timeSinceStylusMoved += Time.deltaTime;
            }

            useMousePointer = _timeSinceStylusMoved > StylusTimeout;
            if (!useMousePointer)
            {
                _previousStylusPose  = pose;
                transform.localScale = ZSStylusSelector.GetScale(pose);
                transform.rotation   = ZSStylusSelector.GetRotation(pose);
                transform.position   = ZSStylusSelector.GetPosition(pose);

                transform.localScale = _zsCore.GetViewerScale() * Vector3.one;
            }
        }

        //Simulate the stylus based on mouse input.

        Vector3 dMousePosition = Input.mousePosition - _lastMousePosition;

        dMousePosition [2] = WheelSensitivity * Input.GetAxis("Mouse ScrollWheel");
        if (Input.GetKey(KeyCode.LeftBracket))
        {
            dMousePosition [2] -= WheelSensitivity * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightBracket))
        {
            dMousePosition [2] += WheelSensitivity * Time.deltaTime;
        }

        Camera mainCamera = (_zsCore.IsStereoEnabled()) ? _centerCamera : _zsCore.CurrentCamera.camera;

        if (useMousePointer && mainCamera != null && mainCamera.enabled)
        {
            if (stylusSimulatorMode == StylusSimulatorMode.Projection || stylusSimulatorMode == StylusSimulatorMode.Position)
            {
                //Only update the wheel total if we aren't rotating.  Avoids extra Z translation artifact.
                _mouseWheel += dMousePosition [2];
                Ray     ray      = mainCamera.ScreenPointToRay(Input.mousePosition);
                Vector3 rayPoint = ray.GetPoint(0.1f + 0.5f * _mouseWheel * mainCamera.transform.localScale.magnitude);
                transform.position = rayPoint;

                if (stylusSimulatorMode == StylusSimulatorMode.Projection)
                {
                    transform.rotation = Quaternion.LookRotation(ray.GetPoint(1.0f) - mainCamera.transform.position, mainCamera.transform.up);
                }
            }
            else if (stylusSimulatorMode == StylusSimulatorMode.Rotation)
            {
                Vector3 euler = transform.localRotation.eulerAngles;
                euler += new Vector3(-0.1f * dMousePosition.y, 0.1f * dMousePosition.x, -1000.0f * dMousePosition.z);
                var oldHoverPoint = transform.TransformPoint(_localHoverPoint);
                transform.localRotation  = Quaternion.Euler(euler);
                transform.localPosition += oldHoverPoint - transform.TransformPoint(_localHoverPoint);
            }
        }

        //Make the hovered object the closest one to the tip.

        if (_useCollision)
        {
            _hoverQueue.update();
            RaycastHit hit = _hoverQueue.getFirst();
            if (hit.collider != null)
            {
                HoverPoint  = hit.point;
                HoverObject = (hit.collider.gameObject.layer == uiLayer) ?
                              hit.collider.gameObject :
                              objectResolver(hit.collider.gameObject);
            }
            else
            {
                ZSLinearShape linearStylus = activeStylus as ZSLinearShape;
                if (linearStylus != null && linearStylus._tip != null && linearStylus._tip.activeSelf)
                {
                    HoverPoint = linearStylus._tip.transform.position;
                }
                else
                {
                    HoverPoint = activeStylus.hotSpot;
                }
                HoverObject = null;
            }
        }
        else
        {
            HoverPoint = transform.TransformPoint(_localHoverPoint);
        }

        if (_HoverObject != null)
        {
            activeStylus.OnHoverStay(_HoverObject, HoverPoint);
        }

        //Update the set of selected objects based on clicking.

        if (GetButtonDown(SelectButton))
        {
            if (!Input.GetKey(KeyCode.LeftControl))
            {
                selectedObjects.Clear();
            }

            if (_HoverObject != null)
            {
                if (_HoverObject.layer == uiLayer)
                {
                    _wasHoveredObjectSelected = false;
                }
                else
                {
                    _wasHoveredObjectSelected = selectedObjects.Contains(_HoverObject);
                    if (!selectedObjects.Contains(_HoverObject))
                    {
                        selectedObjects.Add(_HoverObject);
                    }
                }
            }

            _buttonDownPosition = transform.position;
        }

        if (GetButtonUp(SelectButton))
        {
            bool wasDrag = (transform.position - _buttonDownPosition).magnitude > minDragDistance;
            if (_HoverObject != null && _wasHoveredObjectSelected && !wasDrag && Input.GetKey(KeyCode.LeftControl))
            {
                selectedObjects.Remove(_HoverObject);
            }
        }

        // Send messages to objects whose selection state changed.

        foreach (GameObject selectedObject in _oldSelectedObjects)
        {
            if (selectedObject != null && !selectedObjects.Contains(selectedObject))
            {
                activeStylus.OnDeselected(selectedObject);
                selectedObject.SendMessage("OnDeselected", SendMessageOptions.DontRequireReceiver);
            }
        }

        GameObject[] tmpSelectedObjects = new GameObject[selectedObjects.Count];
        selectedObjects.CopyTo(tmpSelectedObjects);                          // So objects can de-select themselves.
        foreach (GameObject selectedObject in tmpSelectedObjects)
        {
            if (selectedObject != null && !_oldSelectedObjects.Contains(selectedObject))
            {
                selectedObject.SendMessage("OnSelected", SendMessageOptions.DontRequireReceiver);
                activeStylus.OnSelected(selectedObject, HoverPoint);
            }
        }

        _oldSelectedObjects.Clear();
        foreach (GameObject selectedObject in selectedObjects)
        {
            if (selectedObject != null)
            {
                _oldSelectedObjects.Add(selectedObject);
            }
        }

        _lastMousePosition = Input.mousePosition;

        activeStylus.Tool.OnStylus();
    }
Exemple #5
0
 /// <summary>
 /// Creates a HoverQueue for the given ZSStylusSelector.
 /// Only objects in the given bitmask of layers will be considered.
 /// </summary>
 public HoverQueue(ZSStylusSelector stylusSelector, int layerMask, ZSCore core)
 {
     _layerMask      = layerMask;
     _stylusSelector = stylusSelector;
     _core           = core;
 }
 void start()
 {
     _core = GameObject.Find("ZSCore").GetComponent<ZSCore>();
     _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent<ZSStylusSelector>();
 }
 void Awake()
 {
     _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent<ZSStylusSelector>();
 }
Exemple #8
0
 void Awake()
 {
     _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent <ZSStylusSelector>();
     GetComponent <Collider>().enabled = false;
     GetComponent <Renderer>().enabled = false;
 }
 void Awake()
 {
     _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent <ZSStylusSelector>();
 }
 void Awake()
 {
     m_stylusSelector = GameObject.Find("ZSStylus").GetComponent<ZSStylusSelector>();
     collider.enabled = false;
     renderer.enabled = false;
 }
    /// <summary> Saves references to collaborating objects and components. </summary> 
    protected override void OnScriptAwake()
    {
        base.OnScriptAwake();

        _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent<ZSStylusSelector>();
    }
    /// <summary> Saves references to collaborating objects and components. </summary>
    protected override void OnScriptAwake()
    {
        base.OnScriptAwake();

        _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent <ZSStylusSelector> ();
    }
 void Awake()
 {
     _displayBounds = GameObject.Find("DisplayPlane").GetComponent<DisplayBounds>();
     _stylusSelector = GameObject.Find("ZSStylusSelector").GetComponent<ZSStylusSelector>();
 }
    protected override void OnScriptAwake()
    {
        base.OnScriptAwake();

        _core = GameObject.FindObjectOfType(typeof(ZSCore)) as ZSCore;
        _stylusSelector = GameObject.FindObjectOfType(typeof(ZSStylusSelector)) as ZSStylusSelector;
    }