Beispiel #1
0
    // Create STexture
    public static STexture AddTexture(GameObject gameObject)
    {
        STexture texture = UGUITools.AddChild <STexture>(gameObject);

        (texture as RawImage).raycastTarget = false;
        UGUITools.ResetGameObject(texture.gameObject);

        return(texture);
    }
Beispiel #2
0
    // Create SImage
    public static SImage AddImage(GameObject gameObject)
    {
        SImage image = UGUITools.AddChild <SImage>(gameObject);

        image.Atlas         = atlas;
        image.SpriteName    = selectedSprite;
        image.raycastTarget = false;
        UGUITools.ResetGameObject(image.gameObject);

        return(image);
    }
Beispiel #3
0
    // Create SText
    public static SText AddText(GameObject gameObject)
    {
        SText txt = UGUITools.AddChild <SText>(gameObject);

        txt.textStyle               = textStyle;
        txt.text                    = "New Text";
        txt.color                   = Color.black;
        txt.raycastTarget           = false;
        txt.rectTransform.sizeDelta = new Vector2(120, 200);
        UGUITools.ResetGameObject(txt.gameObject);
        return(txt);
    }
Beispiel #4
0
    // Create SMask
    public static SMask AddMask(GameObject gameObject)
    {
        SMask mask = UGUITools.AddChild <SMask>(gameObject);

        mask.name                    = "SMask";
        mask.raycastTarget           = true;
        mask.rectTransform.anchorMin = Vector2.zero;
        mask.rectTransform.anchorMax = Vector2.one;
        mask.rectTransform.sizeDelta = Vector2.zero;
        UGUITools.ResetGameObject(mask.gameObject);

        return(mask);
    }
Beispiel #5
0
    // Create SButton
    public static SButton AddButton(GameObject gameObject)
    {
        var bg = AddImage(gameObject);

        bg.rectTransform.sizeDelta = new Vector2(200, 60);

        var txt = AddText(bg.gameObject);

        txt.rectTransform.anchorMin = Vector2.zero;
        txt.rectTransform.anchorMax = Vector2.one;
        txt.rectTransform.sizeDelta = Vector2.zero;
        txt.alignment      = TextAnchor.MiddleCenter;
        txt.textStyle      = textStyle;
        bg.gameObject.name = "SButton";
        bg.raycastTarget   = true;
        UGUITools.ResetGameObject(bg.gameObject);
        SButton result = bg.gameObject.AddComponent <SButton>();

        result.SText = txt;
        return(result);
    }
Beispiel #6
0
    // Create Canvas
    public static Canvas AddCanvas(GameObject gameObject)
    {
        GameObject go     = new GameObject("Canvas");
        var        canvas = go.AddComponent <Canvas>();

        canvas.renderMode  = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = Camera.main;

        CanvasScaler scaler = go.AddComponent <CanvasScaler>();

        scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
        scaler.referenceResolution = new Vector2(1280, 720);

        go.AddComponent <GraphicRaycaster>();

        if (gameObject)
        {
            go.transform.SetParent(gameObject.transform);
        }
        UGUITools.ResetGameObject(go);

        CreateEventSystem();
        return(canvas);
    }