Example #1
0
    static void OnSceneDraw(SceneView sceneView)
    {
        if (Event.current.isKey)
        {
            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.A)
                {
                    SceneEditorSettings.isOpenFllowMouse = !SceneEditorSettings.isOpenFllowMouse;
                }
            }
        }
        if (Event.current.isMouse)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                /*拖拽鼠标具备选中功能*/
                if (Tools.current == Tool.View)
                {
                    Vector3 mousePosition = Event.current.mousePosition;
                    float   height        = SceneView.currentDrawingSceneView.position.height;
                    mousePosition.y = height - mousePosition.y - 15f;
                    Ray        ray = sceneView.camera.ScreenPointToRay(mousePosition);
                    RaycastHit hit;
                    Physics.Raycast(ray, out hit);
                    if (hit.transform != null && hit.transform.name != "Grid")
                    {
                        GameObject OldSelection = Selection.activeObject as GameObject;
                        if (OldSelection != hit.transform.gameObject)
                        {
                            UISceneElementBase _old = null;
                            if (OldSelection != null)
                            {
                                _old = OldSelection.GetComponent <UISceneElementBase>();
                            }
                            if (_old != null)
                            {
                                _old.OnLostFocus();
                            }
                            UISceneElementBase _new = hit.transform.gameObject.GetComponent <UISceneElementBase>();
                            if (_new != null)
                            {
                                _new.OnFocus();
                            }
                            Selection.activeObject = hit.transform.gameObject;
                        }
                    }
                }
            }
        }

        //开始绘制GUI
        Handles.BeginGUI();

        GUILayout.BeginArea(new Rect(0, sceneView.position.height - 70, 200, 200));
        string currMapName = "";

        if (SceneEditorSettings.currMap != null)
        {
            currMapName = SceneEditorSettings.currMap.name;
        }

        /*正在编辑*/
        GUILayout.Label(EditorStringConfig.getString(10030) + ": " + currMapName);

        #region  标跟随
        /*是否打开了鼠标跟随功能*/
        bool isOpenFllowMouseOld = SceneEditorSettings.isOpenFllowMouse;
        SceneEditorSettings.isOpenFllowMouse = GUILayout.Toggle(SceneEditorSettings.isOpenFllowMouse, EditorStringConfig.getString(10032) + "(" + EditorStringConfig.getString(10045) + ":A)");
        /*从拖拽状态切出*/
        if (isOpenFllowMouseOld != SceneEditorSettings.isOpenFllowMouse && isOpenFllowMouseOld)
        {
            Tools.current = Tool.Move;
        }
        /*强制鼠标拖拽*/
        if (SceneEditorSettings.isOpenFllowMouse)
        {
            Tools.current = Tool.View;
        }
        #endregion

        if (SceneEditorSettings.currMap != null)
        {
            UISceneMap map = SceneEditorSettings.currMap.GetComponent <UISceneMap>();
            if (map != null)
            {
                if (map.EditorCamera != null)
                {
                    //bool isOldOpen = isOpenSceneCamera;
                    /*打开场景摄像机*/
                    isOpenSceneCamera        = GUILayout.Toggle(isOpenSceneCamera, EditorStringConfig.getString(10029));
                    map.EditorCamera.enabled = isOpenSceneCamera;
                    //map.EditorCamera.hideFlags = HideFlags.NotEditable;
                    if (map.EditorCamera.isOrthoGraphic)
                    {
                        map.EditorCamera.isOrthoGraphic = false;
                    }
                    map.EditorCamera.transform.rotation = sceneView.camera.transform.rotation;
                    map.EditorCamera.transform.position = sceneView.camera.transform.position;
                }
            }
        }


        GUILayout.EndArea();
        Handles.EndGUI();
    }