// -------------------------------------------------------------------------- public void OnEnable() { m_fenceLayout = target as FenceLayout; m_terrains = FindObjectsOfType <Terrain>(); SceneView.duringSceneGui += InputUpdate; }
// -------------------------------------------------------------------------- public void OnEnable() { m_fenceLayout = target as FenceLayout; m_terrains = FindObjectsOfType <Terrain>(); SceneView.onSceneGUIDelegate += InputUpdate; }
// -------------------------------------------------------------------------- public void OnEnable() { m_fenceLayout = target as FenceLayout; m_terrains = FindObjectsOfType <Terrain>(); #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui += InputUpdate; #else SceneView.onSceneGUIDelegate += InputUpdate; #endif }
// -------------------------------------------------------------------------- void InputUpdate(SceneView sceneview) { Event e = Event.current; int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); if (e.control) { HandleUtility.AddDefaultControl(controlID); } if (e.type != EventType.Repaint && e.type != EventType.Layout) { GameObject fenceObj = Selection.activeObject as GameObject; if (fenceObj) { FenceLayout fence = fenceObj.GetComponent <FenceLayout>(); if (fence) { m_editMode = FenceLayout.EditMode.None; fence.SetEditMode(FenceLayout.EditMode.None, new Vector3()); if (e.control) { Ray r = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight)); RaycastHit result; if (Physics.Raycast(r, out result)) { m_editMode = (e.control && e.shift) ? FenceLayout.EditMode.Delete : (e.control ? FenceLayout.EditMode.Add : FenceLayout.EditMode.None); m_mousePos = result.point; fence.SetEditMode(m_editMode, result.point); if (e.control && e.button == 0) { if (e.type == EventType.MouseDown) { ApplyEdit(); EditorUtility.SetDirty(fence); } } } } } } } }