コード例 #1
0
        /// <summary>
        /// todo not contextual enough to a generalized folder field, might apply differently later
        /// </summary>
        public string DrawFolderField()
        {
            string assetPath      = Path.GetFullPath(_originalPath);
            string defaultRelPath = LDtkPathUtility.DirectoryOfAssetPath(assetPath);

            if (!DrawFieldAndButton(defaultRelPath))
            {
                string propStringValue = _pathProp.stringValue;
                if (!propStringValue.IsNullOrEmpty())
                {
                    return(propStringValue);
                }
                return(defaultRelPath);
            }

            string destinationPath = EditorUtility.OpenFolderPanel(_filePanelDescription,
                                                                   defaultRelPath,
                                                                   "");

            if (destinationPath.StartsWith(Application.dataPath))
            {
                destinationPath = "Assets" + destinationPath.Substring(Application.dataPath.Length);
            }

            if (!string.IsNullOrEmpty(destinationPath) && AssetDatabase.IsValidFolder(destinationPath))
            {
                _pathProp.stringValue = destinationPath;
            }
            else
            {
                Debug.LogWarning($"LDtk Export: Cannot specify a folder outside of the Unity project\n{destinationPath}");
            }

            return(_pathProp.stringValue);
        }
コード例 #2
0
        public string DrawPathField()
        {
            string assetPath = Path.GetFullPath(_originalPath);
            string csPath    = Path.ChangeExtension(assetPath, $".{_extension}");

            string defaultRelPath = GetRelativePath(assetPath, csPath);

            if (!DrawFieldAndButton(defaultRelPath))
            {
                string propStringValue = _pathProp.stringValue;
                if (!propStringValue.IsNullOrEmpty())
                {
                    return(_pathProp.stringValue);
                }
                return(defaultRelPath);
            }

            string destinationEnumPath = EditorUtility.SaveFilePanel(_filePanelDescription,
                                                                     Path.GetDirectoryName(csPath),
                                                                     Path.GetFileName(csPath), _extension);

            if (!string.IsNullOrEmpty(destinationEnumPath) && AssetDatabase.IsValidFolder(LDtkPathUtility.DirectoryOfAssetPath(destinationEnumPath)))
            {
                string relPath = GetRelativePath(assetPath, destinationEnumPath);
                relPath = LDtkPathUtility.CleanPathSlashes(relPath);
                _pathProp.stringValue = relPath;
            }
            else
            {
                Debug.LogWarning("LDtk Export: Cannot specify within a folder outside of the Unity project");
            }

            return(_pathProp.stringValue);
        }