public static TextAsset SaveTextToFile(DBEntry dbEntry, string key, string text)
        {
            var dbEntryPath      = AssetDatabase.GetAssetPath(dbEntry).Replace(".asset", "");
            var dataPathSplitted = Application.dataPath.Split(Path.DirectorySeparatorChar);

            dataPathSplitted = dataPathSplitted.SubArray(0, dataPathSplitted.Length - 1).ToArray();
            var assetDirectoryPath = Path.Combine(Path.Combine(dataPathSplitted), dbEntryPath);

            var assetPath = $"{assetDirectoryPath}@{key}.txt";

#if UNITY_EDITOR_OSX
            if (!assetPath.StartsWith("/"))
            {
                assetPath = $"/{assetPath}";
            }
#endif

            SaveTextToFile(assetPath, text);

            return(dbEntry.Load <TextAsset>(key));
        }
Esempio n. 2
0
    public static void CreateOrAddComponentToPrefab <T>(DBEntry dbEntry, string key, System.Action <T> onAdding) where T : Component
    {
        var originalPrefab = dbEntry.Load <GameObject>(key);

#if UNITY_2018_3_OR_NEWER
        var path      = AssetDatabase.GetAssetPath(originalPrefab);
        var prefabGO  = PrefabUtility.LoadPrefabContents(path);
        var component = prefabGO.GetComponent <T>();
        if (component == null)
        {
            component = prefabGO.AddComponent <T>();
        }
        onAdding.SafeInvoke(component);
        PrefabUtility.SaveAsPrefabAsset(prefabGO, path);
#else
        var component = originalPrefab.GetComponent <ComponentType>();
        if (component == null)
        {
            component = originalPrefab.AddComponent <ComponentType>();
        }
        onAdding.SafeInvoke(component);
#endif
        EditorUtility.SetDirty(originalPrefab);
    }
 /**
  * <summary>Loads Sprite associated with DBEntry and with name X@Y where X is DBEntry name and Y is key</summary>
  * <param name="item">DBEntry</param>
  * <param name="key">Key for Sprite name</param>
  */
 public static Sprite LoadSprite(this DBEntry item, string key)
 {
     return(item.Load <Sprite>(key));
 }
        /**
         * <summary>Returns content of TextAsset, associated with DBEntry and with name X@Text where X is DBEntry name</summary>
         */
        public static string LoadText(this DBEntry item)
        {
            var textAsset = item.Load <TextAsset>("Text");

            return(textAsset.text);
        }