Beispiel #1
0
    // Use this for initialization
    protected virtual void Start()
    {
        _bStarted = true;

        ++_nCounter;
        if (null == _parent)
        {
            _parent   = transform.parent.transform;
            _textTime = SetText("BG/Time", "");
        }

        string[] id = { "BG/Yes", "BG/No", "BG/OK" };
        for (int i = 0; i < 3; ++i)
        {
            Transform btn = transform.Find(id[i]);
            if (btn)
            {
                OVButton obtn = btn.gameObject.GetComponent <OVButton>();
                obtn.m_OnClick.AddListener(delegate() { this.OnClick(btn.gameObject); });
                // OVUIEventListener.Get(btn.gameObject).onClick = this.OnClick;
            }
        }

        Canvas canvas = GetComponent <Canvas>();

        if (canvas)
        {
            canvas.sortingOrder = _nVisibleCounter++;
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        OVButton hb = (OVButton)target;

        hb._isSlider   = (bool)EditorGUILayout.Toggle("_isSlider", hb._isSlider);
        hb._isCheckBox = (bool)EditorGUILayout.Toggle("_isCheckBox", hb._isCheckBox);
        if (hb._isCheckBox)
        {
            EditorGUILayout.PropertyField(this._CheckGameObject, new GUILayoutOption[0]);
            base.serializedObject.ApplyModifiedProperties();
            EditorGUILayout.PropertyField(this._Checknormal, new GUILayoutOption[0]);
            base.serializedObject.ApplyModifiedProperties();
        }
        //hb._StyleNormal = (Sprite)EditorGUILayout.ObjectField("_StyleNormal", hb._StyleNormal, typeof(Sprite), true, new GUILayoutOption[0]);
        //hb._StyleHover = (Sprite)EditorGUILayout.ObjectField("_StyleHover", hb._StyleHover, typeof(Sprite), true, new GUILayoutOption[0]);
        //hb._StylePress = (Sprite)EditorGUILayout.ObjectField("_StylePress", hb._StylePress, typeof(Sprite), true, new GUILayoutOption[0]);
        //hb._StyleDisable = (Sprite)EditorGUILayout.ObjectField("_StyleDisable", hb._StyleDisable, typeof(Sprite), true, new GUILayoutOption[0]);
        //hb._StylePressed = (Sprite)EditorGUILayout.ObjectField("_StylePressed", hb._StylePressed, typeof(Sprite), true, new GUILayoutOption[0]);
        EditorGUILayout.Space();//空行

        //    EditorGUILayout.PropertyField(this._isCheckBox, new GUILayoutOption[0]);
        EditorGUILayout.PropertyField(this._Buttontext, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.PropertyField(this._StyleNormal, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.PropertyField(this._StyleHover, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.PropertyField(this._StylePress, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.PropertyField(this._StyleDisable, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.PropertyField(this._StylePressed, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
        // EditorGUILayout.PropertyField(this.m_InteractableProperty, new GUILayoutOption[0]);
        EditorGUILayout.Space();//空行
        base.serializedObject.Update();
        EditorGUILayout.PropertyField(this.m_OnClickProperty, new GUILayoutOption[0]);
        base.serializedObject.ApplyModifiedProperties();
    }
Beispiel #3
0
    private void raycast(int index, int device_index, Ray ray)
    {
        if (device_index < 0)
        {
            return;
        }

        // update _Ray position;
        if (_Ray[index].line)
        {
            _Ray[index].line.gameObject.SetActive(device_index >= 0);
        }



        if (_Ray[index].line && index == RAY_MOUSE)
        {
            _Ray[index].line.transform.position = ray.origin;
            _Ray[index].line.transform.LookAt(ray.origin + ray.direction * 100);
        }
        Debug.DrawRay(ray.origin, ray.direction * 100);
        // hit test
        int mask = _nCollideLayerMask != 0 ? _nCollideLayerMask : -1;

        RaycastHit[] hits                  = Physics.RaycastAll(ray, 1000, mask);
        int          hit_index             = -1;
        OVButton     hvb                   = null;
        Collider     hitscrollviewcollider = null;
        OVScrollView hitsv                 = null;
        float        len                   = _fRayLen;

        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].collider.GetComponent <Canvas>())
            {
                RectTransform trans = hits[i].collider.GetComponent <Canvas>().transform as RectTransform;
                Vector3       t     = trans.InverseTransformPoint(hits[i].point);
                Vector2       v2    = new Vector2(t.x, t.y);
                v2 -= trans.rect.min;
                _PointerEventData.delta    = v2 - _PointerEventData.position;
                _PointerEventData.position = v2;
                //Debug.Log("_PointerEventData.delta:=" + _PointerEventData.delta);
                //Debug.Log(_PointerEventData.position);
            }

            if (null != hits[i].collider.GetComponent <OVScrollView>() &&
                hits[i].collider.GetComponent <OVUIEventListener>())
            {
                _PointerEventData.pointerId = device_index;
                OVUIEventListener.Get(hits[i].collider.gameObject).onHover(hits[i].collider.gameObject, _PointerEventData);
                hitscrollviewcollider = hits[i].collider;
                continue;
            }

            OVButton btn_tmp = hits[i].collider.GetComponent <OVButton>();
            if (btn_tmp && !btn_tmp._bIgnoreRay)
            {
                hitsv = hits[i].collider.GetComponentInParent <OVScrollView>();
                if (hitsv == null)
                {
                    hvb = hits[i].collider.GetComponent <OVButton>();                     // 优先button
                    OVUIEventListener.Get(hvb.gameObject);                                //确保button有UIEventListener;
                    hit_index = i;
                }
                else
                {
                    hvb       = hits[i].collider.GetComponent <OVButton>();
                    hit_index = i;                    // 优先button
                }
            }
            //}
        }


        if (_hitscrollviewcollider == null)
        {
            _hitscrollviewcollider = hitscrollviewcollider;
        }
        if (_hitscrollviewcollider != null)
        {
            if (_hitscrollviewcollider != hitscrollviewcollider)
            {
                OVUIEventListener.Get(_hitscrollviewcollider.gameObject).onExit(null);
            }
            _hitscrollviewcollider = hitscrollviewcollider;
        }


        if (hitsv)
        {
            if (hitscrollviewcollider == null)
            {
                hvb = null;
            }
            if (hitscrollviewcollider)
            {
                if (hitsv.name == hitscrollviewcollider.name)
                {
                    OVUIEventListener.Get(hvb.gameObject);
                }
            }
        }

        //spark 处理
        if (hits.Length <= 0)
        {
            if (_Ray[index].spark)
            {
                _Ray[index].spark.SetActive(false);
            }
            if (_Ray[index].line_renderer)
            {
                _Ray[index].line_renderer.SetPosition(1, new Vector3(0, 0, 100));
            }
        }
        else
        {
            float f   = hits[0].distance;
            int   ind = 0;
            for (int i = 0; i < hits.Length; ++i)
            {
                if (hits[i].distance < f)
                {
                    f   = hits[i].distance;
                    ind = i;
                }
            }
            if (_Ray[index].spark)
            {
                _Ray[index].spark.SetActive(true);
                {
                    _Ray[index].spark.transform.position = hits[ind].point;;
                    _Ray[index].spark.transform.LookAt(hits[ind].point - ray.direction, Vector3.up);
                }
            }

            len = Vector3.Distance(ray.origin, hits[ind].point);

            if (_Ray[index].line_renderer)
            {
                _Ray[index].line_renderer.SetPosition(1, new Vector3(0, 0, len));
            }
        }



        Collider col = hit_index >= 0 ? hits[hit_index].collider : null;

        if (col != _Ray[index].hit)
        {
            _Ray[index].hit = col;
            if (_OnListenerCollider != col && _OnListenerCollider != null)
            {
                OVUIEventListener.Get(_OnListenerCollider.gameObject).OnPointerExit(null);
                //Debug.Log("OnPointerExit" + _OnListenerCollider);
                _OnListenerCollider = null;
                SteamVR_Controller.Input(device_index).TriggerHapticPulse(500);
            }

            if (col != null)
            {
                //OVUIEventListener a;
                if (null != (_Ray[index].hit.GetComponent <OVUIEventListener>()))
                {
                    // Debug.Log("OnPointerEnter" + col.gameObject);
                    OVUIEventListener.Get(col.gameObject).OnPointerEnter(null);
                    SteamVR_Controller.Input(device_index).TriggerHapticPulse(1500);
                    _OnListenerCollider = col;
                }
            }
        }

        if (col)
        {
            if (hvb)
            {
                int act = 0;
                if (index == RAY_MOUSE)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        act = 1;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        act = 2;
                    }
                    else if (Input.GetMouseButton(0))
                    {
                        act = 3;
                    }
                }
                else
                {
                    if (SteamVR_Controller.Input(device_index).GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
                    {
                        act = 1;
                    }
                    else if (SteamVR_Controller.Input(device_index).GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
                    {
                        act = 2;
                    }
                    else if (SteamVR_Controller.Input(device_index).GetPress(SteamVR_Controller.ButtonMask.Trigger))
                    {
                        act = 3;
                    }
                }

                if (act == 1)
                {
                    _pressTime        = 0;
                    _Ray[index].press = hvb;

                    if (col != null)
                    {
                        OVUIEventListener a;
                        if (null != (a = _Ray[index].hit.GetComponent <OVUIEventListener>()))
                        {
                            a.OnPointerDown(_PointerEventData);
                        }
                    }
                }
                else if (act == 2)
                {
                    //  hvb.SetButtonState(OVButtonState.Normal);
                    if (_Ray[index].press == hvb)
                    {
                        if (_Ray[index].spark)
                        {
                            //_Ray[index].spark.transform.SetParent(null);
                            _Ray[index].spark.SetActive(false);
                        }
                        if (_pressTime < 0.3)
                        {
                            OVUIEventListener.Get(hvb.gameObject).OnPointerClick(null);
                        }
                        OVUIEventListener.Get(hvb.gameObject).OnPointerUp(null);
                        _Ray[index].press = null;
                    }
                }
                else if (act == 3)
                {
                    _pressTime += Time.deltaTime;
                    if (_Ray[index].press)
                    {
                        if (_PointerEventData.IsPointerMoving())
                        {
                            _PointerEventData.pointerDrag = _Ray[index].hit.gameObject;
                            OVUIEventListener.Get(_Ray[index].press.gameObject).OnDrag(_PointerEventData);
                            //	Debug.Log("OnDrag++++++++++++++++------------------------------------------");
                        }
                        OVUIEventListener.Get(_Ray[index].press.gameObject).OnPointerDown(null);
                        _Ray[index].press.SetButtonState(_Ray[index].press == hvb ? OVButtonState.Press : OVButtonState.Normal);
                    }
                }
            }
        }
    }
Beispiel #4
0
    protected override void Start()
    {
        base.Start();

        _nTime = 0;

        _BG = transform.Find("BG");
        if (null == _BG)
        {
            _BG = transform;
        }

        string    path = OVSDK.GetUserInfo().sConsolePath + "\\" + _JsonFilePrefix + "_unity.json";
        string    json = ReadFile(path);
        OVMenuDef def;

        def.x     = def.y = def.w = def.h = 0;
        def.items = null;
        try
        {
            def       = JsonUtility.FromJson <OVMenuDef>(json);
            _MenuName = def.name;
            def.items = OVJsonHelper.FromJson <OVMenuItemDef>(json);
        }
        catch (Exception e) {
            Debug.Log("Parse json menu-items failed: " + e.Message);
        }
        if (null == _MenuName)
        {
            _MenuName = "";
        }
        if (def.w > 0 && def.h > 0)
        {
            ApplyTransRect(_BG as RectTransform, def.x, def.y, def.w, def.h, 0, false);
        }

        for (int i = 0; def.items != null && i < def.items.Length; ++i)
        {
            OVMenuItem item = CreateItem(def.items[i]);
            if (item != null)
            {
                if (def.items[i].type == "Button")
                {
                    item.directClose = (0 != def.items[i].close);
                    OVButton btn = item.go.gameObject.GetComponent <OVButton>();
                    btn.m_OnClick.AddListener(delegate(){ this.OnClick(item.go.gameObject); });
                    // OVUIEventListener.Get(item.go.gameObject).onClick += this.OnClick;
                }
                else if (def.items[i].type == "Slider")
                {
                    Slider slider = item.go.GetComponent <Slider>();
                    if (slider != null)
                    {
                        if (item.name == "OmniCoupleRate")
                        {
                            _PreOmniCoupleRate = OVSDK.GetUserOmniCoupleRate();
                            slider.value       = OVSDK.GetOmniCoupleRate();
                        }
                        slider.onValueChanged.AddListener(item.OnSliderValueChange);
                    }
                }
                else if (def.items[i].type == "Toggle")
                {
                    Toggle toggle = item.go.GetComponent <Toggle>();
                    if (toggle != null)
                    {
                        if (item.name == "OmniCoupleMode")
                        {
                            _PreOmniCoupleRate = OVSDK.GetUserOmniCoupleRate();
                            toggle.isOn        = OVSDK.GetOmniCoupleRate() < 0.5f ? false : true;
                        }
                        toggle.onValueChanged.AddListener(item.OnToggleStateChange);
                    }
                }
            }
        }

        _AllMsgBoxJson.Add(this);
        refreshButtonsState();
    }