Advertisement
Guest User

CharacterGenerator.cs

a guest
Jan 1st, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4.  
  5. public class CharacterGenerator : MonoBehaviour
  6. {
  7.     private PlayerCharacter _toon;
  8.     private const int STARTING_POINTS = 350;
  9.     private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
  10.     private int pointsLeft;
  11.  
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         _toon = new PlayerCharacter();
  16.         _toon.Awake();
  17.  
  18.         pointsLeft = STARTING_POINTS;
  19.  
  20.         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
  21.         {
  22.             _toon.GetPrimaryAttribute(cnt).BaseValue = MIN_STARTING_ATTRIBUTE_VALUE;
  23.         }
  24.     }
  25.  
  26.     // Update is called once per frame
  27.     void Update () {
  28.         _toon.StatUpdate();
  29.     }
  30.  
  31.     void OnGUI()
  32.     {
  33.         DisplayName();
  34.         DisplayPointsLeft();
  35.         DisplayAttributes();
  36.         DisplayVitals();
  37.         DisplaySkills();
  38.     }
  39.  
  40.     private void DisplayName()
  41.     {
  42.         GUI.Label(new Rect(10, 10, 50, 25), "Name:");
  43.         _toon.Name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.Name);
  44.     }
  45.  
  46.     private void DisplayAttributes()
  47.     {
  48.         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
  49.         {
  50.             GUI.Label(new Rect(10, 40 + (cnt * 25), 100, 25), ((AttributeName)cnt).ToString() + ":" );
  51.             GUI.Label(new Rect(115, 40 + (cnt * 25), 30, 25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString() );
  52.             if(GUI.Button(new Rect(150, 40 + (cnt * 25), 25, 25), "-")){
  53.                 if(_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE)
  54.                 {
  55.                     _toon.GetPrimaryAttribute(cnt).BaseValue--;
  56.                     pointsLeft++;
  57.                 }
  58.             }
  59.             if(GUI.Button(new Rect(180, 40 + (cnt * 25), 25, 25), "+")){
  60.                 if(pointsLeft > 0)
  61.                 {
  62.                     _toon.GetPrimaryAttribute(cnt).BaseValue++;
  63.                     pointsLeft--;
  64.                 }
  65.             }
  66.         }
  67.     }
  68.  
  69.     private void DisplayVitals()
  70.     {
  71.         for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++)
  72.         {
  73.             GUI.Label(new Rect(10, 40 + ((cnt +7) * 25), 100, 25), ((VitalName)cnt).ToString() + ":" );
  74.             GUI.Label(new Rect(115, 40 + ((cnt +7) * 25), 30, 25), _toon.GetVital(cnt).AdjustedBaseValue.ToString() );
  75.         }
  76.     }
  77.  
  78.     private void DisplaySkills()
  79.     {
  80.         for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++)
  81.         {
  82.             GUI.Label(new Rect(250, 40 + (cnt * 25), 105, 25), ((SkillName)cnt).ToString() + ":" );
  83.             GUI.Label(new Rect(355, 40 + (cnt * 25), 30, 25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString() );
  84.         }
  85.     }
  86.  
  87.     private void DisplayPointsLeft()
  88.     {
  89.         GUI.Label(new Rect(250, 10, 100, 25), "Points Left: " + pointsLeft);
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement