예제 #1
0
        public static bool SaveAsset(ItemEffect newEffect, string itemName, string effectName)
        {
            string itemPath = GroundlessSettings.GetOrCreateSettings().ItemPath;
            //format string
            string fileName = itemName.ToTitleCase();

            fileName = fileName.Replace(" ", "");
            //check for min length
            if (fileName.Length <= 3)
            {
                Debug.LogWarning("Effect Name not long enough");
                return(false);
            }
            //check if Folder already exists
            if (!AssetDatabase.IsValidFolder(itemPath + "/" + fileName))
            {
                //create new Folder
                AssetDatabase.CreateFolder(itemPath, fileName);
            }
            AssetDatabase.CreateAsset(newEffect, itemPath + "/" + fileName + "/" + fileName.ToShortVersion() + "_" + effectName + ".asset");
            UnityEditor.VersionControl.Provider.Checkout(UnityEditor.VersionControl.Provider.GetAssetByPath(itemPath + "/" + fileName + "/" + fileName.ToShortVersion() + "_" + effectName + ".asset")
                                                         , UnityEditor.VersionControl.CheckoutMode.Both);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            return(true);
        }
예제 #2
0
        /// <summary>
        /// saves Item Scriptable Object via AssetDatabase in the project
        /// </summary>
        /// <param name="newItem">item to save</param>
        /// <returns>true if successful</returns>
        public static bool SaveAsset(ItemData newItem)
        {
            string itemPath = GroundlessSettings.GetOrCreateSettings().ItemPath;
            //format string
            string fileName = newItem.Name.ToTitleCase();

            fileName = fileName.Replace(" ", "");
            //check for min length
            if (fileName.Length <= 3)
            {
                Debug.LogWarning("ItemAsset Name not long enough");
                return(false);
            }

            string folderPath = newItem.FolderPath;

            if (string.IsNullOrEmpty(folderPath))
            {
                folderPath = itemPath + "/" + fileName;
            }
            //check if Folder already exists
            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                //create new Folder
                AssetDatabase.CreateFolder(itemPath, fileName);
            }

            AssetDatabase.CreateAsset(newItem, folderPath + "/" + fileName + ".asset");
            UnityEditor.VersionControl.Provider.Checkout(UnityEditor.VersionControl.Provider.GetAssetByPath(folderPath + "/" + fileName + ".asset")
                                                         , UnityEditor.VersionControl.CheckoutMode.Both);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            return(true);
        }
 protected override void OnDestroy()
 {
     base.OnDestroy();
     if (GroundlessSettings.GetOrCreateSettings().ConfirmWhenLoadingOrQuitting)
     {
         if (EditorUtility.DisplayDialog("Save", "Do you want to save?", "Yes", "No"))
         {
             SaveAll();
         }
     }
 }
예제 #4
0
        public static string GetItemFolderPath(string name)
        {
            string itemPath   = GroundlessSettings.GetOrCreateSettings().ItemPath;
            var    folderName = name.ToTitleCase();

            string path = "";

            if (!AssetDatabase.IsValidFolder(itemPath + "/" + folderName))
            {
                throw new NotSupportedException("Folder " + name + " doesn't exist");
            }

            path = itemPath + "/" + folderName;
            return(path);
        }
예제 #5
0
        public static ItemData[] LoadItemAssets()
        {
            string          itemPath = GroundlessSettings.GetOrCreateSettings().ItemPath;
            List <ItemData> items    = new List <ItemData>();

            try
            {
                string[] assetsGuid = AssetDatabase.FindAssets("t:ItemData", new[] { itemPath });

                if (assetsGuid == null || assetsGuid.Length <= 0)
                {
                    return(null);
                }                                                                  //return if folder doesn't contain items

                //Iterate over guids to get path and get ItemData from path and add each item to items list
                items.AddRange(assetsGuid.Select(t => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(t), typeof(ItemData)) as ItemData));
            }
            catch (System.Exception)
            {
                items = null;
            }
            return(items?.ToArray());
        }