DavidB
January 9, 2011, 11:07pm
1
Hello everyone,
Ran into a bit of a snag. I’m trying to code a level editor for my cube-based map package. I figured the smoothest way would be to draw a 3d grid of the desired bounds… and then allow the user to scroll through selected tiles with their arrow keys (or wasd). When you highlight a tile, you could then add a prefab’d graphical tile to the space.
I am unable to figure out how to accept keyboard input though… any advice? (Input doesn’t seem to do anything, nor does Event…)
Can you post the code you are using?
DavidB
January 10, 2011, 5:24pm
3
Hello andeeee,
I managed to get it working… apparently I was using the SetDirty incorrectly (was setting the inspector as dirty instead of the target).
This is an excerpt from the Custom Editor I wrote.
// public override void OnInspectorGUI()
// {
// DrawDefaultInspector();
// BasicGameBoard bgb = target as BasicGameBoard;
// if (Event.current.Equals(Event.KeyboardEvent("W")))
// bgb.editPosition += Vector3.forward;
// if (Event.current.Equals(Event.KeyboardEvent("S")))
// bgb.editPosition += Vector3.back;
// if (Event.current.Equals(Event.KeyboardEvent("D")))
// bgb.editPosition += Vector3.right;
// if (Event.current.Equals(Event.KeyboardEvent("A")))
// bgb.editPosition += Vector3.left;
// if (Event.current.Equals(Event.KeyboardEvent("#W")))
// bgb.editPosition += Vector3.up;
// if (Event.current.Equals(Event.KeyboardEvent("#S")))
// bgb.editPosition += Vector3.down;
// bgb.editPosition.x = Mathf.Clamp(bgb.editPosition.x, 0, bgb.MaxDimensions.x - 1.0f);
// bgb.editPosition.y = Mathf.Clamp(bgb.editPosition.y, 0, bgb.MaxDimensions.y - 1.0f);
// bgb.editPosition.z = Mathf.Clamp(bgb.editPosition.z, 0, bgb.MaxDimensions.z - 1.0f);
// Color handleColor;
// handleColor = Color.blue;
// handleColor.a = 0.25f;
// Handles.color = handleColor;
// Handles.CubeCap(0, bgb.editPosition, Quaternion.identity, 1.0f);
// EditorUtility.SetDirty(target);
// }
I was originally trying to use the Input class, but the Event class does seem to have what I want. If there’s a better way I’d love to hear it though!
Cheers