Skip to content

[update] dynamic canvas sorting order#102

Closed
Bian-Sh wants to merge 2 commits intoyasirkula:masterfrom
Bian-Sh:master
Closed

[update] dynamic canvas sorting order#102
Bian-Sh wants to merge 2 commits intoyasirkula:masterfrom
Bian-Sh:master

Conversation

@Bian-Sh
Copy link
Copy Markdown

@Bian-Sh Bian-Sh commented Jan 13, 2025

No description provided.

@yasirkula
Copy link
Copy Markdown
Owner

I'm actually happy about the current implementation. User may initially have a canvas with Sorting Order 0. This script sets FileBrowser's Sorting Order to 1. Then if user instantiates another canvas with Sorting Order 2, it will be rendered above the FileBrowser. But if FileBrowser's Sorting Order remains as 2020, this issue won't occur. In the case that the fixed Sorting Order doesn't suffice, it's possible to either edit the prefab or put the FileBrowser prefab in the scene and modify it from there (but that instance must be deactivated manually in Start).

@Bian-Sh
Copy link
Copy Markdown
Author

Bian-Sh commented Jan 13, 2025

OK, I get you~ I will give you another PR.

@Bian-Sh
Copy link
Copy Markdown
Author

Bian-Sh commented Jan 13, 2025

你担心的下一个面板会拦住 SFB,因此设置了固定值 2016,但是我认为固定的还是不太好:

因为你不能保证用户不会用到大于 2016 的 renderOrder,因此:

  1. 如果用户面板的 RenderOrder = 2017 ,那么 SFB 就显示在此面板之下,但动态RenderOrder 能够解决这个问题。
  2. 你提到下一个面板会覆盖的困惑,但如果用户下一个面板 renderoder =2017 ,SFB 同样会被覆盖在新的面板下。
  3. 所以,为了下一个面板大几率能够正常展示,让我们取个折中措施:把 +1 变成 +2016

以下为 gpt 翻译/ translate by gpt below:

You are concerned that the next panel will block SFB, so you set a fixed value of 2016, but I think it is still not ideal:

Because you cannot guarantee that users will not use a renderOrder greater than 2016, so:

  1. If the user's panel has a RenderOrder = 2017, then SFB will be displayed below this panel, but dynamic RenderOrder can solve this problem.
  2. You mentioned confusion about the next panel covering, what if the user's next panel render order = 2017, SFB will also be covered under the new panel.
  3. Therefore, in order for the next panel to have a higher chance of displaying correctly, let's compromise: change +1 to +2016

@yasirkula
Copy link
Copy Markdown
Owner

As you said though, it unfortunately can't be guaranteed. It always depends on the user's project. User's next canvas might have 3000 Sorting Order. Or user's current canvas might have 100 Sorting Order but they may want it to be displayed above everything, including SFB. With the current solution, SFB would have 100+2016=2116 Sorting Order and be rendered above that canvas. User then would have to set their canvas' sorting order to something greater than 2116 by code. I think that's actually more problematic than the current problem.

@Bian-Sh
Copy link
Copy Markdown
Author

Bian-Sh commented Jan 14, 2025

是的,用户的需求千奇百怪,直接手动设置作为对于这款受众众多的插件来说算得上是一个最佳解~
Yes, the user's needs are varied, and set orders manually are considered the best solution for this widely used plugin.

@Bian-Sh Bian-Sh closed this Jan 14, 2025
@Bian-Sh
Copy link
Copy Markdown
Author

Bian-Sh commented Jan 16, 2025

那希望你可以在参数中加一个 renderOrder的可选参数,默认值就是你设定的2016,这样方便用户使用

@yasirkula
Copy link
Copy Markdown
Owner

How about this code:

(typeof(FileBrowser).GetProperty("Instance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(null, null) as FileBrowser).GetComponent<Canvas>().sortingOrder = 10000;

@Bian-Sh
Copy link
Copy Markdown
Author

Bian-Sh commented Jan 17, 2025

How about this code:

(typeof(FileBrowser).GetProperty("Instance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(null, null) as FileBrowser).GetComponent<Canvas>().sortingOrder = 10000;

是的,我也是意识到了 Instance 是私有的,然后,还得查找 Canvas ,而这一切通过你的 Show 函数就可以轻易传递进去,然后,使用 Option 参数的好处是,用户的任何调用代码没有丝毫变化。

当然,如果 rendererorder 赋值动作是一个非常罕见的操作,那么,可以不考虑加入上面的改善。

@yasirkula
Copy link
Copy Markdown
Owner

Yeah I believe it's a very rare operation. So my cleanest solution right now is the GetComponent one. It should never break because I always name my singletons Instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants