You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the biggest quality-of-life issues using Nova is the lack of being able to right-click and make a default button or any basic UIControl for that matter. So I made a little editor script that does that for me.
I decided to make use of Prefabs with Resources.Load as with Nova I make a decent amount of custom scripts, plus it makes it easy to set up themed UIControls per project. Although my initial reason was that you can't change the Visuals of an ItemView through code to my knowledge lol
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// A quick way of adding custom objects to the GameObject context menu
/// </summary>
static class CreateObjects
{
[MenuItem("GameObject/Nova/MyUIControl")]
static void CreateUIControl(MenuCommand menuCommand)
{
PlaceElementRoot(InstanciatePrefab("MyUIControl"), menuCommand);
}
/// <summary>
/// Return instantiated Prefab from the Resources folder.
/// </summary>
/// <param name="name"> Name of Prefab to instanciate</param>
private static GameObject InstanciatePrefab(string name)
{
GameObject prefab = Object.Instantiate(Resources.Load<GameObject>(name));
prefab.name = name;
return prefab;
}
/// <summary>
/// Set the parent of the element to the currently selected object.
/// </summary>
/// <param name="element">The object to reparent</param>
/// <param name="menuCommand"> used to get the object that is selected</param>
private static void PlaceElementRoot(GameObject element, MenuCommand menuCommand)
{
GameObject parent = menuCommand.context as GameObject;
if(parent != null)
{
// Setting the element to be a child of an element already in the scene should
// be sufficient to also move the element to that scene.
// However, it seems the element needs to be already in its destination scene when the
// RegisterCreatedObjectUndo is performed; otherwise the scene it was created in is dirtied.
SceneManager.MoveGameObjectToScene(element, parent.scene);
if (element.transform.parent == null)
{
Undo.SetTransformParent(element.transform, parent.transform, "Parent " + element.name);
}
}
GameObjectUtility.EnsureUniqueNameForSibling(element);
// We have to fix up the undo name since the name of the object was only known after reparenting it.
Undo.SetCurrentGroupName("Create " + element.name);
GameObjectUtility.SetParentAndAlign(element, parent);
Undo.RegisterCreatedObjectUndo(element, "Create " + element.name);
Selection.activeGameObject = element;
}
}
@ZanKievit
Português:
Será que com essa funcionalidade consigo construir algo semelhante a este vídeo anexado?
Por exemplo, eu tenho uma lista de amigos e quando eu clicar com botão direito quero que apareça um novo contexto (modal) com mais opções (remover, convidar, enviar mensagem, bloquear e etc...)
Minha maior preocupação dessa implementação é ao instanciar esse objeto de jogo em certa posição ele pode "sair" da tela e exibir parcialmente. Eu trouxe uma print do Windows 11 de caso quando clicar bem nos cantos da tela ele consegue se ajustar para dentro.
Minha lista é bem semelhante ao usado no exemplo da cena "UIPlayground"
Inglês (English) google tradutor(google translate):
Could it be that with this functionality I can build something similar to this attached video?
For example, I have a list of friends and when I right-click I want a new context (modal) to appear with more options (remove, invite, send message, block, etc...)
My biggest concern with this implementation is when instantiating this game object in a certain position it can "leave" the screen and partially display. I brought a screenshot of Windows 11 in case when you click right on the corners of the screen it manages to adjust inwards.
My list is very similar to the one used in the "UIPlayground" scene example
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
One of the biggest quality-of-life issues using Nova is the lack of being able to right-click and make a default button or any basic UIControl for that matter. So I made a little editor script that does that for me.
I decided to make use of Prefabs with
Resources.Loadas with Nova I make a decent amount of custom scripts, plus it makes it easy to set up themed UIControls per project. Although my initial reason was that you can't change theVisualsof anItemViewthrough code to my knowledge lolAll reactions