コード例 #1
0
ファイル: LookupRegistry.cs プロジェクト: MegaPiggy/SRML
        /// <summary>
        /// Register a toy (note: does not register the identifiable itself, only the toy, do that separately)
        /// </summary>
        /// <param name="id"><see cref="Identifiable.Id"/> of the toy</param>
        /// <param name="icon">Icon for the toy in the toy store</param>
        /// <param name="cost">How much the toy costs in the toy store</param>
        /// <param name="nameKey"></param>
        public static void RegisterToy(Identifiable.Id id, Sprite icon, int cost, string nameKey)
        {
            ToyDefinition definition = ScriptableObject.CreateInstance <ToyDefinition>();

            definition.toyId   = id;
            definition.icon    = icon;
            definition.cost    = cost;
            definition.nameKey = nameKey?.ToLower() ?? id.ToString().ToLower();
            RegisterToy(definition);
        }
コード例 #2
0
        /// <summary>
        /// Creates a Toy Definition
        /// </summary>
        /// <param name="toyId">The ID of the toy for this definition</param>
        /// <param name="icon">The icon to be displayed</param>
        /// <param name="cost">The cost of this toy</param>
        /// <param name="nameKey">The name for the language key</param>
        public static ToyDefinition CreateToyDefinition(Identifiable.Id toyId, Sprite icon, int cost, string nameKey = null)
        {
            ToyDefinition definition = ScriptableObject.CreateInstance <ToyDefinition>();

            definition.SetPrivateField("toyId", toyId);
            definition.SetPrivateField("icon", icon);
            definition.SetPrivateField("cost", cost);
            definition.SetPrivateField("nameKey", nameKey?.ToLower() ?? toyId.ToString().ToLower());

            return(definition);
        }
コード例 #3
0
        /// <summary>
        /// Register <paramref name="entry"/> into the <see cref="LookupDirector"/>
        /// </summary>
        /// <param name="entry">Entry to register</param>
        public static void RegisterToy(ToyDefinition entry)
        {
            switch (SRModLoader.CurrentLoadingStep)
            {
            case LoadingStep.PRELOAD:
                toysToPatch.Add(entry);
                break;

            default:
                GameContext.Instance.LookupDirector.toyDefinitions.AddAndRemoveWhere(entry, (x, y) => x.toyId == y.toyId);
                GameContext.Instance.LookupDirector.toyDict[entry.toyId] = entry;
                break;
            }
        }