コード例 #1
0
        public void Dispose()
        {
            if (light0 != null)
            {
                UnityEngine.Object.DestroyImmediate(light0.gameObject);
                light0 = null;
            }

            if (light1 != null)
            {
                UnityEngine.Object.DestroyImmediate(light1.gameObject);
                light1 = null;
            }

            if (camera != null)
            {
                UnityEngine.Object.DestroyImmediate(camera.gameObject);
                m_Camera = null;
            }

            if (checkerboardMaterial != null)
            {
                UnityEngine.Object.DestroyImmediate(checkerboardMaterial, true);
                m_CheckerboardMaterial = null;
            }

            EditorSceneManager.ClosePreviewScene(m_Scene);
        }
コード例 #2
0
 protected override void OnDestroy()
 {
     foreach (var sceneAndMask in m_CompanionScenes)
     {
         EditorSceneManager.ClosePreviewScene(sceneAndMask.scene);
     }
 }
コード例 #3
0
 internal static void DestroyPreviewScene(Scene previewScene)
 {
     if (previewScene.IsValid())
     {
         Undo.ClearUndoSceneHandle(previewScene);
         EditorSceneManager.ClosePreviewScene(previewScene);
     }
 }
コード例 #4
0
 public void Dispose()
 {
     EditorSceneManager.ClosePreviewScene(this.m_Scene);
     foreach (GameObject current in this.m_GameObjects)
     {
         UnityEngine.Object.DestroyImmediate(current);
     }
     this.m_GameObjects.Clear();
 }
コード例 #5
0
    public static void WhatUsesThisComponent(MenuCommand command)
    {
        Component c            = (Component)command.context;
        var       typeToSearch = c.GetType();
        var       typeString   = c.GetType().Name;

        Debug.Log("Finding all Prefabs and scenes that have the component " + c.GetType() + "...");

        string[] guids = AssetDatabase.FindAssets("t:scene t:prefab");

        int count = 0;

        for (int i = 0; i < guids.Length; i++)
        {
            string guid = guids[i];
            //Debug.Log(AssetDatabase.GUIDToAssetPath(guid));
            string   myObjectPath = AssetDatabase.GUIDToAssetPath(guid);
            var      asset        = AssetDatabase.LoadAssetAtPath(myObjectPath, typeof(Object));
            Object[] myObjs;
            Scene    s = default;
            if (asset is SceneAsset)
            {
                s      = EditorSceneManager.OpenPreviewScene(myObjectPath);
                myObjs = s.GetRootGameObjects().SelectMany(g => g.GetComponentsInChildren(typeToSearch, true)).ToArray();
            }
            else
            {
                myObjs = AssetDatabase.LoadAllAssetsAtPath(myObjectPath);
            }

            if (EditorUtility.DisplayCancelableProgressBar("Searching in scenes/prefabs...", count + " matches. Progress: " + i + " / " + guids.Length + ". Current: " + asset.name, i / (guids.Length - 1f)))
            {
                goto End;
            }

            foreach (Object thisObject in myObjs)
            {
                if (typeToSearch.IsAssignableFrom(thisObject.GetType()))
                {
                    Debug.Log("<color=red>" + typeString + "</color> Found in <color=green>" + thisObject.name + "</color> at " + myObjectPath, asset);
                    count++;
                    break;
                }
            }

            if (asset is SceneAsset)
            {
                EditorSceneManager.ClosePreviewScene(s);
            }
        }

End:
        EditorUtility.ClearProgressBar();
    }
コード例 #6
0
    private void OnDisable()
    {
        if (scene_loaded)
        {
            DestroyImmediate(sound_object.gameObject);

            EditorSceneManager.ClosePreviewScene(sound_scene);

            scene_loaded = false;
        }
    }
コード例 #7
0
        public void Dispose()
        {
            EditorSceneManager.ClosePreviewScene(m_Scene);

            foreach (var go in m_GameObjects)
            {
                Object.DestroyImmediate(go);
            }

            m_GameObjects.Clear();
        }
コード例 #8
0
ファイル: Stage.cs プロジェクト: LS122800/ProjectEntropy
        private bool disposedValue = false; // To detect redundant calls

        void CleanUp()
        {
            if (!disposedValue)
            {
                if (SRI != null)
                {
                    SRI.SRPData = null;
                }
                SRI = null;
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);

                disposedValue = true;
            }
        }
コード例 #9
0
        internal bool LoadStage(string prefabPath)
        {
            if (initialized)
            {
                Cleanup();
            }

            m_PrefabAssetPath = prefabPath;

            // Tempoary scene used while loading the prefab
            m_PreviewScene = EditorSceneManager.NewPreviewScene();

            // The user can have OnEnable and other callbacks called during LoadPrefabIntoPreviewScene (if they use ExecuteInEditMode or ExecuteAlways)
            // where they might request the current the prefabstage, so we ensure m_PreviewScene have been setup so they can check this stage's scene.
            m_PrefabContentsRoot = PrefabStageUtility.LoadPrefabIntoPreviewScene(prefabAssetPath, m_PreviewScene);

            if (m_PrefabContentsRoot != null)
            {
                // Create the environment scene and move the prefab root to this scene to ensure the correct rendersettings (skybox etc) are used in Prefab Mode.
                string environmentEditingScenePath = PrefabStageUtility.GetEnvironmentScenePathForPrefab(m_PrefabContentsRoot);
                Scene  environmentScene            = PrefabStageUtility.CreatePreviewScene(environmentEditingScenePath);
                environmentScene.name = m_PrefabContentsRoot.name;
                SceneManager.MoveGameObjectToScene(m_PrefabContentsRoot, environmentScene);
                if (!PrefabStageUtility.HandleAutoReparenting(m_PrefabContentsRoot, environmentScene))
                {
                    m_PrefabContentsRoot.transform.SetAsFirstSibling();
                }

                // Close the temporary prefab loading scene and set the environment scene as the scene of the stage
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);
                m_PreviewScene = environmentScene;

                m_PrefabFileIcon      = DeterminePrefabFileIconFromInstanceRootGameObject();
                m_InitialSceneDirtyID = m_PreviewScene.dirtyID;
                UpdateEnvironmentHideFlags();
            }
            else
            {
                // Invalid setup
                Cleanup();
            }

            return(initialized);
        }
コード例 #10
0
        public void OnDisable()
        {
            string assetPath = AssetDatabase.GetAssetPath(Manager.Instance.asset);

            EditorPrefs.SetString("LastNoiseAsset", assetPath);

            //if (NodeManager.Instance.nodes != null && NodeManager.Instance.nodes.Count > 0) //Commented out to make developing faster
            //    Manager.Instance.Save();

            if (NodeManager.Instance.nodes != null)
            {
                foreach (Node node in NodeManager.Instance.nodes)
                {
                    node.CleanUp();
                    EditorSceneManager.ClosePreviewScene(Manager.Instance.scene);
                }
            }

            Manager.Instance.Dispose();
        }
コード例 #11
0
            static void CloseScene(Scene scene, GameObject root)
            {
                if (!scene.IsValid())
                {
                    return;
                }

                if (root != null)
                {
                    UnityObjectUtils.Destroy(root);
                }

                if (EditorSceneManager.IsPreviewScene(scene))
                {
                    EditorSceneManager.ClosePreviewScene(scene);
                }
                else
                {
                    SceneManager.UnloadSceneAsync(scene);
                }
            }
コード例 #12
0
        public void Dispose()
        {
            camera.targetTexture = null;
            if (renderTexture != null)
            {
                UnityEngine.Object.DestroyImmediate(renderTexture);
                renderTexture = null;
            }

            if (cameraObj != null)
            {
                UnityEngine.Object.DestroyImmediate(cameraObj);
            }
            if (avatarObj != null)
            {
                UnityEngine.Object.DestroyImmediate(avatarObj);
            }
            if (lightObj != null)
            {
                UnityEngine.Object.DestroyImmediate(lightObj);
            }

            EditorSceneManager.ClosePreviewScene(scene);
        }
コード例 #13
0
        internal bool LoadStage(string prefabPath)
        {
            if (initialized)
            {
                Cleanup();
            }

            m_PrefabAssetPath = prefabPath;

            // Tempoary scene used while loading the prefab
            m_PreviewScene = EditorSceneManager.NewPreviewScene();

            // The user can have OnEnable and other callbacks called during LoadPrefabIntoPreviewScene (if they use ExecuteInEditMode or ExecuteAlways)
            // where they might request the current the prefabstage, so we ensure m_PreviewScene have been setup so they can check this stage's scene.
            m_PrefabContentsRoot = PrefabStageUtility.LoadPrefabIntoPreviewScene(prefabAssetPath, m_PreviewScene);

            if (m_PrefabContentsRoot != null)
            {
                Scene environmentScene = PrefabStageUtility.MovePrefabRootToEnvironmentScene(m_PrefabContentsRoot);

                // Close the temporary prefab loading scene and set the environment scene as the scene of the stage
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);
                m_PreviewScene = environmentScene;

                m_PrefabFileIcon      = DeterminePrefabFileIconFromInstanceRootGameObject();
                m_InitialSceneDirtyID = m_PreviewScene.dirtyID;
                UpdateEnvironmentHideFlags();
            }
            else
            {
                // Invalid setup
                Cleanup();
            }

            return(initialized);
        }
コード例 #14
0
        static void GenerateVoxelGrids(GameObject prefabRoot, PlaneVoxelGenerationParams voxelGenerationParams, VoxelPlaneFindingParams planeFindingParams)
        {
            // Rather than modifying collider properties and risking corrupting the scene, for each object with a mesh
            // we create a game object with a collider that uses that mesh and add that object to a preview scene.
            var tempPreviewScene = EditorSceneManager.NewPreviewScene();
            var tempPhysicsScene = tempPreviewScene.GetPhysicsScene();

            // k_MeshFilters is cleared by GetComponentsInChildren
            prefabRoot.GetComponentsInChildren(k_MeshFilters);
            var meshesRoot = new GameObject("Meshes").transform;

            k_MeshColliders.Clear();
            foreach (var meshFilter in k_MeshFilters)
            {
                // Ignore synth planes
                if (meshFilter.GetComponent <SynthesizedPlane>())
                {
                    continue;
                }

                var meshCopyTrans    = new GameObject(string.Format("{0} (Mesh)", meshFilter.gameObject.name)).transform;
                var meshCopyCollider = meshCopyTrans.gameObject.AddComponent <MeshCollider>();
                k_MeshColliders.Add(meshCopyCollider);
                meshCopyCollider.sharedMesh = meshFilter.sharedMesh;
                meshCopyTrans.SetParent(meshesRoot);
                var meshFilterTrans = meshFilter.transform;
                meshCopyTrans.position   = meshFilterTrans.position;
                meshCopyTrans.rotation   = meshFilterTrans.rotation;
                meshCopyTrans.localScale = meshFilterTrans.lossyScale;
            }

            SceneManager.MoveGameObjectToScene(meshesRoot.gameObject, tempPreviewScene);

            var sceneBounds    = BoundsUtils.GetBounds(k_MeshColliders);
            var sceneBoundsMin = sceneBounds.min;
            var sceneBoundsMax = sceneBounds.max;

            // Make mesh colliders convex so that we can use CheckSphere to make sure our
            // raycasts don't originate within meshes.
            foreach (var meshCollider in k_MeshColliders)
            {
                meshCollider.convex = true;
            }

            // Seed the random number generator so that results are deterministic
            Random.InitState(voxelGenerationParams.raycastSeed);

            // Setup all ray origins before raycasting since we need mesh colliders to be convex for this step
            // but concave for the raycasting.
            var raycastCount = voxelGenerationParams.raycastCount;

            k_RayOrigins.Clear();
            k_RayOrigins.Capacity = raycastCount;
            for (var i = 0; i < raycastCount; i++)
            {
                var     rayGenerationAttempts = 0;
                Vector3 origin;
                while (true)
                {
                    origin = new Vector3(
                        Random.Range(sceneBoundsMin.x, sceneBoundsMax.x),
                        Random.Range(sceneBoundsMin.y, sceneBoundsMax.y),
                        Random.Range(sceneBoundsMin.z, sceneBoundsMax.z));

                    // If the randomly generated ray origin lies inside a mesh, try again
                    if (tempPhysicsScene.OverlapSphere(origin, k_CheckSphereRadius, k_Colliders,
                                                       Physics.DefaultRaycastLayers, QueryTriggerInteraction.Collide) == 0)
                    {
                        break;
                    }

                    rayGenerationAttempts++;
                    if (rayGenerationAttempts >= k_MaxRayGenerationRetries)
                    {
                        break;
                    }
                }

                k_RayOrigins.Add(origin);
            }

            foreach (var meshCollider in k_MeshColliders)
            {
                // Make mesh colliders concave for more useful raycast results
                meshCollider.convex = false;
            }

            k_UpGridPoints.Clear();
            k_DownGridPoints.Clear();
            k_ForwardGridPoints.Clear();
            k_BackGridPoints.Clear();
            k_RightGridPoints.Clear();
            k_LeftGridPoints.Clear();

            var outerPointsThreshold = voxelGenerationParams.outerPointsThreshold;
            var upGridBounds         = sceneBounds;
            var upGridMax            = upGridBounds.max;

            upGridMax.y     -= Mathf.Min(outerPointsThreshold, upGridBounds.size.y);
            upGridBounds.max = upGridMax;

            var downGridBounds = sceneBounds;
            var downGridMin    = downGridBounds.min;

            downGridMin.y     += Mathf.Min(outerPointsThreshold, downGridBounds.size.y);
            downGridBounds.min = downGridMin;

            var forwardGridBounds = sceneBounds;
            var forwardGridMax    = forwardGridBounds.max;

            forwardGridMax.z     -= Mathf.Min(outerPointsThreshold, forwardGridBounds.size.z);
            forwardGridBounds.max = forwardGridMax;

            var backGridBounds = sceneBounds;
            var backGridMin    = backGridBounds.min;

            backGridMin.z     += Mathf.Min(outerPointsThreshold, backGridBounds.size.z);
            backGridBounds.min = backGridMin;

            var rightGridBounds = sceneBounds;
            var rightGridMax    = rightGridBounds.max;

            rightGridMax.x     -= Mathf.Min(outerPointsThreshold, rightGridBounds.size.x);
            rightGridBounds.max = rightGridMax;

            var leftGridBounds = sceneBounds;
            var leftGridMin    = leftGridBounds.min;

            leftGridMin.x     += Mathf.Min(outerPointsThreshold, leftGridBounds.size.x);
            leftGridBounds.min = leftGridMin;

            // Start raycasting. We run raycasts synchronously so the user can't switch scenes or make scene changes while they are running.
            var maxHitDistance       = voxelGenerationParams.maxHitDistance;
            var normalToleranceAngle = voxelGenerationParams.normalToleranceAngle;
            var rayIndex             = 0;
            var up    = Vector3.up;
            var down  = Vector3.down;
            var back  = Vector3.back;
            var right = Vector3.right;
            var left  = Vector3.left;

            while (rayIndex < raycastCount)
            {
                if (EditorUtility.DisplayCancelableProgressBar(
                        "Generating Point Cloud",
                        string.Format("{0}/{1} raycasts completed", rayIndex, raycastCount),
                        (float)rayIndex / raycastCount))
                {
                    EditorUtility.ClearProgressBar();
                    GUIUtility.ExitGUI();
                    break;
                }

                for (var i = 0; i < k_RaycastProgressBatchSize && rayIndex < raycastCount; i++, rayIndex++)
                {
                    var        origin    = k_RayOrigins[rayIndex];
                    var        direction = RandomRayDirection();
                    RaycastHit raycastHit;
                    if (!tempPhysicsScene.Raycast(origin, direction, out raycastHit, maxHitDistance))
                    {
                        continue;
                    }

                    var point  = raycastHit.point;
                    var normal = raycastHit.normal;

                    if (Vector3.Angle(normal, up) <= normalToleranceAngle && upGridBounds.Contains(point))
                    {
                        k_UpGridPoints.Add(point);
                    }

                    if (Vector3.Angle(normal, down) <= normalToleranceAngle && downGridBounds.Contains(point))
                    {
                        k_DownGridPoints.Add(point);
                    }

                    if (Vector3.Angle(normal, k_Forward) <= normalToleranceAngle && forwardGridBounds.Contains(point))
                    {
                        k_ForwardGridPoints.Add(point);
                    }

                    if (Vector3.Angle(normal, back) <= normalToleranceAngle && backGridBounds.Contains(point))
                    {
                        k_BackGridPoints.Add(point);
                    }

                    if (Vector3.Angle(normal, right) <= normalToleranceAngle && rightGridBounds.Contains(point))
                    {
                        k_RightGridPoints.Add(point);
                    }

                    if (Vector3.Angle(normal, left) <= normalToleranceAngle && leftGridBounds.Contains(point))
                    {
                        k_LeftGridPoints.Add(point);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            EditorSceneManager.ClosePreviewScene(tempPreviewScene);

            // Reset the seed so other uses of Random are not deterministic
            Random.InitState((int)DateTime.Now.Ticks);

            // Generate voxel grids from point cloud
            var voxelSize = voxelGenerationParams.voxelSize;

            s_UpVoxelGrid      = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Up, upGridBounds, voxelSize, planeFindingParams);
            s_DownVoxelGrid    = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Down, downGridBounds, voxelSize, planeFindingParams);
            s_ForwardVoxelGrid = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Forward, forwardGridBounds, voxelSize, planeFindingParams);
            s_BackVoxelGrid    = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Back, backGridBounds, voxelSize, planeFindingParams);
            s_RightVoxelGrid   = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Right, rightGridBounds, voxelSize, planeFindingParams);
            s_LeftVoxelGrid    = new PlaneExtractionVoxelGrid(VoxelGridOrientation.Left, leftGridBounds, voxelSize, planeFindingParams);
            s_UpVoxelGrid.AddPoints(k_UpGridPoints);
            s_DownVoxelGrid.AddPoints(k_DownGridPoints);
            s_ForwardVoxelGrid.AddPoints(k_ForwardGridPoints);
            s_BackVoxelGrid.AddPoints(k_BackGridPoints);
            s_RightVoxelGrid.AddPoints(k_RightGridPoints);
            s_LeftVoxelGrid.AddPoints(k_LeftGridPoints);
        }
コード例 #15
0
 private void OnDisable()
 {
     previewRenderUtility?.Cleanup();
     EditorSceneManager.ClosePreviewScene(previewScene);
     previewRenderUtility = null;
 }
コード例 #16
0
 /// <summary>Clear and close the stage's scene.</summary>
 public void Dispose()
 {
     Clear(persistent: true);
     EditorSceneManager.ClosePreviewScene(m_PreviewScene);
 }
コード例 #17
0
 void OnDisable()
 {
     EditorSceneManager.ClosePreviewScene(m_Scene);
 }