Drawing custom Editor controls in Unity - c#

Sometimes a Unity project has data that demands more than ordinary inspector fields and we want to create more sophisticated tools to edit the data. For example, here's a blog post about creating a node editor: Creating a Node Based Editor in Unity
It's useful to be able to create node editors, but that project draws nothing but boxes and lines and curves using the tools in GUI and Handles, which is fine for what it is, but what if we need to draw something not supplied by Handles?
For example, if we want to draw an elaborate mesh to represent some data that we want to be able to edit, it seems not ideal to render each individual polygon of the mesh using Handles.DrawAAConvexPolygon(...). Shouldn't we instead have a way to more directly send the mesh to be rendered? Or is DrawAAConvexPolygon exactly what we should be doing?
Is the GL class the appropriate approach when wanting to draw arbitrary meshes in an editor control? It is certainly capable of drawing, but is it bad practice? In particular, the GL.Viewport(Rect) method seems to work very strangely within a GUI. One cannot simply give it a GUI Rect and thereby have a viewport in the same place we'd have a GUI control if we gave it that same Rect. We need to calculate the Rect that will put the viewport in the appropriate place, and even then we have to determine the coordinate system within the viewport. Based on the documentation for Viewport(Rect) one might expect the viewport to be (0, 0) to (Screen.width, Screen.height), but it does not always work out that way exactly, and it all gives the impression that GL is not designed to be used within Editor GUI. The documentation for GL.Viewport has it used in an OnPostRender method, so is it misguided to try to use GL in other places?
If we should not be using the GL class, then what is the technique for drawing within custom Editor controls?

You may wanna look at Unity Graph view if you want to make a Node Based Editor in Unity.
It use UXML and USS with is close to HTML and CSS.
Making it pretty easy to customise as you wanted.
Unity Video on UXML and USS: Customize the Unity Editor with UIElements!
https://www.youtube.com/watch?v=CZ39btQ0XlE&t=98s
Here are 3 Github you can download and look at.
https://github.com/rygo6/GTLogicGraph
https://github.com/rygo6/GraphViewExample
This one is made by me.
https://github.com/KasperGameDev/Dialogue-Editor-Tutorial/tree/Dialogue-Prototype-Bonus

Related

Unity - chat not on top of everything

So, I've been searching ALOT for this and I feel like I've tried pretty much everything, and still I'm coming up short.
The basic idea is to have a chat and also be able to have things in front of that chat window (lets say a draggable menu of sorts).
As a first thing I setup my chat as a GUI element. It works perfect.. word-wrapping and all, but it's always on top of everything else, so this doesn't really work for what I want to do.
The chat box is also scaling depending on your screen resolution.
I think the main issue is going to get it nicely word wrapped when NOT using GUI and I'm just all out of ideas.
Also wanted to state that the "menu" that's going over the chat is going to be containing gameobjects so it's not going to be another GUI element.
Can this even be done?
use GUI.depth=10 before drawing your chat window, and GUI.depth=5 after everything should appaer on top now.
From the documentation:
Set this to determine ordering when you have different scripts running simultaneously. GUI elements drawn with lower depth values will appear on top of elements with higher values (ie, you can think of the depth as "distance" from the camera).
if you dont want to do this.. determine order of drawing. Whatever gets drawn last is on top.
I understand at this stage it may be hard to do this, but its best to have one OnGUI active in your whole game/app. Having more than one deteriorates performance.
edit: to include scene renders on top of the GUI, you render your scene to a seperate camera (without gui) and have this camera render to texture. this texture can then be used in your gui by using for instance GUI.DrawTexture.

Can I implement clipping using SFML 2.1 2d drawing API?

I am implementing a simplistic GUI library for a game.
My solution uses SFML 2.1 2d API.
As you can imagine, the ui elements are organized in a hierarchical structure. Children are expected to render within the bounds of their parents.
I could live with the need to trust children to render outside their parent. However, to implement scrolling in a simple manner, I'd like to clip whatever children render.
Is there a way to achieve this using the SFML 2d api ?
For now, I could only come up with drawing to a texture and use that texture for a shape or sprite. I am concerned with performance (even though, the texture would only be regenerated when UI content changes).
Unfortunately this features isn't yet implemented, but you're not the only one waiting for it, see the first issue ever created on SFML's GitHub issue tracker.
In the meantime the only way is to either use OpenGL directly or via a sf::RenderTexture.

Create an Object Editor in C# for WinForms

I need to find, or create an editor that will handle text and images as objects. For instance I have a 3 line string of text, to be able to move it around and position it within a canvas, also the ability to add an image, and possibly resize it within that canvas. and take the result, and save it, whether I get the the offsets and positions manually, of each of the objects (preferable) , or get the entire canvas as an image, to be able to save and print.
Rulers would be great... Im not trying to re-create Photoshop, but the idea is similar.
I will be doing this in a C# WinForms application, it does seem however that a WPF solution might be better suited, and I think I can have a WPF control within winforms...
Any direction or advice would be greatly appreciated.
Forget winforms. It doesn't support anything. Your best bet is to do it in WPF and if you need, you can integrate it into an existing winforms application via the ElementHost.
Please see my similar answers/samples about this:
https://stackoverflow.com/a/15580293/643085
https://stackoverflow.com/a/15469477/643085
https://stackoverflow.com/a/15821573/643085
Also, see this example with support for zoom, panning and resizing functionality:
https://stackoverflow.com/a/16947081/643085
They're all MVVM based and have some interesting features.
You can easily customize these samples and add ANY type of elements:
images,
geometries,
usable interactive UI elements with functionality (TextBoxes, ComboBoxes, whatever),
text,
videos,
FlowDocuments,
or whatever that's visible on screen)
by adding additional data items and their corresponding DataTemplates.

Map format for a 3D game

I'm learning 3D programming and I decided to make a really simple "engine" where you can just fly around the map, etc. Only basic rendering of walls.
So, I was thinking - how can I save the level and how can I edit it. I don't want to make also an editor for it, because it is only a learning project, and not an actual game. So, I was looking towards this level format: UDMF http://zdoom.org/wiki/Universal_Doom_Map_Format although it is for a completely different type of game, still, it does what I need. Specifies vertices, floor, ceiling positions, etc. So, basic 2.5D geometry, which could be easily interpreted into a 3D space, which is more than enough for my purposes. There are also tons of editors (main reason).
BUT, I do realise that this is not really the best solution, and kind of workaround.
So, my question: Is there any "open" map format and "open" editors that I can use for my engine/game?
UPD: I'm working with C# and XNA, if that is important.
You could use XML (or something even simpler) that provides the location and other attributes of all the objects in the level. This would be the easiest solution (and have the benefit of containing whatever info you want but nothing else) but would not provide a level editor.
However, I know you want an editor (who wouldn't). Here is a very new, work-in-progress editor that looks interesting: 3D Scene Editor for XNA

How to create an interactive Map using Images

I have a couple of images that I would like to create an interactive map of in Silverlight and WPF. The pictures are of States and counties. I tried doing some search on how this is done but have not been able to find a good example on how to go about accomplishing this. So I would appreciate your help. Thanks in advance.
I was involved in creating a Xaml World map from scratch (below) and that alone took nearly a day for a stylised polygon version (no fine detail)....
I have since purchased a Wacom Bamboo tablet & stylus and found that to be about 5 times faster to work with compared with a mouse.
Quoting myself: "You import a map as a background image and use the pen tool to dot-to-dot trace around the country. Combine all those path segments into a single path. Then create a separate poly-path for each state (close them to allow for a fill)."
Once you create them you can name the individual country polygons and connect up mouse logic to make them all glow on mouse over or change colour on press etc.
Basically all the other stuff on that screen are user controls and custom controls. Work out the behaviour you want and create controls to suit your own needs.
In your instance you can use less accurate polygons as they will only be for hit-testing and highlighting and you will want to retain the actual map images under the polygons.

Categories