コード例 #1
0
        /// <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;
        }
コード例 #2
0
        private void CleanUp()
        {
            if (setupComplete && isClosing)
            {
                SceneView.onSceneGUIDelegate           -= OnGUIDelegate;
                EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged;

                if (hapticSceneView != null)
                {
                    hapticSceneView.Dispose();
                    hapticSceneView = null;
                }

                if (hitListener != null)
                {
                    hitListener.BodyPartHit -= HitListener_BodyPartHit;
                    hitListener.Dispose();
                    hitListener = null;
                }
            }
        }