Example #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);
            }
        }
Example #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);
        }
        private void OnWizardUpdate()
        {
            string errorMsg = "";
            string helpMsg  = "";

            bool validName = false;
            bool validType = false;

            // We need to check for null, because the string is occasionally
            // null upon wizard's creation
            if (string.IsNullOrEmpty(humanReadableName))
            {
                helpMsg += "Please enter the Human Readable Name.";
            }
            else if (!VariableTypeBuilder.IsValidName(humanReadableName))
            {
                errorMsg +=
                    "The Human Readable Name is not a valid C# variable" +
                    " name!\n";
            }
            else if (ScriptFileManager.IsNameTaken(humanReadableName))
            {
                errorMsg +=
                    "The Human Readable Name conflicts with another," +
                    " already existing variable type!\n";
            }
            else
            {
                validName = true;
            }

            helpMsg += '\n';                    // Force push the next line into a blank field.


            if (string.IsNullOrEmpty(dataType))
            {
                helpMsg += "Please enter the Data Type.";
            }
            else if (!VariableTypeBuilder.IsValidName(dataType))
            {
                errorMsg += "The Data Type is not a valid C# variable name!";
            }
            else
            {
                validType = true;
            }


            helpMsg += '\n';                    // Force push the next line into a blank field.


            if (referability == ReferabilityMode.Unknown)
            {
                helpMsg += "Please choose a referability mode.";
            }


            // We use Trim here because having extra newlines looks ugly.
            errorString = errorMsg.Trim();
            helpString  = helpMsg;

            isValid = (
                validName &&
                validType &&
                referability != ReferabilityMode.Unknown
                );
        }