Skip to content

Commit

Permalink
add more metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hieki-chan committed Mar 5, 2025
1 parent 49b4ff8 commit f3639bd
Show file tree
Hide file tree
Showing 68 changed files with 2,616 additions and 4,366 deletions.
12 changes: 10 additions & 2 deletions Assets/Editor/Resources/UnityDocfx/unity-docset.asset
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ MonoBehaviour:
build:
globalMetadata:
_appTitle: Unity Docfx
_appName:
_appFooter: 'Made by Unity-Docfx: https://github.com/lusties/unity-docfx'
_appName: Unity Documentaion
_appLogoPath: icon/bruh.jpg
_appLogoUrl:
_appFaviconPath: icon/favicon.ico
_enableSearch: 1
_disableContribution: 1
content:
- src:
files:
Expand All @@ -44,10 +48,14 @@ MonoBehaviour:
files:
- '*.yml'
dest: api
resource:
- files:
- icon/favicon.ico
- icon/bruh.jpg
dest: ../docs
template:
- default
- templates/darkfx
- templates/unity
TOC:
- name: Home
href: README.md to index.md
Expand Down
19 changes: 15 additions & 4 deletions Assets/UnityDocfx/Editor/DocfxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public static void OpenCmd(string command, EventHandler onDisposed, string cmdOp
/// <returns>A process configured to run the docfx command.</returns>
public static Process GetDocfxCommand(string argument, string folder)
{
string docfxJsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), folder, "docfx.json");
string docfxJsonFullPath = string.Join("/", folder, "docfx.json");
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C docfx \"{docfxJsonFullPath}\" {argument}",
Arguments = $"/C docfx {docfxJsonFullPath} {argument}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Expand Down Expand Up @@ -170,6 +170,8 @@ public static void GenDocfxJson(UnityDocset unityDocset)
{
// Gen buid.content
GenBuildContent(unityDocset);
// Gen build.resource
GenResource(unityDocset);

var settings = new JsonSerializerSettings
{
Expand Down Expand Up @@ -243,9 +245,18 @@ private static void GenBuildContent(UnityDocset unityDocset)
}
}

private static void GenTemplate(UnityDocset unityDocset)
private static void GenResource(UnityDocset unityDocset)
{
var template = unityDocset.docfxJson.build.template;
var resource = unityDocset.docfxJson.build.resource;
if (resource.Count == 0)
resource.Add(new Resource());
resource[0].files.Clear();
string _appFaviconPath = unityDocset.docfxJson.build.globalMetadata._appFaviconPath;
if(!_appFaviconPath.StartsWith("http"))
resource[0].files.Add(_appFaviconPath);
string _appLogoPath = unityDocset.docfxJson.build.globalMetadata._appLogoPath;
if (!_appFaviconPath.StartsWith("http"))
resource[0].files.Add(_appLogoPath);
}

private static void CopyReadmeToIndex(string folderPath)
Expand Down
44 changes: 16 additions & 28 deletions Assets/UnityDocfx/Editor/DocfxSetupTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void InstallationCheck()
}

//Help box message
HelpBox helpBox = new HelpBox(helpBoxMessage, helpBoxType);
UnityEngine.UIElements.HelpBox helpBox = new UnityEngine.UIElements.HelpBox(helpBoxMessage, helpBoxType);
helpBox.style.flexShrink = helpBox.style.flexGrow = 1;

VisualElement installInfoContainer = rootVisualElement.Q<VisualElement>("docfx").Q<VisualElement>("install-info");
Expand Down Expand Up @@ -234,37 +234,13 @@ void QueryMetadata()
};
srcListView.itemsChosen += (items) => { OnTOCItemSelected(); };
srcListView.selectedIndex = 0;

docfxSettingsContainer.Q<TextField>("_appTitle").BindProperty(FindProp("docfxJson.build.globalMetadata._appTitle"));
docfxSettingsContainer.Q<TextField>("_appFooter").BindProperty(FindProp("docfxJson.build.globalMetadata._appFooter"));
docfxSettingsContainer.Q<Toggle>("_enableSearch").BindProperty(FindProp("docfxJson.build.globalMetadata._enableSearch"));
}

void QueryOutputSettings()
{
VisualElement outputContainer = rootVisualElement.Q<VisualElement>("output-container");
var txtDest = outputContainer.Q<TextField>("dest");
txtDest.BindProperty(FindProp("docfxJson.build.dest"));

outputContainer.Q<Button>("btn-output-browse").RegisterCallback<ClickEvent>(evt =>
{
string outputDir = EditorUtility.OpenFolderPanel("Browse Output Directory", "", "");
if (!string.IsNullOrWhiteSpace(outputDir))
txtDest.value = outputDir;
});

outputContainer.Q<Button>("btn-output-view").RegisterCallback<ClickEvent>(evt =>
{
string folderPath = unityDocset.docfxJson.build.fullDest;
if (Directory.Exists(folderPath))
{
Process.Start("explorer.exe", folderPath);
}
else
{
EditorUtility.DisplayDialog("Path doesn't exist", $"Path: {folderPath} DOES NOT EXIST", "OK");
}
});
PathField destField = outputContainer.Q<PathField>();
destField.BindProperty(FindProp("docfxJson.build.dest"));
}

void QueryServerSettings()
Expand Down Expand Up @@ -293,6 +269,18 @@ void QueryServerSettings()
void QueryTemplateSettings()
{
VisualElement templateContainer = rootVisualElement.Q<VisualElement>("template-container");

// template metadata
string globalMetadata = "docfxJson.build.globalMetadata";
templateContainer.Q<TextField>("_appTitle").BindProperty(FindProp($"{globalMetadata}._appTitle"));
templateContainer.Q<TextField>("_appName").BindProperty(FindProp($"{globalMetadata}._appName"));
templateContainer.Q<TextField>("_appFooter").BindProperty(FindProp($"{globalMetadata}._appFooter"));
templateContainer.Q<PathField>("_appLogoPath").BindProperty(FindProp($"{globalMetadata}._appLogoPath"));
templateContainer.Q<PathField>("_appFaviconPath").BindProperty(FindProp($"{globalMetadata}._appFaviconPath"));
templateContainer.Q<Toggle>("_enableSearch").BindProperty(FindProp($"{globalMetadata}._enableSearch"));
templateContainer.Q<Toggle>("_disableContribution").BindProperty(FindProp($"{globalMetadata}._disableContribution"));

// template list
ListView templateList = templateContainer.Q<ListView>("list-templates");
templateList.itemsSource = unityDocset.docfxJson.build.template;

Expand Down Expand Up @@ -558,7 +546,7 @@ void BuildAndServeDocfxWithCmd()

void ServeDocfxCommand()
{
using Process docfxProcess = DocfxService.GetDocfxCommand("serve", unityDocset.folder);
using Process docfxProcess = DocfxService.GetDocfxCommand("--serve", unityDocset.folder);
docfxProcess.Start();
docfxProcess.BeginOutputReadLine();
docfxProcess.BeginErrorReadLine();
Expand Down
27 changes: 12 additions & 15 deletions Assets/UnityDocfx/Editor/Resources/SettingsLayout.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
<ui:Foldout text="Metadata" name="Foldout" value="false" class="label-s">
<ui:Instance template="horizontal-line" name="horizontal-line" />
<ui:VisualElement name="docfx-s-container" style="flex-grow: 1; font-size: 12px;">
<ui:ListView show-foldout-header="true" header-title="Src:" name="metadata-src" fixed-item-height="45" virtualization-method="DynamicHeight" reorderable="true" show-border="false" selection-type="Multiple" horizontal-scrolling="false" show-add-remove-footer="true" reorder-mode="Animated" />
<ui:TextField picking-mode="Ignore" label="Title:" value="Unity docfx title" name="_appTitle" />
<ui:TextField picking-mode="Ignore" label="Footer:" value="Unity docfx footer" name="_appFooter" multiline="true" />
<ui:Toggle label="Enable Search:" value="true" name="_enableSearch" />
<ui:Toggle label="Enable Darkmode:" value="true" />
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
<ui:TextField picking-mode="Ignore" label="Enabl" value="filler text" style="flex-shrink: 1; flex-grow: 1;" />
<ui:Button text="Button" parse-escape-sequences="true" display-tooltip-when-elided="true" style="width: 50px;" />
</ui:VisualElement>
<ui:ListView show-foldout-header="false" header-title="Src:" name="metadata-src" fixed-item-height="45" virtualization-method="DynamicHeight" reorderable="true" show-border="false" selection-type="Multiple" horizontal-scrolling="false" show-add-remove-footer="true" reorder-mode="Animated" show-bound-collection-size="true" />
</ui:VisualElement>
</ui:Foldout>
</ui:VisualElement>
Expand Down Expand Up @@ -57,9 +49,18 @@
</ui:Foldout>
</ui:VisualElement>
<ui:VisualElement name="template-container" class="settings-area" style="flex-grow: 1;">
<ui:Foldout text="Template" name="Foldout" value="false" class="label-s">
<ui:Foldout text="Template" name="Foldout" value="true" class="label-s">
<ui:Instance template="horizontal-line" name="horizontal-line" />
<ui:VisualElement style="flex-grow: 1; font-size: 12px;">
<ui:TextField picking-mode="Ignore" label="Title:" name="_appTitle" />
<ui:TextField picking-mode="Ignore" label="Footer:" name="_appFooter" multiline="true" />
<ui:TextField picking-mode="Ignore" label="App Name:" name="_appName" multiline="true" />
<Lustie.UnityDocfx.HelpBox text="Some templates do not support app name" message-type="Info" />
<Lustie.UnityDocfx.PathField Label="App Logo Path:" name="_appLogoPath" path-type="File" />
<Lustie.UnityDocfx.PathField Label="App Favicon Path:" name="_appFaviconPath" path-type="File" />
<ui:Toggle label="Enable Search:" value="true" name="_enableSearch" />
<ui:Toggle label="Disable Contribution" name="_disableContribution" />
<ui:VisualElement name="spacing" style="flex-grow: 1; height: 28px;" />
<ui:VisualElement style="flex-grow: 1; flex-direction: row; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-left-color: rgb(32, 32, 32); border-right-color: rgb(32, 32, 32); border-top-color: rgb(32, 32, 32); border-bottom-color: rgb(32, 32, 32); padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; border-top-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px;">
<ui:VisualElement style="flex-grow: 1; width: 40%;">
<ui:Label tabindex="-1" text="Avaiable templates:" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Label" style="margin-bottom: 6px; -unity-font-style: bold;" />
Expand All @@ -83,11 +84,7 @@
<ui:Label tabindex="-1" text="Output" parse-escape-sequences="true" display-tooltip-when-elided="true" class="label-s" style="margin-top: 4px; margin-right: 4px; margin-bottom: 4px; margin-left: 4px; -unity-text-align: middle-left;" />
</ui:VisualElement>
<ui:TextField picking-mode="Ignore" label="Folder:" value="filler text" name="txt-doc-folder" />
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
<ui:TextField picking-mode="Ignore" label="Output:" name="dest" tooltip="Destination of the final document web project containing index.html. If you are about to build with GitHub Pages, you should keep it in the &apos;docs&apos; folder." style="flex-shrink: 1; flex-grow: 1;" />
<ui:Button text="Browse" parse-escape-sequences="true" display-tooltip-when-elided="true" name="btn-output-browse" style="width: 50px;" />
<ui:Button text="View" parse-escape-sequences="true" display-tooltip-when-elided="true" name="btn-output-view" style="width: 50px;" />
</ui:VisualElement>
<Lustie.UnityDocfx.PathField />
</ui:VisualElement>
<ui:VisualElement style="flex-grow: 1; margin-top: 35px;">
<ui:Button text="Generate config files" parse-escape-sequences="true" display-tooltip-when-elided="true" name="btn-build" class="btn-cmd" />
Expand Down
8 changes: 8 additions & 0 deletions Assets/UnityDocfx/Editor/UIElements.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Assets/UnityDocfx/Editor/UIElements/HelpBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UnityEngine.UIElements;

namespace Lustie.UnityDocfx
{
public class HelpBox : UnityEngine.UIElements.HelpBox
{
public HelpBox() : base()
{

}

new class UxmlFactory : UxmlFactory<HelpBox, UxmlTraits> { }

new class UxmlTraits : UnityEngine.UIElements.HelpBox.UxmlTraits { }
}
}
11 changes: 11 additions & 0 deletions Assets/UnityDocfx/Editor/UIElements/HelpBox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions Assets/UnityDocfx/Editor/UIElements/PathField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Lustie.UnityDocfx
{
public class PathField : VisualElement, IBindable, INotifyValueChanged<string>
{
public string value
{
get => txtPath.value;
set
{
if (txtPath.value == value)
return;
using var evt = ChangeEvent<string>.GetPooled(txtPath.value, value);
evt.target = this;
SendEvent(evt);
txtPath.value = value;
}
}

public string label
{
get => txtPath.label;
set => txtPath.label = value;
}

public string buttonBrowseLabel
{
get => btnBrowse.text;
set => btnBrowse.text = value;
}

public string buttonViewLabel
{
get => btnView.text;
set => btnView.text = value;
}

public PathType pathType { get; set; }

public string extensions { get; set; }

public string FullPath
=> value.StartsWith("../") ? string.Join('\\', Directory.GetCurrentDirectory(), value.Replace("../", "")) : value;

public IBinding binding { get => txtPath.binding; set => txtPath.binding = value; }
public string bindingPath { get => txtPath.bindingPath; set => txtPath.bindingPath = value; }

#region Child Elements
private TextField txtPath;
private Button btnBrowse;
private Button btnView;
#endregion


public PathField()
{
// Container styles
this.style.flexDirection = FlexDirection.Row;

txtPath = new TextField();
txtPath.name = "txt-path";
txtPath.style.flexGrow = 1;
txtPath.style.flexShrink = 1;

btnBrowse = new Button();
btnBrowse.name = "btn-browse";
btnBrowse.style.width = new StyleLength(new Length(9.5f, LengthUnit.Percent));

btnView = new Button();
btnView.name = "btn-view";
btnView.style.width = new StyleLength(new Length(9.5f, LengthUnit.Percent));

// button events
btnBrowse.RegisterCallback<ClickEvent>(evt => { Browse(); });

btnView.RegisterCallback<ClickEvent>(evt => { ViewInPanel(); });

hierarchy.Add(txtPath);
hierarchy.Add(btnBrowse);
hierarchy.Add(btnView);
}

void Browse()
{
string outputDir = pathType == PathType.Directory ? EditorUtility.OpenFolderPanel("Browse Folder", "", "")
: EditorUtility.OpenFilePanel("Browse File", "", ".jpg");
if (!string.IsNullOrWhiteSpace(outputDir))
this.value = outputDir;
}

void ViewInPanel()
{
string folderPath = FullPath;
if (Uri.IsWellFormedUriString(folderPath, UriKind.Absolute) && (folderPath.StartsWith("http://") || folderPath.StartsWith("https://")))
{
Application.OpenURL(folderPath);
}
else if (Directory.Exists(folderPath))
{
Process.Start("explorer.exe", folderPath);
}
else
{
EditorUtility.DisplayDialog("Path doesn't exist", $"Path: {folderPath} DOES NOT EXIST", "OK");
}
}

public void SetValueWithoutNotify(string newValue)
{
txtPath.SetValueWithoutNotify(newValue);
}

public enum PathType
{
File,
Directory
}

new class UxmlFactory : UxmlFactory<PathField, UxmlTraits> { }

new class UxmlTraits : BindableElement.UxmlTraits
{
UxmlStringAttributeDescription m_labelAttr = new UxmlStringAttributeDescription { name = "Label", defaultValue = "Path" };
UxmlStringAttributeDescription m_PathAttr = new UxmlStringAttributeDescription { name = "value", defaultValue = "C:/" };
UxmlStringAttributeDescription m_BtnBrowseLabelAttr = new UxmlStringAttributeDescription { name = "button-Browse-Label", defaultValue = "Browse" };
UxmlStringAttributeDescription m_BtnViewLabelAttr = new UxmlStringAttributeDescription { name = "button-View-Label", defaultValue = "View" };
UxmlEnumAttributeDescription<PathType> m_PathTypeAttr = new UxmlEnumAttributeDescription<PathType> { name = "path-type", defaultValue = PathType.Directory };

public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
{
get { yield return new UxmlChildElementDescription(typeof(VisualElement)); }
}

public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);

PathField pathField = (PathField)ve;

pathField.label = m_labelAttr.GetValueFromBag(bag, cc);
pathField.value = m_PathAttr.GetValueFromBag(bag, cc);
pathField.buttonBrowseLabel = m_BtnBrowseLabelAttr.GetValueFromBag(bag, cc);
pathField.buttonViewLabel = m_BtnViewLabelAttr.GetValueFromBag(bag, cc);
pathField.pathType = m_PathTypeAttr.GetValueFromBag(bag, cc);
}
}
}
}
Loading

0 comments on commit f3639bd

Please sign in to comment.