Exemple #1
0
        void Awake()
        {
            bodyAffectedByDevice = new Dictionary <HumanBodyBones, List <HapticDevice> >();
            ignoreBoneSet        = new HashSet <HumanBodyBones>();
            ignoreHapticDevices  = new HashSet <HapticDevice>();

            animator = GetComponent <Animator>();

            if (animator != null)
            {
                foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones)))
                {
                    Transform boneTransform = animator.GetBoneTransform(bone);

                    if (boneTransform != null)
                    {
                        BodyCoordinate attachedCoordinate = boneTransform.gameObject.GetComponent <BodyCoordinate>();

                        if (attachedCoordinate != null)
                        {
                            attachedCoordinate.attachedBody = bone;
                        }
                    }
                }
            }
            else
            {
                Debug.LogWarning("No Animator found on HapticManager. Bones cannot be automatically set, please make sure it was manually done.", this);
            }
        }
 public void OnBodyPartHit(BodyCoordinate bodyCoordinate, BodyCoordinateHit hitInfo, Vector3 hitLocation)
 {
     if (BodyPartHit != null)
     {
         BodyPartHit(this, new HapticInformation(bodyCoordinate, hitInfo, hitLocation));
     }
 }
        /// <summary>
        /// Sets up a new scene for pattern creation. This method will set up a capsule with a body coordinate system, a line
        /// renderer for the haptic points, and the GUI and listeners needed to manage the new pattern.
        /// </summary>
        /// <param name="previousSceneName">The string of the scene that the user needs to return to when the leave this Scene UI</param>
        public void SetupCapsuleScene(string previousSceneName)
        {
            previousScene = previousSceneName;

            // Don't allow playmode to be entered while in this scene
            EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged;

            // Hook into mouse events from the scene
            hitListener              = new BodyHitListener();
            hitListener.BodyPartHit += HitListener_BodyPartHit;

            // Set up the In-Scene GUI
            hapticSceneView = new HapticSceneViewGUI
            {
                patternWindow = this
            };

            // Connect to the OnGUI event cycle
            SceneView.onSceneGUIDelegate += OnGUIDelegate;

            // Set up the capsule
            capsuleGO = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            capsuleGO.GetComponent <Renderer>().material = capsuleMaterial;
            capsuleGO.hideFlags   = HideFlags.HideInInspector;
            capsuleBodyCoordinate = capsuleGO.AddComponent <BodyCoordinate>();
            capsuleBodyCoordinate.drawGizmoUnselected = true;

            // Set up the line render for the active curve line
            GameObject lineHolder = new GameObject("Line Holder", typeof(LineRenderer));

            lineHolder.transform.parent = capsuleGO.transform;
            lineHolder.hideFlags        = HideFlags.HideInHierarchy;

            currentCurveLineRenderer = lineHolder.GetComponent <LineRenderer>();

            currentCurveLineRenderer.widthMultiplier           = lineRendererData.widthMultiplier;
            currentCurveLineRenderer.numCornerVertices         = lineRendererData.numCornerVertices;
            currentCurveLineRenderer.numCapVertices            = lineRendererData.numCapVertices;
            currentCurveLineRenderer.material                  = lineRendererData.lineMaterial;
            currentCurveLineRenderer.receiveShadows            = lineRendererData.receiveShadows;
            currentCurveLineRenderer.allowOcclusionWhenDynamic = lineRendererData.allowOcclusionWhenDynamic;
            currentCurveLineRenderer.startColor                = lineRendererData.lineStartColor;
            currentCurveLineRenderer.endColor                  = lineRendererData.lineEndColor;

            // Start with 0 points in the line
            currentCurveLineRenderer.positionCount = 0;

            // Focus the camera on the capsule
            Selection.activeGameObject = capsuleGO;
            SceneView.lastActiveSceneView.FrameSelected();

            // Start work on the haptic pattern
            currentPattern = ScriptableObject.CreateInstance <ScriptableHapticPattern>();
            AddNewCurve("Default");

            // Don't need the event listener for a new scene anymore, wait for when this scene closes
            setupComplete = true;
        }
        public void GetMouseClicks(SceneView sceneView)
        {
            // Only care about mouse down events
            if (Event.current.type != EventType.MouseDown)
            {
                return;
            }

            // convert GUI coordinates to screen coordinates
            Vector3 screenPosition       = Event.current.mousePosition;
            Vector3 cameraScreenPosition = screenPosition;

            cameraScreenPosition.y = Camera.current.pixelHeight - cameraScreenPosition.y;

            Ray        ray = Camera.current.ScreenPointToRay(cameraScreenPosition);
            RaycastHit hit;

            // Wait for double clicks on left mouse
            if (Event.current.clickCount == 2 && Event.current.button == 0)
            {
                // Cast ray into the scene
                if (Physics.Raycast(ray, out hit))
                {
                    Event.current.Use();

                    BodyCoordinate bodyPart = hit.collider.GetComponent <BodyCoordinate>();

                    if (bodyPart != null)
                    {
                        BodyCoordinateHit hitLocation = bodyPart.CalculateBodyCoordinateHitFromPosition(hit.point);

                        OnBodyPartHit(bodyPart, hitLocation, hit.point);

                        return;
                    }

                    BodyHitUI uiHit = hit.collider.GetComponent <BodyHitUI>();

                    if (uiHit != null)
                    {
                        // Make sure that another UI is not already displaying
                        lastUIHit?.HideUI(screenPosition, true);

                        lastUIHit = uiHit;

                        lastUIHit.DisplayUI(screenPosition);
                        return;
                    }
                }
            }
            else if (Event.current.clickCount == 1)
            {
                // Close the hitUI if they click outside of it
                if (lastUIHit != null)
                {
                    // Right/middle clicks will force close the UI
                    bool wasHidden = (Event.current.button != 0) ? lastUIHit.HideUI(screenPosition, true) : lastUIHit.HideUI(screenPosition);

                    if (wasHidden)
                    {
                        lastUIHit = null;
                    }
                }
            }
        }
 public HapticInformation(BodyCoordinate bodyCoordinate, BodyCoordinateHit hitInfo, Vector3 hitLocation)
 {
     bodyPart         = bodyCoordinate;
     bodyHitInfo      = hitInfo;
     worldHitLocation = hitLocation;
 }