Skip to content

Commit 9782cc9

Browse files
committed
add Option 可视化功能
1 parent 1628991 commit 9782cc9

File tree

3 files changed

+97
-8
lines changed

3 files changed

+97
-8
lines changed

Demo/API_V2/Assets/API/Render/ToTempFilePath/ToTempFilePath.cs

+86-3
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,65 @@
55

66
public class ToTempFilePath : Details
77
{
8+
private void Start()
9+
{
10+
LogCurrentOptions();
11+
}
12+
813
protected override void TestAPI(string[] args)
914
{
15+
LogCurrentOptions(); // 执行API前打印当前值
1016
LoadCanvasToTempFilePath();
1117
}
1218

19+
/// <summary>
20+
/// 当下拉菜单值改变时的回调方法
21+
/// </summary>
22+
/// <param name="dropdownIndex">下拉菜单索引</param>
23+
/// <param name="optionIndex">选项索引</param>
24+
public new void OnDropdownValueChanged(int dropdownIndex, int optionIndex)
25+
{
26+
base.OnDropdownValueChanged(dropdownIndex, optionIndex);
27+
string newValue = entrySO.optionList[dropdownIndex].availableOptions[optionIndex];
28+
UpdateOption(dropdownIndex, newValue);
29+
LogCurrentOptions();
30+
}
31+
32+
33+
private float GetOptionValue(int optionIndex, float defaultValue = 0f)
34+
{
35+
if (options != null && optionIndex < options.Length)
36+
{
37+
if (float.TryParse(options[optionIndex], out float value))
38+
{
39+
return value;
40+
}
41+
}
42+
return defaultValue;
43+
}
44+
1345
private void LoadCanvasToTempFilePath()
1446
{
15-
var sys = WX.GetSystemInfoSync();
47+
var sys = WX.GetSystemInfoSync();
1648
string sysInfo = string.Format(
1749
"屏幕信息:\nscreenWidth:{0}\nscreenHeight:{1}\nwindowWidth:{2}\nwindowHeight:{3}\n",
1850
sys.screenWidth, sys.screenHeight, sys.windowWidth, sys.windowHeight
1951
);
2052

21-
53+
// 根据options数组的索引获取值
54+
float x = GetOptionValue(0);
55+
float y = GetOptionValue(1);
56+
float width = GetOptionValue(2);
57+
float height = GetOptionValue(3);
58+
59+
Debug.Log($"Using values: x={x}, y={y}, width={width}, height={height}");
60+
2261
WXCanvas.ToTempFilePath(new WXToTempFilePathParam()
2362
{
63+
x = (int)x,
64+
y = (int)y,
65+
width = (int)width,
66+
height = (int)height,
2467
success = (result) =>
2568
{
2669
WX.ShowModal(new ShowModalOption()
@@ -49,8 +92,48 @@ private void LoadCanvasToTempFilePath()
4992
},
5093
complete = (result) =>
5194
{
52-
//完成处理
95+
Debug.Log("complete");
5396
},
5497
});
5598
}
99+
100+
// 打印当前选项的值
101+
private void LogCurrentOptions()
102+
{
103+
if (options != null)
104+
{
105+
for (int i = 0; i < options.Length; i++)
106+
{
107+
Debug.Log($"Option {i}: {options[i]}");
108+
}
109+
}
110+
else
111+
{
112+
Debug.Log("Options array is null");
113+
}
114+
}
115+
116+
// 更新指定索引的选项值
117+
public void UpdateOption(int optionIndex, string value)
118+
{
119+
if (options != null && optionIndex < options.Length)
120+
{
121+
options[optionIndex] = value;
122+
}
123+
else
124+
{
125+
Debug.Log($"Cannot update option {optionIndex}: Invalid index or options not initialized");
126+
}
127+
}
128+
129+
// 更新所有选项值
130+
public void UpdateValues()
131+
{
132+
// 直接从entrySO中获取值并更新
133+
for (int i = 0; i < entrySO.optionList.Count; i++)
134+
{
135+
string value = entrySO.optionList[i].availableOptions[0];
136+
UpdateOption(i, value); // 更新对应索引选项值
137+
}
138+
}
56139
}

Demo/API_V2/Assets/API/Render/ToTempFilePath/ToTempFilePath.cs.meta

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Render/ToTempFilePath/ToTempFilePathSO.asset

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ MonoBehaviour:
1919
optionList:
2020
- optionName: x
2121
availableOptions:
22-
- "\u9ED8\u8BA4\u503C0"
22+
- 0
23+
- 500
2324
- optionName: y
2425
availableOptions:
25-
- "\u9ED8\u8BA4\u503C0"
26+
- 0
27+
- 500
2628
- optionName: width
2729
availableOptions:
28-
- "\u9ED8\u8BA4\u503Ccanvas \u7684\u5BBD\u5EA6"
30+
- 0
31+
- 400
2932
- optionName: height
3033
availableOptions:
31-
- "\u9ED8\u8BA4\u503Ccanvas \u7684\u9AD8\u5EA6"
34+
- 0
35+
- 800
3236
initialButtonText: "\u8FD0\u884C\u622A\u56FE"
3337
extraButtonList: []
3438
initialResultList: []

0 commit comments

Comments
 (0)