For those interested, the code looks a little like this:
//
OnScenGUI is how the Editor handles events in the scene window
function OnSceneGUI() {
// Handles are like Gizmos
// Draw cube at 0,0,0 when level builder is on
Handles.color = Color.red;
Handles.CubeCap(0, Vector3.zero, Quaternion.identity, 0.5);
if(editMode) {
if(Event.current.type == EventType.MouseDown) {
if(Event.current.button == 0) {
var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
var dist : float;
// Cast a ray on a "fake" plane (The Plane class in Unity is a "Representation of planes")
// If ray hits the plane (grid stand in), use the current mouse position to instantiate our prefab
if(grid.Raycast(ray, dist)) {
var pos : Vector3 = ray.origin + ray.direction.normalized * dist * 0.5;
Debug.Log("Placed fab at: " + pos);
// Using EditorUtility.InstantiatePrefab does stop me from creating clones of my prefab
// I could still use Instantiate(gameObject, pos, Quaternion.identity) here as well
var currentPiece : GameObject = EditorUtility.InstantiatePrefab(target.currentFab);
// Seems like the line below is causing some problems
currentPiece.transform.position = pos;
}//END grid Raycast
}//END Mouse Left Click
}
// Prevent deselection of object while in Edit Mode
Selection.activeGameObject = target.transform.gameObject;
}//END In Edit Mode
}//END OnSceneGUI
Failure is listed down below, I'm getting worried about how long this is all taking so any suggestions are most welcome.
Edit: I've sort of resolved the fragmenting of prefabs, it had to do with my invoking of particular functions. I will be working on the functionality of the level builder.
This one is a little old but it does show that I've resolved a strange problem with the math that determined where a collider positioned itself and when you resized buildings.
For funs:
Minecraft - Unity Style. Also has a playable demo.
No comments:
Post a Comment