Skip to content

Commit

Permalink
add function : open layouts with folder path
Browse files Browse the repository at this point in the history
liuhaopen committed Jul 26, 2018
1 parent 6c49416 commit 42b00c9
Showing 3 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions Assets/UIEditor/Common/ContextMenu.cs
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ static public void AddCommonItems(GameObject[] targets)
{
AddItem("新建", false, UIEditorHelper.CreatNewLayoutForMenu);
AddItem("打开界面", false, UIEditorHelper.LoadLayout);
AddItem("打开文件夹", false, UIEditorHelper.LoadLayoutWithFolder);
}
if (targets != null && targets.Length > 0)
{
13 changes: 12 additions & 1 deletion Assets/UIEditor/Common/UIEditorHelper.cs
Original file line number Diff line number Diff line change
@@ -192,7 +192,18 @@ public static void ClearAllCanvas()
[MenuItem("UIEditor/加载文件夹", false, 1)]
public static void LoadLayoutWithFolder()
{

string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
string select_path = EditorUtility.OpenFolderPanel("Open Layout", default_path, "");
PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, select_path);
if (select_path.Length > 0)
{
string[] file_paths = Directory.GetFiles(select_path, "*.prefab");
foreach (var path in file_paths)
{
LoadLayoutByPath(path);
}
}
UILayoutTool.ResortAllLayout();
}

private static GameObject GetLoadedLayout(string layoutPath)
22 changes: 11 additions & 11 deletions Assets/UIEditor/Common/UILayoutTool.cs
Original file line number Diff line number Diff line change
@@ -16,19 +16,19 @@ public static void ResortAllLayout()
if (testUI != null)
{
Canvas[] layouts = testUI.GetComponentsInChildren<Canvas>();
if (layouts[0] != null)
if (layouts.Length > 0)
{
SceneView.lastActiveSceneView.MoveToView(layouts[0].transform);
}
Vector2 startPos = new Vector2(layouts[0].transform.position.x - 1280 * 1, layouts[0].transform.position.y + 720 * 1);
int index = 0;
foreach (var item in layouts)
{
int row = index / 5;
int col = index % 5;
Vector2 pos = new Vector2(1280 * col + startPos.x, -720 * row + startPos.y);
item.transform.position = pos;
index++;
Vector2 startPos = new Vector2(layouts[0].transform.position.x - 1280 * 1, layouts[0].transform.position.y + 720 * 1);
int index = 0;
foreach (var item in layouts)
{
int row = index / 5;
int col = index % 5;
Vector2 pos = new Vector2(1280 * col + startPos.x, -720 * row + startPos.y);
item.transform.position = pos;
index++;
}
}
}
}

0 comments on commit 42b00c9

Please sign in to comment.