public void ResetPreviewInstance() { if (m_PreviewUtility == null) { InitPreviewUtility(); } DestroyPreviewInstance(); if (palette != null) { m_PaletteInstance = previewUtility.InstantiatePrefabInScene(palette); // Prevent palette from overriding the prefab while it is active, unless user saves the palette PrefabUtility.DisconnectPrefabInstance(m_PaletteInstance); EditorUtility.InitInstantiatedPreviewRecursive(m_PaletteInstance); m_PaletteInstance.transform.position = new Vector3(0, 0, 0); m_PaletteInstance.transform.rotation = Quaternion.identity; m_PaletteInstance.transform.localScale = Vector3.one; string assetPath = AssetDatabase.GetAssetPath(palette); GridPalette paletteAsset = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath); if (paletteAsset != null) { if (paletteAsset.cellSizing == GridPalette.CellSizing.Automatic) { Grid grid = m_PaletteInstance.GetComponent <Grid>(); if (grid != null) { grid.cellSize = GridPaletteUtility.CalculateAutoCellSize(grid, grid.cellSize); } else { Debug.LogWarning("Grid component not found from: " + assetPath); } } } else { Debug.LogWarning("GridPalette subasset not found from: " + assetPath); } foreach (var renderer in m_PaletteInstance.GetComponentsInChildren <Renderer>()) { renderer.gameObject.layer = Camera.PreviewCullingLayer; renderer.allowOcclusionWhenDynamic = false; } foreach (var transform in m_PaletteInstance.GetComponentsInChildren <Transform>()) { transform.gameObject.hideFlags = HideFlags.HideAndDontSave; } PreviewRenderUtility.SetEnabledRecursive(m_PaletteInstance, false); clipboardView.ResetPreviewMesh(); } }
public void ResetPreviewInstance() { if (this.m_PreviewUtility == null) { this.InitPreviewUtility(); } this.DestroyPreviewInstance(); if (this.palette != null) { this.m_PaletteInstance = this.previewUtility.InstantiatePrefabInScene(this.palette); PrefabUtility.DisconnectPrefabInstance(this.m_PaletteInstance); EditorUtility.InitInstantiatedPreviewRecursive(this.m_PaletteInstance); this.m_PaletteInstance.transform.position = new Vector3(0f, 0f, 0f); this.m_PaletteInstance.transform.rotation = Quaternion.identity; this.m_PaletteInstance.transform.localScale = Vector3.one; string assetPath = AssetDatabase.GetAssetPath(this.palette); GridPalette gridPalette = AssetDatabase.LoadAssetAtPath <GridPalette>(assetPath); if (gridPalette != null) { if (gridPalette.cellSizing == GridPalette.CellSizing.Automatic) { Grid component = this.m_PaletteInstance.GetComponent <Grid>(); if (component != null) { component.cellSize = GridPaletteUtility.CalculateAutoCellSize(component, component.cellSize); } else { Debug.LogWarning("Grid component not found from: " + assetPath); } } } else { Debug.LogWarning("GridPalette subasset not found from: " + assetPath); } Renderer[] componentsInChildren = this.m_PaletteInstance.GetComponentsInChildren <Renderer>(); for (int i = 0; i < componentsInChildren.Length; i++) { Renderer renderer = componentsInChildren[i]; renderer.gameObject.layer = Camera.PreviewCullingLayer; renderer.allowOcclusionWhenDynamic = false; } Transform[] componentsInChildren2 = this.m_PaletteInstance.GetComponentsInChildren <Transform>(); for (int j = 0; j < componentsInChildren2.Length; j++) { Transform transform = componentsInChildren2[j]; transform.gameObject.hideFlags = HideFlags.HideAndDontSave; } PreviewRenderUtility.SetEnabledRecursive(this.m_PaletteInstance, false); this.clipboardView.ResetPreviewMesh(); } }
//instantiate all prefabs inside the basic level prefab private void PrepareScene() { /* Not necessary anymore since the Soundmanager has been added to the GameController * //Instantiate the Soundmanager * GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/" + pathSound); * PrefabUtility.InstantiatePrefab(prefab); */ //Instantiate the basic level GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + pathBasic); /*GameObject prefabClone =*/ PrefabUtility.InstantiatePrefab(prefab) /*as GameObject*/; //Instantiate the basic dynamic level prefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/" + pathDynamic); UnityEngine.Object dynamicLevel = PrefabUtility.InstantiatePrefab(prefab); PrefabUtility.DisconnectPrefabInstance(dynamicLevel); /*prefabClone.transform.DetachChildren(); * * DestroyImmediate(prefabClone);*/ }