Beispiel #1
0
    private static void DrawHierarchyIcon(int instanceID, Rect selectionRect)
    {
        GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

        if (gameObject != null)
        {
            UISceneElementBase baseElement = gameObject.GetComponent <UISceneElementBase>();
            if (gameObject != null && baseElement != null && gameObject.name != "UIRectGrid")
            {
                Rect rect = new Rect(selectionRect.x + selectionRect.width - 16f, selectionRect.y, 16f, 16f);
                switch (baseElement.settingData.Type)
                {
                case  SceneElementType.MAP:
                    GUI.DrawTexture(rect, GUIUISceneMapCallBack.MIcon);
                    break;

                case SceneElementType.NPC:
                    GUI.DrawTexture(rect, GUIUISceneMapCallBack.NIcon);
                    break;

                default:
                    GUI.DrawTexture(rect, GUIUISceneMapCallBack.CIcon);
                    break;
                }
            }
        }
    }
Beispiel #2
0
    public void OnSceneGUI()
    {
        UISceneElementBase baseTarget = (UISceneElementBase)target;

        if (baseTarget == null || !baseTarget.enabled)
        {
            return;
        }


        baseTarget.UpdateData();

        SceneCamera = SceneView.currentDrawingSceneView.camera;
        //Vector3 CameraPos = SceneCamera.transform.position;

        if (Event.current.isMouse)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                OnPressAtDrawScene(true);
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                OnPressAtDrawScene(false);
            }
        }
        if (Event.current.isKey)
        {
            if (Event.current.type == EventType.KeyDown)
            {
                OnKeyBoardDown(Event.current.keyCode);
            }
        }

        Handles.BeginGUI();
        GUILayout.BeginArea(new Rect(0, 0, 300, 100));
        //场景摄像机参考
        GUILayout.Label("SceneCamera " + EditorStringConfig.getString(10037) + ":" + SceneCamera.transform.position.ToString());
        GUILayout.Label("SceneCamera " + EditorStringConfig.getString(10038) + ":" + SceneCamera.transform.rotation.eulerAngles.ToString());
        GUILayout.EndArea();
        Handles.EndGUI();
    }
Beispiel #3
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();
    }