Ejemplo n.º 1
0
        private static void CreatePanel()
        {
            GameObject go = MenuItems.CreatePrefab("Panel", false);

            go.name = "Shapes2D Panel";
            if (MenuItems.AddToSelectedCanvas(go))
            {
                Undo.RegisterCreatedObjectUndo(go, "Create Shapes2D Panel");
            }
            else
            {
                bool   createdCanvas = false;
                Canvas canvas        = GameObject.FindObjectOfType <Canvas>();
                if (canvas == null || !canvas.enabled || canvas.transform.parent != null)
                {
                    canvas        = CreateCanvas();
                    createdCanvas = true;
                }
                go.transform.SetParent(canvas.transform);
                Selection.activeTransform = go.transform;
                if (createdCanvas)
                {
                    Undo.RegisterCreatedObjectUndo(canvas.gameObject, "Create Shapes2D Panel");
                }
                else
                {
                    Undo.RegisterCreatedObjectUndo(go, "Create Shapes2D Panel");
                }
            }
            RectTransform rt = go.GetComponent <RectTransform>();

            rt.offsetMin            = new Vector2(0, 0);
            rt.offsetMax            = new Vector2(0, 0);
            rt.transform.localScale = new Vector3(1, 1, 1);
        }
Ejemplo n.º 2
0
        private static void CreateButton()
        {
            GameObject go = MenuItems.CreatePrefab("Button", false);

            go.name = "Shapes2D Button";
            if (MenuItems.AddToSelectedCanvas(go))
            {
                Undo.RegisterCreatedObjectUndo(go, "Create Shapes2D Button");
            }
            else
            {
                bool   createdCanvas = false;
                Canvas canvas        = GameObject.FindObjectOfType <Canvas>();
                if (canvas == null || !canvas.enabled || canvas.transform.parent != null)
                {
                    canvas        = CreateCanvas();
                    createdCanvas = true;
                }
                go.transform.SetParent(canvas.transform);
                Selection.activeTransform = go.transform;
                if (createdCanvas)
                {
                    Undo.RegisterCreatedObjectUndo(canvas.gameObject, "Create Shapes2D Button");
                }
                else
                {
                    Undo.RegisterCreatedObjectUndo(go, "Create Shapes2D Button");
                }
            }
            go.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
            go.transform.localScale = new Vector3(1, 1, 1);
        }