Example #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken token = JToken.Load(reader);

            if (token.Type == JTokenType.Array)
            {
                string[]             categoryIds   = token.ToObject <string[]>();
                SpriteCategoryInfo[] categoryInfos = new SpriteCategoryInfo[categoryIds.Length];
                if (categoryIds.Length != SpriteCategoryPool.Count)
                {
                    throw new ArgumentException($"Categories must match the length of {SpriteCategoryPool.Count}!");
                }
                HashSet <string> categoryIdSet = new HashSet <string>();
                for (int i = 0; i < SpriteCategoryPool.Count; i++)
                {
                    string categoryId = categoryIds[i];
                    if (!categoryIdSet.Add(categoryId))
                    {
                        throw new ArgumentException($"Category \"{categoryId}\" is already contained in array!");
                    }
                    categoryInfos[i] = SpriteCategoryPool.Get(categoryId);
                }
                return(categoryInfos);
            }
            throw new InvalidOperationException("must be an array!");
        }
        private void OnMoveSpritePrimaryCategoryUp()
        {
            int index = SelectedSpritePrimaryCategoryIndex;
            SpriteCategoryInfo swap = SpritePrimaryCategories[index];

            SpritePrimaryCategories[index]     = SpritePrimaryCategories[index - 1];
            SpritePrimaryCategories[index - 1] = swap;
            SelectedSpritePrimaryCategoryIndex = index - 1;
        }
        private void OnMoveSpriteSecondaryCategoryDown()
        {
            int index = SelectedSpriteSecondaryCategoryIndex;
            SpriteCategoryInfo swap = SpriteSecondaryCategories[index];

            SpriteSecondaryCategories[index]     = SpriteSecondaryCategories[index + 1];
            SpriteSecondaryCategories[index + 1] = swap;
            SelectedSpriteSecondaryCategoryIndex = index + 1;
        }