private string PromptForNewString(string initPathRel)
        {
            bool   valid      = false;
            string newPathAbs = "";
            string newPathRel = "";

            do
            {
                newPathAbs = EditorUtility.OpenFolderPanel("Choose a target folder", initPathRel, "");

                if (string.IsNullOrEmpty(newPathAbs))
                {
                    // They must have canceled or something
                    newPathRel = initPathRel;
                    valid      = true;
                }
                else
                {
                    newPathRel = UnityPathUtils.AbsoluteToRelative(newPathAbs);

                    valid = UnityPathUtils.IsRelativePath(newPathRel);

                    if (!valid)
                    {
                        EditorUtility.DisplayDialog(
                            title: "Invalid Destination",
                            message: "You must pick a folder within the project's Assets folder!",
                            ok: "OK"
                            );
                    }
                }
            } while(!valid);

            return(newPathRel);
        }
Пример #2
0
        /// <summary>
        /// Rebuild the files associated with this type based upon its meta data.
        /// This can potentially delete scripts if the templates don't
        /// explicitly build them.
        ///
        /// Scripts are dumped into the folder pointed to by DominantPath.
        /// </summary>
        /// <param name="newMetaData">
        /// The new metadata to use. This simply means that the new scripts
        /// will use this metadata, and then we'll delete old scripts which
        /// haven't been overriden. It does NOT mean that files will get
        /// renamed.
        /// </param>
        /// <returns>The paths of the new/modified files.</returns>
        public List <string> RebuildFiles(ScriptMetaData newMetaData)
        {
            // We'll save the file paths for later... we can never really
            // trust that things won't get updated after we modify the files.
            string[] origPaths = GUIDs;
            for (int i = 0; i < origPaths.Length; i++)
            {
                origPaths[i] = UnityPathUtils.LocalizeDirectorySeparators(
                    AssetDatabase.GUIDToAssetPath(origPaths[i])
                    );
            }

            List <string> resultFiles = VariableTypeBuilder.CreateNewVariableType(
                newMetaData,
                UnityPathUtils.AbsoluteToRelative(DominantPath),
                overrideExisting: true
                );

            // Once we perform the reset, we'll want to clean up any extra files
            // which were not in our set of templates. If we find any,
            // we'll make sure to delete 'em and get everything cleaned up.
            foreach (string origPath in origPaths)
            {
                if (!resultFiles.Contains(origPath))
                {
                    AssetDatabase.DeleteAsset(origPath);
                }
            }

            return(resultFiles);
        }
Пример #3
0
 /// <summary>
 /// Tests if the path given is valid and can be stored.
 /// </summary>
 /// <returns>The new path.</returns>
 /// <param name="newPath">New path.</param>
 private static string TestNewPath(string newPath)
 {
     // This function exists because we need to be able to use this
     // logic inside the constructor. However, as a struct, the constructor
     // cannot access the path field.
     newPath = UnityPathUtils.AbsoluteToRelative(newPath);
     if (AssetDatabase.IsValidFolder(newPath))
     {
         return(newPath);
     }
     else
     {
         return("");
     }
 }