public static bool MakeIcon(TileWand tileWand) { if (tileWand != null && tileWand.textureForGUI != null) { tileWand.sprites = tileWand.GetSpriteRenderers().Select(s => s.sprite).ToArray(); tileWand.colors = tileWand.GetColors().ToArray(); Texture2D _tex = tileWand.textureForGUI.MakeIcon(ref tileWand.sprites, ref tileWand.colors); if (_tex == null) { tileWand.textureForGUI.bCorrupted = false; return(true); } if (tileWand.textureForGUI.texture == null || !AssetDatabase.Contains(tileWand.textureForGUI.texture)) { AssetDatabase.AddObjectToAsset(_tex, tileWand); tileWand.textureForGUI.texture = _tex; } else { EditorUtility.CopySerialized(_tex, tileWand.textureForGUI.texture); } tileWand.textureForGUI.bCorrupted = false; EditorUtility.SetDirty(tileWand.textureForGUI.texture); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(true); } return(false); }
public static TileWand CreateAsset(string path, IsoTile tile) { TileWand newTileWand = ScriptableObject.CreateInstance <TileWand>(); string _path = AssetDatabase.GenerateUniqueAssetPath(path + ".asset"); AssetDatabase.CreateAsset(newTileWand, _path); GameObject tileGameObject = tile.gameObject; if (!PrefabHelper.IsPrefab(tileGameObject)) { tileGameObject = PrefabHelper.CreatePrefab(AssetDatabase.GenerateUniqueAssetPath(path + ".prefab"), tileGameObject); } // Revert All Lightings tile = IsoTile.Find(tileGameObject); tile.LightRecivers_RevertAll(); tile.LightRecivers_RemoveAll(false); IsometricSortingOrder iso = tile.GetComponent <IsometricSortingOrder>(); iso.Clear_Backup(false); newTileWand.Prefab = tileGameObject; MakeIcon(newTileWand); if (newTileWand != null) { // AssetDatabase.AddObjectToAsset(tilePrefab, newTileWand); EditorUtility.SetDirty(newTileWand); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } if (newTileWand == null) { newTileWand = AssetDatabase.LoadAssetAtPath <TileWand>(_path); } return(newTileWand); }