Exemple #1
0
        private void OnWizardCreate()
        {
            try {
                ScriptMetaData newMetaData = new ScriptMetaData(
                    humanReadableName, dataType, referability, menuOrder, builtin
                    );

                if (InEditMode)
                {
                    editTarget.RebuildFiles(newMetaData);
                }
                else
                {
                    VariableTypeBuilder.CreateNewVariableType(
                        newMetaData,
                        targetFolder.Path
                        );
                }

                // It worked, so we can go ahead and save the path now
                EditorPrefs.SetString(PathPref, targetFolder.Path);
            }
            catch (System.Exception e) {
                //Debug.LogError(e.Message);
                EditorUtility.DisplayDialog(
                    title:   "Couldn't Create Scripts!",
                    message: e.Message,
                    ok:      "Go back"
                    );

                // Re-open the menu.
                //CreateWizard(humanReadableName, dataType, referability, targetFolder.Path);
                ReopenWizard(this);
            }
        }
        private void OnWizardCreate()
        {
            try {
                VariableTypeBuilder.CreateNewVariableType(
                    humanReadableName,
                    dataType,
                    referability,
                    targetFolder.Path
                    );

                // It worked, so we can go ahead and save the path now
                EditorPrefs.SetString(PathPref, targetFolder.Path);
            }
            catch (System.Exception e) {
                //Debug.LogError(e.Message);
                EditorUtility.DisplayDialog(
                    title:   "Couldn't Create Scripts!",
                    message: e.Message,
                    ok:      "Go back"
                    );

                // Re-open the menu.
                CreateWizard(humanReadableName, dataType, referability, targetFolder.Path);
            }
        }
Exemple #3
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);
        }