- Home /
turn off selection in the Scene View
I am making an editor to add, move and size particles as well as change particle color. So far I manage to detect particles close to the mouse position (although I have problem because Camera.current doesn't have the right aspect ratio)
when I click on a particle, I get the closest particle to the ray, simulating a raycast
the problem is I do that and it selects the particle systems and thus exits the Editor script. it's strange because I have a [CustomEditor(typeof(GameObject))] at the head of that editor class so it should keep that script running but it doesn't
anyone has an idea about that ?
using UnityEditor; using UnityEngine; using System.Collections; using System.Collections.Generic;
[CustomEditor(typeof(GameObject))]
public class FurEditor : Editor { bool edit;
void OnSceneGUI ()
{
if (Selection.activeGameObject.GetComponent<Fur>())
{
Handles.BeginGUI ();
var tmpColor = GUI.color;
if (edit)
GUI.color = Color.red;
if (GUILayout.Button ("Edit", GUILayout.Width (70)))
edit = !edit;
GUI.color = tmpColor;
Handles.EndGUI ();
if (edit) {
EditBalls (Selection.activeGameObject.GetComponent<Fur>());
}
if (GUI.changed || edit && Event.current.type == EventType.MouseMove)
EditorUtility.SetDirty (target);
}
}
Transform selection;
void EditBalls (Fur target)
{
Vector3 mousePosition = new Vector3 (Event.current.mousePosition.x, Event.current.mousePosition.y, 0);
Ray ray = Camera.current.ScreenPointToRay (new Vector2( mousePosition.x, Screen.height - mousePosition.y));
Handles.DrawLine(ray.origin, ray.origin + 10*ray.direction);
// if (Event.current.button == 0) // { List<Transform> ballsClicked = new List<Transform> (); foreach (Transform b in target.balls) { if (Helpers.DistanceToLine (ray, b.position) <= b.lossyScale.x * .1f) ballsClicked.Add (b); }
if (ballsClicked.Count > 0) {
float depth = Mathf.Infinity;
foreach (Transform b in ballsClicked) {
Handles.DrawSolidDisc(b.position, Camera.current.transform.forward, .1f);
if (Camera.current.transform.InverseTransformPoint (b.position).z < depth) {
depth = Camera.current.transform.TransformPoint (b.position).z;
selection = b;
}
}
} else
selection = null;
// }
if (selection) {
Handles.BeginGUI ();
GUILayout.Label (selection.position.ToString ());
GUILayout.Label (ballsClicked.Count.ToString ());
Handles.RadiusHandle (Quaternion.identity, selection.transform.position, selection.lossyScale.x);
Handles.EndGUI ();
}
}
}
I am also looking to disable mouse selection in the editor view. I try to do raycasting to place objects onto a grid, but selection often messes things up. Let me know if you figure it out Joshua.