Спасибо.
Скрипт
Синтаксис:
Используется csharp
public class BaseStat {
private int _baseValue;
private int _buffValue;
private int _expToLevel;
private float _levelModifier;
public BaseStat(){
_baseValue = 0;
_buffValue = 0;
_levelModifier = 1.1f;
_expToLevel = 100;
}
#region Базові функції по вибірці і назначення основних параметрів класа
public int BaseValue {
get{return _baseValue;}
set{_baseValue = value;}
}
public int BuffValue{
get{return _buffValue;}
set{_buffValue = value;}
}
public int ExpToLevel{
get{return _expToLevel;}
set{_expToLevel = value;}
}
public float LevelModefier{
get{return _levelModifier;}
set{_levelModifier = value;}
}
#endregion
private int CalculateExpToLevel(){
return (int)(_expToLevel * _levelModifier);
}
private void LevelUp(){
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedBaseValue {
get {return _baseValue + _buffValue;}
}
}
private int _baseValue;
private int _buffValue;
private int _expToLevel;
private float _levelModifier;
public BaseStat(){
_baseValue = 0;
_buffValue = 0;
_levelModifier = 1.1f;
_expToLevel = 100;
}
#region Базові функції по вибірці і назначення основних параметрів класа
public int BaseValue {
get{return _baseValue;}
set{_baseValue = value;}
}
public int BuffValue{
get{return _buffValue;}
set{_buffValue = value;}
}
public int ExpToLevel{
get{return _expToLevel;}
set{_expToLevel = value;}
}
public float LevelModefier{
get{return _levelModifier;}
set{_levelModifier = value;}
}
#endregion
private int CalculateExpToLevel(){
return (int)(_expToLevel * _levelModifier);
}
private void LevelUp(){
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedBaseValue {
get {return _baseValue + _buffValue;}
}
}
Синтаксис:
Используется csharp
using System.Collections.Generic;
public class ModifietStat : BaseStat {
public List<ModifyingAttribute> _mods;
public int _modValue;
public ModifietStat(){
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier (ModifyingAttribute mod){
_mods.Add(mod);
}
private void CalculateModValue(){
_modValue = 0;
if (_mods.Count>0)
foreach(ModifyingAttribute att in _mods)
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
public new int AdjustBaseValue{
get {return BaseValue + BuffValue + _modValue;}
}
public void Update(){
CalculateModValue();
}
}
public struct ModifyingAttribute{
public Attribute attribute;
public float ratio;
public ModifyingAttribute (Attribute att, float rat){
attribute = att;
ratio = rat;
}
}
public class ModifietStat : BaseStat {
public List<ModifyingAttribute> _mods;
public int _modValue;
public ModifietStat(){
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier (ModifyingAttribute mod){
_mods.Add(mod);
}
private void CalculateModValue(){
_modValue = 0;
if (_mods.Count>0)
foreach(ModifyingAttribute att in _mods)
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
public new int AdjustBaseValue{
get {return BaseValue + BuffValue + _modValue;}
}
public void Update(){
CalculateModValue();
}
}
public struct ModifyingAttribute{
public Attribute attribute;
public float ratio;
public ModifyingAttribute (Attribute att, float rat){
attribute = att;
ratio = rat;
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System;
public class BaseCharacter : MonoBehaviour {
private string _name;
private int _level;
private uint _freeExp;
private Attribute[] _primaryAttribute;
private Vital[] _vital;
private Skill[] _skill;
public void Awake(){
_name = string.Empty;
_level = 0;
_freeExp = 0;
_vital = new Vital [Enum.GetValues(typeof(VitalName)).Length];
_skill = new Skill [Enum.GetValues(typeof(SkillName)).Length];
_primaryAttribute = new Attribute [Enum.GetValues (typeof (Attribute.AttributeNa)).Length];
//установка зависимостей атрибутов
SetupPrimaryAttribures();
SetupVitals();
SetupSkills();
}
public string Name {
get {return _name;}
set {_name = value;}
}
public int Level{
get {return _level;}
set {_level = value;}
}
public uint FreeExp{
get {return _freeExp;}
set {_freeExp = value;}
}
public void AddExp (uint exp){
_freeExp += exp;
CalculateLevel();
}
public void CalculateLevel(){
}
private void SetupPrimaryAttribures(){
for (int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals(){
for (int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt] = new Vital();
SetupVitalModifiers();
}
private void SetupSkills(){
for (int cnt = 0; cnt < _skill.Length; cnt++)
_skill[cnt] = new Skill();
SetupSkillModifiers();
}
public Attribute GetPrimaryAttribute (int index){
return _primaryAttribute[index];
}
public Skill GetSkill (int index){
return _skill[index];
}
public Vital GetVital (int index){
return _vital[index];
}
private void SetupVitalModifiers(){
//health
GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), .5f));
//energy
GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), 1.0f));
//health
GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), 1.0f));
}
private void SetupSkillModifiers(){
//melle offine
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Might), .33f));
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Nimbleness), .33f));
//melle define
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f)) ;
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), .33f)) ;
//magic offine
GetSkill((int)SkillName.Magic_Offince).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Magic_Offince).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), .33f));
//magic define
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), .33f));
//ranged offine
GetSkill((int)SkillName.Ranger_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Ranger_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f));
//ranged define
GetSkill((int)SkillName.Ranger_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f));
GetSkill((int)SkillName.Ranger_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Nimbleness), .33f));
}
public void StatUpdate(){
for (int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt].Update();
for (int cnt = 0; cnt < _skill.Length; cnt++)
_skill [cnt].Update();
}
}
using System.Collections;
using System;
public class BaseCharacter : MonoBehaviour {
private string _name;
private int _level;
private uint _freeExp;
private Attribute[] _primaryAttribute;
private Vital[] _vital;
private Skill[] _skill;
public void Awake(){
_name = string.Empty;
_level = 0;
_freeExp = 0;
_vital = new Vital [Enum.GetValues(typeof(VitalName)).Length];
_skill = new Skill [Enum.GetValues(typeof(SkillName)).Length];
_primaryAttribute = new Attribute [Enum.GetValues (typeof (Attribute.AttributeNa)).Length];
//установка зависимостей атрибутов
SetupPrimaryAttribures();
SetupVitals();
SetupSkills();
}
public string Name {
get {return _name;}
set {_name = value;}
}
public int Level{
get {return _level;}
set {_level = value;}
}
public uint FreeExp{
get {return _freeExp;}
set {_freeExp = value;}
}
public void AddExp (uint exp){
_freeExp += exp;
CalculateLevel();
}
public void CalculateLevel(){
}
private void SetupPrimaryAttribures(){
for (int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals(){
for (int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt] = new Vital();
SetupVitalModifiers();
}
private void SetupSkills(){
for (int cnt = 0; cnt < _skill.Length; cnt++)
_skill[cnt] = new Skill();
SetupSkillModifiers();
}
public Attribute GetPrimaryAttribute (int index){
return _primaryAttribute[index];
}
public Skill GetSkill (int index){
return _skill[index];
}
public Vital GetVital (int index){
return _vital[index];
}
private void SetupVitalModifiers(){
//health
GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), .5f));
//energy
GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), 1.0f));
//health
GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), 1.0f));
}
private void SetupSkillModifiers(){
//melle offine
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Might), .33f));
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Nimbleness), .33f));
//melle define
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f)) ;
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Constitution), .33f)) ;
//magic offine
GetSkill((int)SkillName.Magic_Offince).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Magic_Offince).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), .33f));
//magic define
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Willpower), .33f));
//ranged offine
GetSkill((int)SkillName.Ranger_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Concentration), .33f));
GetSkill((int)SkillName.Ranger_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f));
//ranged define
GetSkill((int)SkillName.Ranger_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Speed), .33f));
GetSkill((int)SkillName.Ranger_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)Attribute.AttributeNa.Nimbleness), .33f));
}
public void StatUpdate(){
for (int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt].Update();
for (int cnt = 0; cnt < _skill.Length; cnt++)
_skill [cnt].Update();
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System;
public class CharacterGenerator: MonoBehaviour {
private PlayerCharacter _toon;
private const int STARTING_POINTS = 20;
private const int MIN_STARTING_ATTRIBUTE_VALUE = 50;
private const int STARTING_VALUE = 50;
private int pointsLeft;
public GUISkin mySkin;
public GameObject playerPrefab;
// Use this for initialization
void Start () {
GameObject pc = Instantiate (playerPrefab, Vector3.zero, Quaternion.identity)as GameObject;
pc.name = "_pc";
// _toon = new PlayerCharacter();
// _toon.Awake();
_toon = pc.GetComponent<PlayerCharacter>();
pointsLeft = STARTING_POINTS;
for(int cnt = 0; cnt <Enum.GetValues(typeof (Attribute.AttributeNa)).Length; cnt++){
_toon.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
//pointsLeft -=(STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
}
_toon.StatUpdate();
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
GUI.skin = mySkin;
DisplayName();
DisplayAttributes();
DisplayPointsLeft();
DisplayVitals();
DisplaysSkills();
DisplayCreateButton();
}
private void DisplayName(){
GUI.Label (new Rect(10,10,100,25), "Имя:");
_toon.Name = GUI.TextArea (new Rect (120,10,200,25), _toon.Name);
}
private void DisplayAttributes(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (Attribute.AttributeNa)).Length; cnt++){
GUI.Label (new Rect (10,40 + (cnt*25),150,25), ((Attribute.AttributeNa)cnt).ToString());
GUI.Label (new Rect (160,40 + (cnt*25),50,25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if(GUI.Button (new Rect (220, 40 + (cnt*25), 30, 25), "+")){
if (pointsLeft > 0){
_toon.GetPrimaryAttribute(cnt).BaseValue++;
pointsLeft--;
_toon.StatUpdate();
}
}
if(GUI.Button (new Rect (253, 40 + (cnt*25), 30, 25), "-")){
if (_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE){
_toon.GetPrimaryAttribute(cnt).BaseValue--;
pointsLeft++;
_toon.StatUpdate();
}
}
}
}
private void DisplayVitals(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (VitalName)).Length; cnt++){
GUI.Label (new Rect (10,40 + ((cnt+7)*25),150,25), ((VitalName)cnt).ToString() );
GUI.Label (new Rect (160,40 + ((cnt+7)*25),50,25), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplaysSkills(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (SkillName)).Length; cnt++){
GUI.Label (new Rect (300,40 + (cnt*25),150,25), ((SkillName)cnt).ToString() );
GUI.Label (new Rect (455,40 + (cnt*25),50,25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplayPointsLeft(){
GUI.Label (new Rect(320,10,200,25), "Очки обучения: "+pointsLeft.ToString());
}
private void DisplayCreateButton(){
if (GUI.Button (new Rect (400, 260, 100, 30),"Старт")){
GameObject gs = GameObject.Find ("__GameSetting");
GameSetting gsScript = gs.GetComponent<GameSetting>();
gsScript.SaveCharacterData();
Application.LoadLevel("02");
}
}
}
using System.Collections;
using System;
public class CharacterGenerator: MonoBehaviour {
private PlayerCharacter _toon;
private const int STARTING_POINTS = 20;
private const int MIN_STARTING_ATTRIBUTE_VALUE = 50;
private const int STARTING_VALUE = 50;
private int pointsLeft;
public GUISkin mySkin;
public GameObject playerPrefab;
// Use this for initialization
void Start () {
GameObject pc = Instantiate (playerPrefab, Vector3.zero, Quaternion.identity)as GameObject;
pc.name = "_pc";
// _toon = new PlayerCharacter();
// _toon.Awake();
_toon = pc.GetComponent<PlayerCharacter>();
pointsLeft = STARTING_POINTS;
for(int cnt = 0; cnt <Enum.GetValues(typeof (Attribute.AttributeNa)).Length; cnt++){
_toon.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
//pointsLeft -=(STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
}
_toon.StatUpdate();
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
GUI.skin = mySkin;
DisplayName();
DisplayAttributes();
DisplayPointsLeft();
DisplayVitals();
DisplaysSkills();
DisplayCreateButton();
}
private void DisplayName(){
GUI.Label (new Rect(10,10,100,25), "Имя:");
_toon.Name = GUI.TextArea (new Rect (120,10,200,25), _toon.Name);
}
private void DisplayAttributes(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (Attribute.AttributeNa)).Length; cnt++){
GUI.Label (new Rect (10,40 + (cnt*25),150,25), ((Attribute.AttributeNa)cnt).ToString());
GUI.Label (new Rect (160,40 + (cnt*25),50,25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if(GUI.Button (new Rect (220, 40 + (cnt*25), 30, 25), "+")){
if (pointsLeft > 0){
_toon.GetPrimaryAttribute(cnt).BaseValue++;
pointsLeft--;
_toon.StatUpdate();
}
}
if(GUI.Button (new Rect (253, 40 + (cnt*25), 30, 25), "-")){
if (_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE){
_toon.GetPrimaryAttribute(cnt).BaseValue--;
pointsLeft++;
_toon.StatUpdate();
}
}
}
}
private void DisplayVitals(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (VitalName)).Length; cnt++){
GUI.Label (new Rect (10,40 + ((cnt+7)*25),150,25), ((VitalName)cnt).ToString() );
GUI.Label (new Rect (160,40 + ((cnt+7)*25),50,25), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplaysSkills(){
for(int cnt = 0; cnt <Enum.GetValues(typeof (SkillName)).Length; cnt++){
GUI.Label (new Rect (300,40 + (cnt*25),150,25), ((SkillName)cnt).ToString() );
GUI.Label (new Rect (455,40 + (cnt*25),50,25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplayPointsLeft(){
GUI.Label (new Rect(320,10,200,25), "Очки обучения: "+pointsLeft.ToString());
}
private void DisplayCreateButton(){
if (GUI.Button (new Rect (400, 260, 100, 30),"Старт")){
GameObject gs = GameObject.Find ("__GameSetting");
GameSetting gsScript = gs.GetComponent<GameSetting>();
gsScript.SaveCharacterData();
Application.LoadLevel("02");
}
}
}
Синтаксис:
Используется csharp
public class Attribute : BaseStat {
public Attribute(){
ExpToLevel = 50;
LevelModefier = 1.05f;
}
public enum AttributeNa {
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
}
public Attribute(){
ExpToLevel = 50;
LevelModefier = 1.05f;
}
public enum AttributeNa {
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
}
Синтаксис:
Используется csharp
public class Skill : ModifietStat {
private bool _known;
public Skill(){
_known = false;
ExpToLevel = 25;
LevelModefier = 1.1f;
}
public bool Known {
get {return _known;}
set {_known = value;}
}
}
public enum SkillName{
Melee_Offence,
Melee_Defence,
Ranger_Offence,
Ranger_Defence,
Magic_Offince,
Magic_Defence
}
private bool _known;
public Skill(){
_known = false;
ExpToLevel = 25;
LevelModefier = 1.1f;
}
public bool Known {
get {return _known;}
set {_known = value;}
}
}
public enum SkillName{
Melee_Offence,
Melee_Defence,
Ranger_Offence,
Ranger_Defence,
Magic_Offince,
Magic_Defence
}
Синтаксис:
Используется csharp
public class Vital : ModifietStat {
private int _curValue;
public Vital(){
_curValue = 0;
ExpToLevel = 50;
LevelModefier = 1.1f;
}
public int CurValue {
get {
if(_curValue > AdjustBaseValue)
_curValue = AdjustBaseValue;
return _curValue;
}
set {_curValue = value;}
}
}
public enum VitalName {
Health,
Energy,
Mana
}
private int _curValue;
public Vital(){
_curValue = 0;
ExpToLevel = 50;
LevelModefier = 1.1f;
}
public int CurValue {
get {
if(_curValue > AdjustBaseValue)
_curValue = AdjustBaseValue;
return _curValue;
}
set {_curValue = value;}
}
}
public enum VitalName {
Health,
Energy,
Mana
}