一:安裝Graphviz
1.下載
百度雲盤:pan.baidu.com/s/1EfxDf50p…
2.安裝
建議預設安裝路徑
3.配置環境變數
將Graphviz的bin目錄加入path,我的是C:\Program Files (x86)\Graphviz2.38\bin。 開啟命令列視窗,執行dot -version,能顯示相關資訊表示安裝成功

4.測試
雙擊bin目錄下的gvedit.exe
新建一個檔案File-New

digraph startgame {
edge [fontname="FangSong"] node [shape=box, fontname="FangSong" size="20,20"]
label="遊戲資源更新流程" fontname="FangSong"
rankdir="TB"
start[label="啟動遊戲" shape=circle style=filled]
ifwifi[label="網路環境判斷是否 WIFI" shape=diamond]
needupdate[label="是否有資源需要更新" shape=diamond]
startslientdl[label="靜默下載" shape=box]
enterhall[label="進入遊戲大廳" shape=box]
enterroom[label="進入房間" shape=box]
resourceuptodate[label="資源不完整" shape=diamond]
startplay[label="正常遊戲" shape=circle fillcolor=blue]
warning[label="提醒玩家是否更新" shape=diamond]
startdl[label="進入下載介面" shape=box]
//{rank=same; needupdate, enterhall}
{shape=diamond; ifwifi, needupdate}
start -> ifwifi
ifwifi->needupdate[label="是"]
ifwifi->enterhall[label="否"]
needupdate->startslientdl[label="是"]
startslientdl->enterhall
needupdate->enterhall[label="否"]
enterhall -> enterroom
enterroom -> resourceuptodate
resourceuptodate -> warning[label="是"]
resourceuptodate -> startplay[label="否"]
warning -> startdl[label="確認下載"]
warning -> enterhall[label="取消下載"]
startdl -> enterhall[label="取消下載"]
startdl -> startplay[label="下載完成"]
}
複製程式碼
點選layout


5.備註
Graphviz出現中文亂碼:參考示例中加上 edge [fontname="FangSong"] node [shape=box, fontname="FangSong" size="20,20"];標籤label="中文"如果亂碼,後面加上fontname="FangSong"
二:Android Studio 安裝 PlantUML外掛
1.安裝
線上安裝,直接搜尋PlantUML然後安裝即可


外掛安裝完成後,配置Graphviz路徑。

2.測試
在Android Studio選擇一個目錄,右鍵新建,選擇UML Class,名稱為Test,便會生成一個Test.puml檔案

Test.puml裡面會自動生成一份示例程式碼,右側會自動轉化成UML圖,如下所示

參考: