11000+款5星资源

8.5万+用户参与评分

10万+社区成员鼎力支持

每款资源都经过 Unity 审核

首页
工具
整合
1/8
Defines role playing attributes like "max health" using generics that can be modified non-destructively and notify on changes.
描述

There comes a time when many a gamedev sets out for adventure but first must create their own stat class. That is to say a class which captures a game "stat", or "statistic" for lack of a better word, like health, attack, defense, etc. This one is mine. Oh wait! there is a better word: "attribute." But I don't want to take "attribute" from your game, so I'll call mine IModifiableValue<T>. Consider it a sound building block for you to create your own attribute class.


These attributes and their derivatives may affect and be effected by a multitude of transient things, e.g, a sword that bestows an attack advantage; a shield that raises one's defense; a ring that regenerates health. Because of that attributes ought to respect the following requirements:


  • An attribute's value shall be altered non-destructively.
  • Because so many things may alter an attribute, it shall notify us when changed.

See sample scene here.

技术细节

Features

  • C# Interface Based

The heart of this library is defined by a few C# interfaces, making it easier to understand. Also one can substitute their own implementations easily if need be. 

  • Supports Generics

Too many libraries decide all attributes must be a float or an int. With this library one can choose which type suits an attribute, and they may still interact with one another.

  • Generic Math

Many a library probably shied away from generics because .NET has not had generic math support, i.e., it was not possible to write T Plus<T>(T a, T b) => a + b. The release of .NET 7 will have that support, which this library makes use of. In addition a workaround makes it possible to present the same API with netstandard2.0, which is important for Unity3D compatability.

  • Flexible Modifiers

Sure, one can add, minus, multiply, and divide their stats, but what about clamping the value? Is it easy to add that feature? With this library one can implement their own modifier or create ad hoc ones easily.

  • Generic RPG Sample Scene

This sample shows how one might structure their attributes and modifiers in a generic RPG mock up. The user interface is responsive. Tooltips show what effects items have, i.e., show their modifiers. Tooltips also show how each attribute is affected by any modifiers. The sword and shield can be equipped and unequipped. The other items can be consumed. Hit 'R' to reset and 'H' to show help.


Supports

  • Unity 2021.3 and later

Role Play Attributes

(暂无评分)
46 users have favourite this asset
(46)
FREE
13 views in the past week
高品质资源
11000+款5星资源
深受用户信赖
8.5万+用户参与评分
强大的社区支持
10万+社区成员鼎力支持
Unity logo
语言
反馈
合作伙伴计划
合作伙伴
USD
EUR
Copyright © 2025 Unity Technologies
所有价格不包含税
USD
EUR
FREE