ppg-snippets icon indicating copy to clipboard operation
ppg-snippets copied to clipboard

how to add a category

Open An4r3w opened this issue 3 years ago • 2 comments

how can i add a category for all my custom humans guns and objects?

An4r3w avatar Feb 26 '22 17:02 An4r3w

using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;


public class CategoryBuilder
{
    /// <summary>
    /// Use this method to create your own category.
    /// </summary>
    /// <param name="name">New category name</param>
    /// <param name="description">Description of the new category</param>
    /// <param name="icon">New category icon</param>
    public static void Create(string name, string description, Sprite icon)
    {
        CatalogBehaviour manager = UnityEngine.Object.FindObjectOfType<CatalogBehaviour>();
        if (manager.Catalog.Categories.FirstOrDefault((Category c) => c.name == name) == null)
        {
            Category category = ScriptableObject.CreateInstance<Category>();
            category.name = name;
            category.Description = description;
            category.Icon = icon;
            Category[] NewCategories = new Category[manager.Catalog.Categories.Length + 1];
            Category[] categories = manager.Catalog.Categories;
            for (int i = 0; i < categories.Length; i++)
            {
                NewCategories[i] = categories[i];
            }
            NewCategories[NewCategories.Length - 1] = category;
            manager.Catalog.Categories = NewCategories;
        }
    }
}

copy and paste all of the first code into a clean .cs file and call it CategoryBuilder

CategoryBuilder.Create("NameOfCategory", "DescriptionOfCategory", ModAPI.LoadSprite("ImageOfCategory.png")); create another .cs file and call it script.cs, then you use the basic entry point code and paste this line inside Main.

Make sure your mod.json file have this line below Scripts "CategoryBuilder.cs",

If you want to add custom content to the category just find the category u created CategoryOverride = ModAPI.FindCategory("CustomCategorynamegoeshere"),

R0Y1T0 avatar Mar 06 '22 18:03 R0Y1T0

Hello, first of all thank you so much. I have another question tho, what size must be the category icon? Can i add color to it?

An4r3w avatar Mar 08 '22 14:03 An4r3w