public static GameObject CreateNewPalette(string folderPath, string name, Grid.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize, Grid.CellSwizzle swizzle) { GameObject temporaryGO = new GameObject(name); Grid grid = temporaryGO.AddComponent <Grid>(); // We set size to kEpsilon to mark this as new uninitialized palette // Nice default size can be decided when first asset is dragged in grid.cellSize = cellSize; grid.cellLayout = layout; grid.cellSwizzle = swizzle; CreateNewLayer(temporaryGO, "Layer1", layout); string path = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + name + ".prefab"); Object prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(temporaryGO, path, InteractionMode.AutomatedAction); GridPalette palette = GridPalette.CreateInstance <GridPalette>(); palette.name = "Palette Settings"; palette.cellSizing = cellSizing; AssetDatabase.AddObjectToAsset(palette, prefab); PrefabUtility.ApplyPrefabInstance(temporaryGO); AssetDatabase.Refresh(); GameObject.DestroyImmediate(temporaryGO); return(AssetDatabase.LoadAssetAtPath <GameObject>(path)); }
private void RefreshPalettesCache() { if (ScriptableSingleton <GridPalettes> .instance.m_PalettesCache == null) { ScriptableSingleton <GridPalettes> .instance.m_PalettesCache = new List <GameObject>(); } string[] array = AssetDatabase.FindAssets("t:GridPalette"); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string guid = array2[i]; string assetPath = AssetDatabase.GUIDToAssetPath(guid); GridPalette gridPalette = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GridPalette)) as GridPalette; if (gridPalette != null) { string assetPath2 = AssetDatabase.GetAssetPath(gridPalette); GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(assetPath2) as GameObject; if (gameObject != null) { this.m_PalettesCache.Add(gameObject); } } } this.m_PalettesCache.Sort((GameObject x, GameObject y) => string.Compare(x.name, y.name, StringComparison.OrdinalIgnoreCase)); }
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(); } }
public static GameObject CreateNewPalette(string folderPath, string name, GridLayout.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize) { GameObject gameObject = new GameObject(name); Grid grid = gameObject.AddComponent <Grid>(); grid.cellSize = cellSize; grid.cellLayout = layout; GridPaletteUtility.CreateNewLayer(gameObject, "Layer1", layout); string text = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + name + ".prefab"); UnityEngine.Object @object = PrefabUtility.CreateEmptyPrefab(text); GridPalette gridPalette = ScriptableObject.CreateInstance <GridPalette>(); gridPalette.name = "Palette Settings"; gridPalette.cellSizing = cellSizing; AssetDatabase.AddObjectToAsset(gridPalette, @object); PrefabUtility.ReplacePrefab(gameObject, @object, ReplacePrefabOptions.Default); AssetDatabase.Refresh(); UnityEngine.Object.DestroyImmediate(gameObject); return(AssetDatabase.LoadAssetAtPath <GameObject>(text)); }
private void RefreshPalettesCache() { if (instance.m_PalettesCache == null) { instance.m_PalettesCache = new List <GameObject>(); } string[] guids = AssetDatabase.FindAssets("t:GridPalette"); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); GridPalette paletteAsset = AssetDatabase.LoadAssetAtPath(path, typeof(GridPalette)) as GridPalette; if (paletteAsset != null) { string assetPath = AssetDatabase.GetAssetPath(paletteAsset); GameObject palette = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject; if (palette != null) { m_PalettesCache.Add(palette); } } } m_PalettesCache.Sort((x, y) => String.Compare(x.name, y.name, StringComparison.OrdinalIgnoreCase)); }