GetComponentByPathDeprecated: use GetByXPath instead.
Automatically assign a component to a field by a given path.
-
(Optional)
EGetComp configOptions are:
EGetComp.ForceResign: when the target changed (e.g. you delete/create one), automatically resign the new correct component.EGetComp.NoResignButton: do not display a re-sign button when the target mismatches.
-
string paths...Paths to search.
-
AllowMultiple: Yes. But not necessary.
The path is a bit like html's XPath but with less function:
| Path | Meaning |
|---|---|
/ | Separator. Using at start means the root of the current scene. |
// | Separator. Any descendant children |
. | Node. Current node |
.. | Node. Parent node |
* | All nodes |
| name | Node. Any nodes with this name |
[last()] | Index Filter. Last of results |
[index() > 1] | Index Filter. Node index that is greater than 1 |
[0] | Index Filter. First node in the results |
For example:
./sthorsth: direct child object of current object namedsth.//sth: any descendant child under current. (descendant::sth)..//sth: first go to parent, then find the direct child namedsth/sth: top level node in current scene namedsth//sth: first go to top level, then find the direct child namedsth///sth: first go to top level, then find any node namedsth./get/sth[1]: the child namedgetof current node, then the second node namedsthin the direct children list ofget
using SaintsField; // starting from root, search any object with name "Dummy" [GetComponentByPath("///Dummy")] public GameObject dummy; // first child of current object [GetComponentByPath("./*[1]")] public GameObject direct1; // child of current object which has index greater than 1 [GetComponentByPath("./*[index() > 1]")] public GameObject directPosTg1; // last child of current object [GetComponentByPath("./*[last()]")] public GameObject directLast; // re-sign the target if mis-match [GetComponentByPath(EGetComp.NoResignButton | EGetComp.ForceResign, "./DirectSub")] public GameObject directSubWatched; // without "ForceResign", it'll display a reload button if mis-match // with multiple paths, it'll search from left to right [GetComponentByPath("/no", "./DirectSub1")] public GameObject directSubMulti; // if no match, it'll show an error message [GetComponentByPath("/no", "///sth/else/../what/.//ever[last()]/goes/here")] public GameObject notExists;
