Creating a Button

확인 완료한 버전: 2017.3

-

난이도: 중급

In this session Online Evangelist Matt Gambell will take us through building a system that allows for a flexible and customisable way to work with UI in a project by taking advantage of the power of ScriptableObjects.

Creating a Button

중급 User Interface (UI)

FlexibleUIButton

Code snippet

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Image))]
[RequireComponent(typeof(Button))]
public class FlexibleUIButton : FlexibleUI
{

    Button button;
    Image image;

    public ButtonType buttonType;

    protected override void OnSkinUI()
    {

        base.OnSkinUI();
        image = GetComponent();
        button = GetComponent();

        button.transition = Selectable.Transition.SpriteSwap;
        button.targetGraphic = image;

        image.sprite = skinData.buttonSprite;
        image.type = Image.Type.Sliced;
        button.spriteState = skinData.buttonSpriteState;
}

관련 자습서