private void DrawDependencyListElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            var list        = m_DependenciesList.serializedProperty;
            var dependency  = list.GetArrayElementAtIndex(index);
            var packageName = dependency.FindPropertyRelative("packageName");
            var version     = dependency.FindPropertyRelative("version");

            var w = rect.width;

            rect.x                 += 4;
            rect.width              = w / 3 * 2 - 2;
            rect.height            -= EditorGUIUtility.standardVerticalSpacing;
            packageName.stringValue = EditorGUI.DelayedTextField(rect, packageName.stringValue);

            if (!IsNullOrEmptyTrim(packageName.stringValue) && !PackageValidation.ValidateName(packageName.stringValue))
            {
                errorMessages.Add($"Invalid Dependency Package Name '{packageName.stringValue}'");
            }

            using (new EditorGUI.DisabledScope(IsNullOrEmptyTrim(packageName.stringValue)))
            {
                rect.x             += w / 3 * 2;
                rect.width          = w / 3 - 4;
                version.stringValue = EditorGUI.DelayedTextField(rect, version.stringValue);

                if (!IsNullOrEmptyTrim(version.stringValue) && !PackageValidation.ValidateVersion(version.stringValue))
                {
                    errorMessages.Add(
                        $"Invalid Dependency Version '{version.stringValue}' for '{packageName.stringValue}'");
                }
            }
        }
Esempio n. 2
0
        private static void ValidateOptions(PackageTemplateOptions options)
        {
            var errors = new List <string>();
            var requiredErrorMessage = L10n.Tr("{0} is required");

            options.name = options.name?.Trim();
            if (string.IsNullOrEmpty(options.name))
            {
                errors.Add(string.Format(requiredErrorMessage, nameof(options.name)));
            }
            else if (!PackageValidation.ValidateName(options.name))
            {
                errors.Add(string.Format(L10n.Tr("Package name [{0}] is invalid"), options.name));
            }
            else if (PackageInfo.GetAll().Any(p => p.name == options.name))
            {
                errors.Add(string.Format(L10n.Tr("The project already contains a package with the name [{0}]."), options.name));
            }

            options.displayName = options.displayName?.Trim();
            if (string.IsNullOrEmpty(options.displayName))
            {
                errors.Add(string.Format(requiredErrorMessage, nameof(options.displayName)));
            }

            options.rootNamespace = options.rootNamespace?.Trim();
            if (!string.IsNullOrEmpty(options.rootNamespace) && !ValidateRootNamespace(options.rootNamespace))
            {
                errors.Add(string.Format(L10n.Tr("[{0}] is not a valid namespace"), options.rootNamespace));
            }

            options.templateFolder = options.templateFolder?.Trim();
            if (string.IsNullOrEmpty(options.templateFolder))
            {
                errors.Add(string.Format(requiredErrorMessage, nameof(options.templateFolder)));
            }
            else if (!Directory.Exists(options.templateFolder))
            {
                errors.Add(string.Format(L10n.Tr("The directory [{0}] does not exist"), options.templateFolder));
            }

            if (errors.Count > 0)
            {
                var invalidParamMsg = string.Format(L10n.Tr("{0} parameter is invalid"), nameof(options));
                var errorMsg        = string.Join(Environment.NewLine, errors.ToArray());
                throw new ArgumentException($"{invalidParamMsg}:{Environment.NewLine}{errorMsg}");
            }
        }
Esempio n. 3
0
        private void PerformValidation()
        {
            if (!PackageValidation.ValidateName(m_Name.stringValue))
            {
                errorMessages.Add($"Invalid Package Name '{m_Name.stringValue}'");
            }

            if (!PackageValidation.ValidateVersion(m_Version.stringValue))
            {
                errorMessages.Add($"Invalid Version '{m_Version.stringValue}'");
            }

            if (m_UnityVersionEnabled.boolValue)
            {
                if (!PackageValidation.ValidateUnityVersion(m_UnityMajor.stringValue, m_UnityMinor.stringValue,
                                                            m_UnityRelease.stringValue))
                {
                    var unityVersion = string.Join(".", new[] { m_UnityMajor.stringValue, m_UnityMinor.stringValue });
                    if (!IsNullOrEmptyTrim(m_UnityRelease.stringValue))
                    {
                        unityVersion += "." + m_UnityRelease.stringValue.Trim();
                    }

                    errorMessages.Add($"Invalid Unity Version '{unityVersion}'");
                }
            }

            if (IsNullOrEmptyTrim(m_DisplayName.stringValue) || m_DisplayName.stringValue.Trim().Length == 0)
            {
                warningMessages.Add("Display name should be provided.");
            }

            if (IsNullOrEmptyTrim(m_Description.stringValue) || m_Description.stringValue.Trim().Length == 0)
            {
                warningMessages.Add("Package description should be provided.");
            }

            if ((PackageVisibility)m_Visibility.intValue == PackageVisibility.AlwaysHidden)
            {
                warningMessages.Add("This package and all its assets will be hidden by default in Editor because its visibility is set to 'Always Hidden'");
            }
            if ((PackageVisibility)m_Visibility.intValue == PackageVisibility.AlwaysVisible)
            {
                warningMessages.Add("This package and all its assets will be visible by default in Editor because its visibility is set to 'Always Visible'");
            }
            else
            {
                if (IsNullOrEmptyTrim(packageState.info.type))
                {
                    warningMessages.Add("This package and all its assets will be hidden by default in Editor because its type is empty");
                }
                else if (PackageInfo.GetPredefinedHiddenByDefaultPackageTypes().Contains(packageState.info.type))
                {
                    warningMessages.Add($"This package and all its assets will be hidden by default in Editor because its type is '{packageState.info.type}'");
                }
                else
                {
                    warningMessages.Add($"This package and all its assets will be visible by default in Editor because its type is '{packageState.info.type}'");
                }
            }
        }