Beispiel #1
0
    public virtual void OnColliderEventDragStart(ColliderButtonEventData eventData)
    {
        if (!IsValidGrabButton(eventData))
        {
            return;
        }

        if (!m_allowMultipleGrabbers)
        {
            ClearGrabbers(false);
            ClearEventGrabberSet();
        }

        var grabber = BasicGrabbable.Grabber.Get(eventData);
        var offset  = RigidPose.FromToPose(grabber.grabberOrigin, new RigidPose(transform));

        grabber.grabOffset = offset;

        if (m_eventGrabberSet == null)
        {
            m_eventGrabberSet = new IndexedTable <ColliderButtonEventData, BasicGrabbable.Grabber>();
        }
        m_eventGrabberSet.Add(eventData, grabber);

        AddGrabber(grabber);
        Vector3 deltaVec          = grabber.grabberOrigin.pos - transform.position;
        Vector3 deltaVecProjected = Vector3.ProjectOnPlane(deltaVec, transform.up).normalized;

        initialDeltaDegrees = Vector3.SignedAngle(transform.forward, deltaVecProjected, transform.up);
    }
Beispiel #2
0
    public virtual void OnBeginDrag(PointerEventData eventData)
    {
        var hitDistance = 0f;

        switch (eventData.button)
        {
        case PointerEventData.InputButton.Middle:
        case PointerEventData.InputButton.Right:
            hitDistance = Mathf.Min(eventData.pointerPressRaycast.distance, m_initGrabDistance);
            break;

        case PointerEventData.InputButton.Left:
            hitDistance = eventData.pointerPressRaycast.distance;
            break;

        default:
            return;
        }

        var grabber = Grabber.Get(eventData);

        grabber.grabber2hit = new RigidPose(new Vector3(0f, 0f, hitDistance), Quaternion.identity);
        grabber.hit2pivot   = RigidPose.FromToPose(grabber.grabberOrigin * grabber.grabber2hit, new RigidPose(transform));

        if (m_eventGrabberSet == null)
        {
            m_eventGrabberSet = new IndexedTable <PointerEventData, Grabber>();
        }
        m_eventGrabberSet.Add(eventData, grabber);

        AddGrabber(grabber);
    }
Beispiel #3
0
 static ViveRoleEnum()
 {
     // find all valid ViveRole enum type in current assemblies
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         try
         {
             foreach (var type in assembly.GetTypes())
             {
                 if (ValidateViveRoleEnum(type) == ViveRoleEnumValidateResult.Valid)
                 {
                     s_validViveRoleTable.Add(type.FullName, type);
                 }
             }
         }
         catch (System.Reflection.ReflectionTypeLoadException e)
         {
             Debug.LogWarning(e);
             Debug.LogWarning("load assembly " + assembly.FullName + " fail");
         }
         catch (Exception e)
         {
             Debug.LogError(e);
         }
     }
 }
Beispiel #4
0
            public void SetStayingObjHierarchy(GameObject obj)
            {
                if (obj == null)
                {
                    return;
                }

                for (var tr = obj.transform; tr != null; tr = tr.parent)
                {
                    var trObj = tr.gameObject;

                    var trObjIndex = stayingObjs.IndexOf(trObj);

                    if (trObjIndex < 0)
                    {
                        enterHandlers.Add(trObj);
                        stayingObjs.Add(trObj, true);
                    }
                    else if (!stayingObjs.GetValueByIndex(trObjIndex))
                    {
                        stayingObjs.SetValueByIndex(trObjIndex, true);
                    }
                    else
                    {
                        // skip if root obj is already recorded
                        return;
                    }
                }
            }
        public virtual void OnColliderEventDragStart(ColliderButtonEventData eventData)
        {
            if (eventData.button != m_grabButton)
            {
                return;
            }

            if (!m_allowMultipleGrabbers)
            {
                ClearGrabbers(false);
                ClearEventGrabberSet();
            }

            var grabber = Grabber.Get(eventData);
            var offset  = RigidPose.FromToPose(grabber.grabberOrigin, new RigidPose(transform));

            if (alignPosition)
            {
                offset.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offset.rot = Quaternion.Euler(alignRotationOffset);
            }
            grabber.grabOffset = offset;

            if (m_eventGrabberSet == null)
            {
                m_eventGrabberSet = new IndexedTable <ColliderButtonEventData, Grabber>();
            }
            m_eventGrabberSet.Add(eventData, grabber);

            AddGrabber(grabber);
        }
Beispiel #6
0
 protected virtual void OnTriggerEnter(Collider collider)
 {
     if (hoveredColliderCount.ContainsKey(collider))
     {
         ++hoveredColliderCount[collider];
     }
     else
     {
         hoveredColliderCount.Add(collider, 1);
     }
 }
        static ViveRoleEnum()
        {
            // find all valid ViveRole enum type in current assemblies
            var currentAsm     = typeof(ViveRoleEnumAttribute).Assembly;
            var currentAsmName = currentAsm.GetName().Name;

            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    var referencingCurrentAsm = false;

                    if (asm == currentAsm)
                    {
                        referencingCurrentAsm = true;
                    }
                    else
                    {
                        foreach (var asmref in asm.GetReferencedAssemblies())
                        {
                            if (asmref.Name == currentAsmName)
                            {
                                referencingCurrentAsm = true;
                                break;
                            }
                        }
                    }

                    if (referencingCurrentAsm)
                    {
                        // try find valid role enum type in assembly
                        foreach (var type in asm.GetTypes())
                        {
                            if (ValidateViveRoleEnum(type) == ViveRoleEnumValidateResult.Valid)
                            {
                                s_validViveRoleTable.Add(type.FullName, type);
                            }
                        }
                    }
                }
                catch (System.Reflection.ReflectionTypeLoadException e)
                {
                    Debug.LogWarning(e);
                    Debug.LogWarning("load assembly " + asm.FullName + " fail");
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }
 static ViveRoleEnum()
 {
     // find all valid ViveRole enum type in current assemblies
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         foreach (var type in assembly.GetTypes())
         {
             if (ValidateViveRoleEnum(type) == ViveRoleEnumValidateResult.Valid)
             {
                 s_validViveRoleTable.Add(type.FullName, type);
             }
         }
     }
 }
Beispiel #9
0
            public void SetColliderStaying(Collider collider)
            {
                var index = colliderFlags.IndexOf(collider);

                if (index < 0)
                {
                    ++addCount;
                    ++stayCount;
                    colliderFlags.Add(collider, true);
                }
                else if (!colliderFlags.GetValueByIndex(index))
                {
                    ++stayCount;
                    colliderFlags.SetValueByIndex(index, true);
                }
            }
Beispiel #10
0
    public virtual void OnBeginDrag(PointerEventData eventData)
    {
        var hitDistance = 0f;

        //수정한 코드
        VivePointerEventData viveEventData;

        if (eventData.TryGetViveButtonEventData(out viveEventData))
        {
            if (viveEventData.viveButton == ControllerButton.Pad)
            {
                return;
            }
        }
        /////////////////////////////////
        switch (eventData.button)
        {
        case PointerEventData.InputButton.Middle:
        case PointerEventData.InputButton.Right:
            hitDistance = Mathf.Min(eventData.pointerPressRaycast.distance, m_initGrabDistance);
            break;

        case PointerEventData.InputButton.Left:
            hitDistance = eventData.pointerPressRaycast.distance;
            break;

        default:
            return;
        }

        var grabber = Grabber.Get(eventData);

        grabber.grabber2hit = new RigidPose(new Vector3(0f, 0f, hitDistance), Quaternion.identity);
        grabber.hit2pivot   = RigidPose.FromToPose(grabber.grabberOrigin * grabber.grabber2hit, new RigidPose(transform));

        if (m_eventGrabberSet == null)
        {
            m_eventGrabberSet = new IndexedTable <PointerEventData, Grabber>();
        }
        m_eventGrabberSet.Add(eventData, grabber);

        AddGrabber(grabber);


        GameObject.Find("LocalPlayer").GetComponent <isLocalPlayer>().CmdClientAuthority(gameObject);
    }
Beispiel #11
0
        public virtual void OnColliderEventPressDown(ColliderButtonEventData eventData)
        {
            if (eventData.button != m_grabButton)
            {
                return;
            }

            Grabber grabber;

            if (m_eventGrabberSet == null || !m_eventGrabberSet.TryGetValue(eventData, out grabber))
            {
                if (!m_allowMultipleGrabbers)
                {
                    ClearGrabbers(false);
                    ClearEventGrabberSet();
                }

                grabber = Grabber.Get(eventData);
                var offset = RigidPose.FromToPose(grabber.grabberOrigin, new RigidPose(transform));
                if (alignPosition)
                {
                    offset.pos = alignPositionOffset;
                }
                if (alignRotation)
                {
                    offset.rot = Quaternion.Euler(alignRotationOffset);
                }
                grabber.grabOffset = offset;
                grabber.grabFrame  = Time.frameCount;

                if (m_eventGrabberSet == null)
                {
                    m_eventGrabberSet = new IndexedTable <ColliderButtonEventData, Grabber>();
                }
                m_eventGrabberSet.Add(eventData, grabber);

                AddGrabber(grabber);
            }
            else if (toggleToRelease)
            {
                RemoveGrabber(grabber);
                m_eventGrabberSet.Remove(eventData);
                Grabber.Release(grabber);
            }
        }
            public GenericInfo()
            {
                m_info = GetInfo(typeof(TRole));
                var roleEnums = m_info.RoleValues as TRole[];

                m_nameTable = new IndexedTable <string, TRole>(roleEnums.Length);
                m_roles     = new TRole[ValidRoleLength];

                for (int i = 0; i < m_roles.Length; ++i)
                {
                    m_roles[i] = InvalidRole;
                }

                for (int i = 0; i < roleEnums.Length; ++i)
                {
                    var roleValue = ToRoleValue(roleEnums[i]);

                    m_nameTable.Add(GetNameByElementIndex(i), roleEnums[i]);

                    if (roleValue == InvalidRoleValue)
                    {
                        m_invalidRole = roleEnums[i];
                    }
                    else
                    {
                        var offset = RoleValueToRoleOffset(roleValue);
                        m_roles[offset] = roleEnums[i];
                    }
                }

                m_minValidRole = ToRole(m_info.MinValidRoleValue);
                m_maxValidRole = ToRole(m_info.MaxValidRoleValue);

                if (s_instance == null)
                {
                    s_instance = this;
                }
                else
                {
                    UnityEngine.Debug.Log("redundant instance for RoleInfo<" + typeof(TRole).Name + ">");
                }
            }
Beispiel #13
0
        private void OnDeviceConnected(uint deviceIndex, bool connected)
        {
            BindingInterfaceDeviceItem item;

            if (connected)
            {
                if (m_itemPool.Count == 0)
                {
                    var itemObj = Instantiate(m_deviceItem.gameObject);
                    itemObj.transform.SetParent(m_deviceItem.transform.parent, false);
                    item = itemObj.GetComponent <BindingInterfaceDeviceItem>();

                    item.onClick += m_onSelectDevice.Invoke;
                    item.onEnter += OnEnterDevice;
                    item.onExit  += OnExitDevice;
                }
                else
                {
                    item = m_itemPool[m_itemPool.Count - 1];
                    m_itemPool.RemoveAt(m_itemPool.Count - 1); // remove last
                }

                m_itemTable.Add(deviceIndex, item);
                item.deviceIndex = deviceIndex;
                item.isBound     = m_selectedRoleMap.IsDeviceConnectedAndBound(deviceIndex);
                item.UpdateModel();
            }
            else
            {
                item = m_itemTable[deviceIndex];
                m_itemTable.Remove(deviceIndex);

                m_itemPool.Add(item);
            }

            item.gameObject.SetActive(connected);
        }
Beispiel #14
0
        public virtual void OnColliderEventDragStart(ColliderButtonEventData eventData)
        {
            if (!IsValidGrabButton(eventData))
            {
                return;
            }

            if (!m_allowMultipleGrabbers)
            {
                ClearGrabbers(false);
                ClearEventGrabberSet();
            }

            var grabber = Grabber.Get(eventData);
            var offset  = RigidPose.FromToPose(grabber.grabberOrigin, new RigidPose(transform));

            if (alignPosition)
            {
                offset.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offset.rot = Quaternion.Euler(alignRotationOffset);
            }
            grabber.grabOffset = offset;

            if (m_eventGrabberSet == null)
            {
                m_eventGrabberSet = new IndexedTable <ColliderButtonEventData, Grabber>();
            }
            m_eventGrabberSet.Add(eventData, grabber);
            lastJoy = eventData;

            AddGrabber(grabber);
            //if (gameObject.GetComponent<PortalTraveller>() != null) gameObject.GetComponent<PortalTraveller>().readyToTeleport = false;
        }
        public static IInfo GetInfo(Type roleEnumType)
        {
            if (s_infoTable == null)
            {
                s_infoTable = new IndexedTable <Type, IInfo>();
            }

            IInfo info;

            if (!s_infoTable.TryGetValue(roleEnumType, out info))
            {
                var validateResult = ValidateViveRoleEnum(roleEnumType);
                if (validateResult != ViveRoleEnumValidateResult.Valid)
                {
                    UnityEngine.Debug.LogWarning(roleEnumType.Name + " is not valid ViveRole. " + validateResult);
                    return(null);
                }

                info = new Info(roleEnumType);
                s_infoTable.Add(roleEnumType, info);
            }

            return(info);
        }
Beispiel #16
0
        private static Map GetInternalMap(Type roleType)
        {
            if (s_mapTable == null)
            {
                s_mapTable = new IndexedTable <Type, Map>();
            }

            Map map;

            if (!s_mapTable.TryGetValue(roleType, out map))
            {
                var validateResult = ViveRoleEnum.ValidateViveRoleEnum(roleType);
                if (validateResult != ViveRoleEnumValidateResult.Valid)
                {
                    Debug.LogWarning(roleType.Name + " is not valid ViveRole type. " + validateResult);
                    return(null);
                }

                map = new Map(roleType);
                s_mapTable.Add(roleType, map);
            }

            return(map);
        }
Beispiel #17
0
        private void OnLoadModelComplete(string renderModelName)
        {
            m_loadingRenderModels.Remove(renderModelName);

            if (loadedModelName == renderModelName)
            {
                return;
            }
            if (preferedModelName != renderModelName)
            {
                return;
            }
            if (!isActiveAndEnabled)
            {
                return;
            }
            //Debug.Log(transform.parent.parent.name + " OnLoadModelComplete " + renderModelName);
            ClearModel();

            VIUSteamVRRenderModelLoader.RenderModel renderModel;
            if (!VIUSteamVRRenderModelLoader.renderModelsCache.TryGetValue(renderModelName, out renderModel))
            {
                return;
            }

            if (loadedShader == null)
            {
                loadedShader = preferedShader;
            }

            if (renderModel.childCount == 0)
            {
                VIUSteamVRRenderModelLoader.Model model;
                if (VIUSteamVRRenderModelLoader.modelsCache.TryGetValue(renderModelName, out model))
                {
                    Material material;
                    if (!m_materials.TryGetValue(model.textureID, out material))
                    {
                        if (!renderModel.TryCreateMaterialForTexture(model.textureID, loadedShader, out material))
                        {
                            material = new Material(loadedShader);
                        }

                        m_materials.Add(model.textureID, material);
                    }

                    m_meshFilter                  = gameObject.AddComponent <MeshFilter>();
                    m_meshFilter.mesh             = model.mesh;
                    m_meshRenderer                = gameObject.AddComponent <MeshRenderer>();
                    m_meshRenderer.sharedMaterial = material;
                }
            }
            else
            {
                for (int i = 0, imax = renderModel.childCount; i < imax; ++i)
                {
                    var childName = renderModel.childCompNames[i];
                    var modelName = renderModel.childModelNames[i];
                    if (string.IsNullOrEmpty(childName) || string.IsNullOrEmpty(modelName))
                    {
                        continue;
                    }

                    if (!m_chilTransforms.ContainsKey(childName))
                    {
                        var root = new GameObject(childName).transform;

                        root.SetParent(transform, false);
                        root.gameObject.layer = gameObject.layer;

                        VIUSteamVRRenderModelLoader.Model model;
                        if (VIUSteamVRRenderModelLoader.modelsCache.TryGetValue(modelName, out model))
                        {
                            Material material;
                            if (!m_materials.TryGetValue(model.textureID, out material))
                            {
                                if (!renderModel.TryCreateMaterialForTexture(model.textureID, loadedShader, out material))
                                {
                                    material = new Material(loadedShader);
                                }

                                m_materials.Add(model.textureID, material);
                            }

                            root.gameObject.AddComponent <MeshFilter>().mesh             = model.mesh;
                            root.gameObject.AddComponent <MeshRenderer>().sharedMaterial = material;
                        }

                        // Also create a child 'attach' object for attaching things.
                        var attach = new GameObject(LOCAL_TRANSFORM_NAME).transform;
                        attach.SetParent(root, false);
                        attach.gameObject.layer = gameObject.layer;

                        m_chilTransforms.Add(childName, new ChildTransforms()
                        {
                            root   = root,
                            attach = attach,
                        });
                    }
                }
            }

            loadedModelName = renderModelName;
        }