Exemplo n.º 1
0
    private void OnSceneGUI()
    {
        Launcher  launcher  = target as Launcher;
        Transform transform = launcher.gunBody.transform;

        // Debug draw the offset handle and its state
        using (var cc = new EditorGUI.ChangeCheckScope())
        {
            Vector3 newOffset = transform.InverseTransformPoint(
                Handles.PositionHandle(transform.TransformPoint(launcher.offset), transform.rotation));

            if (cc.changed)
            {
                Undo.RecordObject(launcher, "Offset Change");
                launcher.offset = newOffset;
            }
        }

        // Buttons to access the methods needed from the launcher script
        Handles.BeginGUI();
        {
            Vector3 rectMin = Camera.current.WorldToScreenPoint(launcher.transform.position + launcher.offset);
            Rect    rect    = new Rect();
            rect.xMin   = rectMin.x;
            rect.yMin   = SceneView.currentDrawingSceneView.position.height - rectMin.y;
            rect.width  = 64;
            rect.height = 18;

            GUILayout.BeginArea(rect);
            {
                using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
                {
                    if (GUILayout.Button("Fire"))
                    {
                        launcher.Fire();
                    }
                }
            }
            GUILayout.EndArea();
            rect.yMin = SceneView.currentDrawingSceneView.position.height - rectMin.y - 30;

            GUILayout.BeginArea(rect);
            {
                using (new EditorGUI.DisabledGroupScope(!Application.isPlaying))
                {
                    if (GUILayout.Button("Aim"))
                    {
                        launcher.Aim();
                    }
                }
            }
            GUILayout.EndArea();
        }
        Handles.EndGUI();
    }