I am trying to access certain ui elements like the crosshair, the vital bars and the compass with the use of a script to incorporate into a dfmod. I am fairly inexperienced with the Daggerfall tools for Unity and am having a hard time figuring out a way. Any help would be appreciated. I am currently using DaggerfallWorkshop.Game; DaggerfallWorkshop.Game.UserInterface; DaggerfallWorkshop.Game.UserInterfaceWindows; and DaggerfallWorkshop.Game.Utility.ModSupport;
I am trying to toggle the HUD (at the very least the crosshair) on and off with the use of a button press. My first approach would be to use an if statement with input.geykeydown("button"). This part is all well and good but i simply do not know how to use this to toggle the HUD since it is not a part of the canvas in the editor.
Accessing UI elements with scripts?
-
- Posts: 3
- Joined: Wed Jun 12, 2019 12:35 pm
Accessing UI elements with scripts?
Last edited by FatalityGrogen on Sat Mar 28, 2020 1:57 pm, edited 1 time in total.
- BadLuckBurt
- Posts: 948
- Joined: Sun Nov 05, 2017 8:30 pm
Re: Accessing UI elements with scripts?
Not my area of expertise but if you have a repository available so we can look at the code, someone might be able to point you in the right direction.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt
.
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt
.
- pango
- Posts: 3359
- Joined: Wed Jul 18, 2018 6:14 pm
- Location: France
- Contact:
Re: Accessing UI elements with scripts?
Welcome to the forums FatalityGrogen,
I'm not sure what you mean by "accessing" UI elements and what you're trying to do so I could be wrong, but I suspect this could be a misguided attempt, if anything because UI can be modded (and hopefully will get even easier to mod with time), so depending on specific UI elements could be bad. Another reason is that UI should just be visualization of internal data, and not the right place to take information from or inject values in.
So my first question is, could you explain what you're trying to do?
I'm not sure what you mean by "accessing" UI elements and what you're trying to do so I could be wrong, but I suspect this could be a misguided attempt, if anything because UI can be modded (and hopefully will get even easier to mod with time), so depending on specific UI elements could be bad. Another reason is that UI should just be visualization of internal data, and not the right place to take information from or inject values in.
So my first question is, could you explain what you're trying to do?
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart
-
- Posts: 3
- Joined: Wed Jun 12, 2019 12:35 pm
Re: Accessing UI elements with scripts?
I am trying to toggle the HUD (at the very least the crosshair) on and off with the use of a button press. My first approach would be to use an if statement with input.geykeydown("button"). This part is all well and good but i simply do not know how to use this to toggle the HUD since it is not a part of the canvas in the editor.
- Hazelnut
- Posts: 3016
- Joined: Sat Aug 26, 2017 2:46 pm
- Contact:
Re: Accessing UI elements with scripts?
Pretty sure you can do something like this to switch off (or on if you set to true) the crosshair:
Just a quick example to get you started, hopefully it works
there are a bunch of properties you can use to show/hide the various HUD elements or find out whether they're on or off. Just take a look at the DaggerfallHUD class.
Code: Select all
DaggerfallUI.Instance.DaggerfallHUD.ShowCrosshair = false;
there are a bunch of properties you can use to show/hide the various HUD elements or find out whether they're on or off. Just take a look at the DaggerfallHUD class.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods
-
- Posts: 3
- Joined: Wed Jun 12, 2019 12:35 pm
Re: Accessing UI elements with scripts?
Well, thank you very much! You can not believe what i have tried to achieve this ahahaha. Long story short, as a last resort i tried disabling the DaggerfallUI script. Let me try this and get back to you.
- Hazelnut
- Posts: 3016
- Joined: Sat Aug 26, 2017 2:46 pm
- Contact:
Re: Accessing UI elements with scripts?
No problem, as soon as you described what you were trying to do I could help. Always remember people reading your question don't know the context... that's all in your head.FatalityGrogen wrote: ↑Sat Mar 28, 2020 2:02 pm Well, thank you very much! You can not believe what i have tried to achieve this ahahaha. Long story short, as a last resort i tried disabling the DaggerfallUI script. Let me try this and get back to you.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods