Exemple #1
0
        /// <summary>
        /// Ensures this path will exist if it does not already.
        /// </summary>
        public static void Path(this HUMIO.Data.Ensure ensure)
        {
            var legalPath = !ensure.path.Contains(".") ? ensure.path : ensure.path.Remove(ensure.path.LastIndexOf("/") + 1, (ensure.path.Length - 1) - ensure.path.LastIndexOf("/"));

            if (!Directory.Exists(legalPath))
            {
                Directory.CreateDirectory(legalPath);
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves a new asset instance at path if it doesn't already exist. Optionally you can immediately refresh the database after saving.
        /// </summary>
        public static T Asset <T>(this HUMIO.Data.Ensure ensure, string filename, bool ensurePath = false, bool refresh = false)
            where T : ScriptableObject
        {
            if (ensurePath)
            {
                ensure.Path();
            }
            var asset = AssetDatabase.LoadAssetAtPath <T>(ensure.path + filename);

            if (asset == null)
            {
                asset = ScriptableObject.CreateInstance <T>();
                asset.Save().Asset(ensure.path.Remove().EndSlash() + "/" + filename, refresh);
            }
            return(asset);
        }