public static GameObject CreateNewPalette(string folder_path, string name, Grid.CellLayout layout, GridPalette.CellSizing cell_sizing, Vector3 cell_size, Grid.CellSwizzle swizzle) { var tmp_go = new GameObject(name); var grid = tmp_go.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 = cell_size; grid.cellLayout = layout; grid.cellSwizzle = swizzle; CreateNewLayer(tmp_go, "Layer1", layout); var path = AssetDatabase.GenerateUniqueAssetPath(folder_path + "/" + name + ".prefab"); Object prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(tmp_go, path, InteractionMode.AutomatedAction); var palette = GridPalette.CreateInstance <GridPalette>(); palette.name = "Palette Settings"; palette.cellSizing = cell_sizing; AssetDatabase.AddObjectToAsset(palette, prefab); PrefabUtility.ApplyPrefabInstance(tmp_go, InteractionMode.AutomatedAction); AssetDatabase.Refresh(); GameObject.DestroyImmediate(tmp_go); return(AssetDatabase.LoadAssetAtPath <GameObject>(path)); }
public static GameObject CreateNewPaletteNamed(string name, Grid.CellLayout layout, GridPalette.CellSizing cellSizing, Vector3 cellSize, Grid.CellSwizzle swizzle) { string defaultPath = ProjectBrowser.s_LastInteractedProjectBrowser ? ProjectBrowser.s_LastInteractedProjectBrowser.GetActiveFolderPath() : "Assets"; string folderPath = EditorUtility.SaveFolderPanel("Create palette into folder ", defaultPath, ""); folderPath = FileUtil.GetProjectRelativePath(folderPath); if (string.IsNullOrEmpty(folderPath)) { return(null); } return(CreateNewPalette(folderPath, name, layout, cellSizing, cellSize, swizzle)); }
public static Vector3 Swizzle(this Vector3 v, Grid.CellSwizzle swizz) { return(Grid.Swizzle(swizz, v)); }
public static Vector3 Swizzle(this Vector2 v, Grid.CellSwizzle swizz) { Vector3 vect = v; return(vect.Swizzle(swizz)); }
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.CreateEmptyPrefab(path); GridPalette palette = GridPalette.CreateInstance <GridPalette>(); palette.name = "Palette Settings"; palette.cellSizing = cellSizing; AssetDatabase.AddObjectToAsset(palette, prefab); PrefabUtility.ReplacePrefab(temporaryGO, prefab, ReplacePrefabOptions.Default); AssetDatabase.Refresh(); GameObject.DestroyImmediate(temporaryGO); return(AssetDatabase.LoadAssetAtPath <GameObject>(path)); }