Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to create a scale field?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AzpxMsw, Dec 14, 2022.

  1. AzpxMsw

    AzpxMsw

    Joined:
    Jun 1, 2020
    Posts:
    13
    I need to create a scale field with x, y and z values for creating Box Collider with these values. Here's a code:


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class SampleWindow : EditorWindow
    7. {
    8.     bool Colliders;
    9.  
    10.     Vector2 scrollView = Vector2.zero;
    11.  
    12.     [MenuItem("Window/Other/Open Sample Window #M")]
    13.     static void onOpen()
    14.     {
    15.         EditorWindow.GetWindow(typeof(SampleWindow));
    16.     }
    17.  
    18.     void OnGUI()
    19.     {
    20.         Colliders = EditorGUILayout.Foldout(Colliders, "Colliders");
    21.         if (Colliders)
    22.         {
    23.             //Here I need to input scale values and build Box Collider with these values
    24.  
    25.             EditorGUILayout.BeginHorizontal();
    26.             if (GUILayout.Button("Box", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    27.             {
    28.                 GameObject build = new GameObject("Box");
    29.                 BoxCollider collider = build.AddComponent<BoxCollider>();
    30.                 collider.isTrigger = true;
    31.                 Selection.activeGameObject = build;
    32.             }
    33.             if (GUILayout.Button("Mesh", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    34.             {
    35.                 GameObject build = new GameObject("Mesh");
    36.                 build.AddComponent<UnityEngine.MeshCollider>();
    37.                 Selection.activeGameObject = build;
    38.             }
    39.             EditorGUILayout.EndHorizontal();
    40.         }
    41.     }
    42. }