Unity由于要自定义角色皮肤颜色,所以写了个取色板ColorPalette

理论任何环境下可用,包括手机运行时...

效果如下:

ColorPalette.gif

代码如下(只写了一点简单的注释,逻辑也不是很复杂,有空再补吧):

using System;
using UnityEngine;
using UnityEngine.UI;

public class ColorPalette : MonoBehaviour
{
    //C_DragHandler为自己封装的Event事件,可以自己通过IBeginDragHandler, IDragHandler, IEndDragHandler实现是一样的,这里用自己的库就懒得改了
    C_DragHandler drag_SaturationPanel;
    //C_PointerDownAndUpHandler同理,实际上也就是继承IPointerDownHandler, IPointerUpHandler即可
    C_PointerDownAndUpHandler dau_SaturationPanel;
    RectTransform mark_SaturationPos;

    C_DragHandler drag_HuePanell;
    C_PointerDownAndUpHandler dau_HuePanell;
    RectTransform mark_HuePos;

    C_DragHandler drag_TransparentPanel;
    C_PointerDownAndUpHandler dau_TransparentPanel;
    RectTransform mark_TransparentPos;

    Image SaturationPanel;
    Image HuePanel;
    Image TransparentPanel;
    Image CurrentColorPanel;

    RectTransform rect_SaturationPanel;
    RectTransform rect_HuePanel;
    RectTransform rect_TransparentPanel;

    Sprite sprite_Saturation;
    Sprite sprite_Hue;
    Sprite sprite_TransparentPanel;

    public Button Btn_Apply;

    private Color color_Hue = Color.red;

    Color current_color = Color.white;

    public Action OnColorPaletteSelectedColor;

    public void Awake()
    {
        Btn_Apply = this.transform.Find("Container/Btn_Apply").GetComponent

你可能感兴趣的:(Unity由于要自定义角色皮肤颜色,所以写了个取色板ColorPalette)