Example #1
0
    /// <summary>
    /// GUI definition for Classic Tab
    /// </summary>
    void OnGUI()
    {
        if (AlignEditor.editorPath == null)
        {
            AlignEditor.editorPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
        }

        title        = "AE Camera v" + AlignEditor.VERSION;
        this.minSize = new Vector2(180, 56);
        mainScroll   = EditorGUILayout.BeginScrollView(mainScroll);
        GUILayout.BeginHorizontal();
        CameraButtonGUI(Selection.transforms);
        AlignEditor.SettingsButtonGUI();
        GUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();
    }
    void OnGUI()
    {
        if (AlignEditor.editorPath == null)
        {
            AlignEditor.editorPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
        }

        title = "AllIn v" + AlignEditor.VERSION;
        ImagePosition wasPosition = AlignEditor.ButtonStyle;

        // v2.0 : automatic layout from ratio width/height
        if (this.position.width > this.position.height)
        {
            EditorGUILayout.BeginHorizontal();
            this.minSize = new Vector2(292, 58);
        }
        else
        {
            // Force image above for vertical layout
            if (wasPosition == ImagePosition.ImageLeft)
            {
                AlignEditor.ButtonStyle = ImagePosition.ImageAbove;
            }
            this.minSize = new Vector2(52, 256);
        }
        ClassicWindow.DetectAlignAxis();
        ClassicWindow.AlignButtonGUI(Selection.transforms, true);
        GridWindow.GridButtonGUI(Selection.transforms);
        CameraWindow.CameraButtonGUI(Selection.transforms);

        AlignEditor.SettingsButtonGUI();
        if (this.position.width > this.position.height)
        {
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            AlignEditor.ButtonStyle = wasPosition;
        }
        // Restore the previous state of button style
    }
    void OnGUI()
    {
        if (AlignEditor.editorPath == null)
        {
            AlignEditor.editorPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
        }

        title      = "AE Grid v" + AlignEditor.VERSION;
        mainScroll = EditorGUILayout.BeginScrollView(mainScroll);
        // auto grid size is enabled for distribution (if there is more than 1 selected object)
        bool GUIWasEnabled = GUI.enabled;

        GUI.enabled = (Selection.transforms.Length > 1);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Grid Size");
        Vector3 gridSize       = AlignEditor.gridSize;
        bool    wantedAutoSize = GUILayout.Toggle(AlignEditor.autoSize, "auto", "MiniButton", GUILayout.Width(70));

        if (wantedAutoSize != AlignEditor.autoSize)
        {
            Undo.RegisterUndo(this, "change auto grid size");
            AlignEditor.autoSize = wantedAutoSize;
        }
        EditorGUILayout.EndHorizontal();
        GUI.enabled = GUIWasEnabled;

        EditorGUILayout.BeginHorizontal();
        if (AlignEditor.autoSize && (Selection.transforms.Length > 1))
        {
            AlignEditor.calculatedGridSize = Mathf.Max(Mathf.CeilToInt(Mathf.Pow(Selection.transforms.Length, 1 / 3)), 2);
            EditorGUILayout.PrefixLabel("Every axis");
            GUILayout.Label("" + AlignEditor.calculatedGridSize);
        }
        else
        {
            Vector3 wantedGridSize = gridSize;
            GUILayout.Label("X");
            wantedGridSize.x = Mathf.Max(1, EditorGUILayout.IntField((int)gridSize.x));
            GUILayout.Label("Y");
            wantedGridSize.y = Mathf.Max(1, EditorGUILayout.IntField((int)gridSize.y));
            GUILayout.Label("Z");
            wantedGridSize.z = Mathf.Max(1, EditorGUILayout.IntField((int)gridSize.z));
            if (!wantedGridSize.Equals(gridSize))
            {
                Undo.RegisterUndo(this, "change grid size");
                AlignEditor.gridSize = wantedGridSize;
            }
        }
        EditorGUILayout.EndHorizontal();

        // Offset is enabled only for duplication (if there is only 1 selected object)
        GUIWasEnabled = GUI.enabled;
        GUI.enabled   = (Selection.transforms.Length == 1);
        Vector3 wantedOffset = EditorGUILayout.Vector3Field("Offset", AlignEditor.gridOffset);

        if (!wantedOffset.Equals(AlignEditor.gridOffset))
        {
            Undo.RegisterUndo(this, "change grid offset");
            AlignEditor.gridOffset = wantedOffset;
        }
        GUI.enabled = GUIWasEnabled;

        if (Selection.transforms.Length == 1)
        {
            EditorGUILayout.LabelField("Duplicate", Selection.activeTransform.name);
        }
        else if (Selection.transforms.Length > 1)
        {
            EditorGUILayout.LabelField("Distribute", "" + Selection.transforms.Length + " objects");
        }
        else
        {
            GUILayout.Label("Select 1 object to duplicate, N to distribute", EditorStyles.boldLabel);
        }
        EditorGUILayout.BeginHorizontal();
        GridButtonGUI(Selection.transforms);
        AlignEditor.SettingsButtonGUI();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();
    }
Example #4
0
    /// <summary>
    /// GUI definition for Classic Tab
    /// </summary>
    void OnGUI()
    {
        if (AlignEditor.editorPath == null)
        {
            AlignEditor.editorPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
        }

        title      = "AE Classic v" + AlignEditor.VERSION;
        mainScroll = EditorGUILayout.BeginScrollView(mainScroll);

        // New in 1.9 : the alignment is linked to the current Tool : None=Move=View=Position, Rotate=Rotation, Scale=Scale (!)

        // Axis alignement selection
        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.PrefixLabel("Axis");
        bool wantedAutoAxis = GUILayout.Toggle(AlignEditor.autoAxis, "auto", "MiniButton", GUILayout.Width(70));

        if (wantedAutoAxis != AlignEditor.autoAxis)
        {
            Undo.RegisterUndo(this, "change auto axis");
            AlignEditor.autoAxis = wantedAutoAxis;
        }
        // Auto set the axis from the last active view camera
        DetectAlignAxis();
        if (AlignEditor.autoAxis)
        {
            GUILayout.Label("Detected: " + AlignEditor.axis);
        }
        else
        {
            AlignEditor.AlignAxis wantedAxis = (AlignEditor.AlignAxis)EditorGUILayout.EnumPopup(AlignEditor.axis);
            if (wantedAxis != AlignEditor.axis)
            {
                Undo.RegisterUndo(this, "change axis");
                AlignEditor.axis = wantedAxis;
            }
        }
        EditorGUILayout.EndHorizontal();
        // Sort by axis selection
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Sort by");
        bool wantedUseAxis = GUILayout.Toggle(AlignEditor.useAlignAxis, "identical", "MiniButton", GUILayout.Width(70));

        if (wantedUseAxis != AlignEditor.useAlignAxis)
        {
            Undo.RegisterUndo(this, "change use align axis");
            AlignEditor.useAlignAxis = wantedUseAxis;
        }
        if (AlignEditor.useAlignAxis)
        {
            // Can not sort by "all" axis, indicates that to the user (X is the default)
            switch (AlignEditor.axis)
            {
            case AlignEditor.AlignAxis.Z:
                AlignEditor.sortBy = DistributionManager.SortAxis.Z;
                break;

            case AlignEditor.AlignAxis.Y:
                AlignEditor.sortBy = DistributionManager.SortAxis.Y;
                break;

            default:
                AlignEditor.sortBy = DistributionManager.SortAxis.X;
                break;
            }
            GUILayout.Label("Detected:" + AlignEditor.sortBy.ToString());
        }
        else
        {
            DistributionManager.SortAxis wantedSortBy = (DistributionManager.SortAxis)EditorGUILayout.EnumPopup(AlignEditor.sortBy);
            if (wantedSortBy != AlignEditor.sortBy)
            {
                Undo.RegisterUndo(this, "change sort by");
                AlignEditor.sortBy = wantedSortBy;
            }
        }
        EditorGUILayout.EndHorizontal();

        if (Selection.transforms.Length > 1)
        {
            EditorGUILayout.LabelField("Align with", Selection.activeTransform.name);
        }
        else
        {
            GUILayout.Label("Select at least 2 objects", EditorStyles.boldLabel);
        }

        GUILayout.Space(4);
        EditorGUILayout.BeginHorizontal();
        AlignButtonGUI(Selection.transforms, false);
        AlignEditor.SettingsButtonGUI();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();
    }