seefood_diet / Assets / UIKit / UIStyleSheet.cs
UIStyleSheet.cs
Raw
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UIKit {

    public enum UIType {

        Undefined = 0,
        Button = 1,
        Dialog = 2,
        Alert = 3,
        ActionSheet = 4,
        Card = 5,
        Tag = 6,
        Bubble = 7
    }

    public enum UIStyleId {

        None = 0,
        Button = (int) UIType.Button * 100,
        SystemButton = (int) UIType.Button * 100 + 1,
        IconButton = (int) UIType.Button * 100 + 2,
        SceneIconButton = (int) UIType.Button * 100 + 3,

        Dialog = (int) UIType.Dialog * 100,
        Alert = (int) UIType.Alert * 100,
        ActionSheet = (int) UIType.ActionSheet * 100,
        Card = (int) UIType.Card * 100,
        Tag = (int) UIType.Tag * 100,
        Bubble = (int) UIType.Bubble * 100,
    }

    [CreateAssetMenu (menuName = "StyleSheet")]
    public class UIStyleSheet : ScriptableObject, ISerializationCallbackReceiver {

        public Dictionary<string, UIStyle> StyleSheet = new Dictionary<string, UIStyle> ();

        public List<string> StyleKeyList = new List<string> ();
        public List<UIStyle> StyleList = new List<UIStyle> ();

        public void OnBeforeSerialize () {

            StyleKeyList.Clear ();
            StyleList.Clear ();

            foreach (var item in Enum.GetValues (typeof (UIStyleId))) {

                var key = item.ToString ();
                StyleKeyList.Add (key);
                StyleList.Add (StyleSheet.ContainsKey (key) ? StyleSheet[key] : new UIStyle ());
            }
        }

        public void OnAfterDeserialize () {

            StyleSheet.Clear ();

            for (int i = 0; i < StyleKeyList.Count; ++i) {
                StyleSheet[StyleKeyList[i]] = StyleList[i];
            }
        }
    }
}