Hello.
I’ve a strange message when I launch the game at this state of the course.
I understand that the classes aren’t in the dictionnary but why ?
I must signal that I haven’t a look like sam in the Progression scriptable object but it worked so far.
Is it an indentation problem ?
here is my Progression scriptable object “code”:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 10073e6f9ccbd1d468678ecd4a785653, type: 3}
m_Name: progression
m_EditorClassIdentifier:
characterClasses:
- characterClass: 0
stats:
- stat: 0
levels:
- 20
- 50
- 100
- 200
- 400
- characterClass: 4
stats:
- stat: 0
levels:
- 20
- 50
- 100
- stat: 1
levels:
- 15
- 30
- 60
- characterClass: 5
stats:
- stat: 0
levels:
- 20
- 50
- 100
- 200
- 400
- stat: 1
levels:
- 15
- 30
- 60
- 120
- 240
- characterClass: 6
stats:
- stat: 0
levels:
- 20
- 50
- 100
- 200
- 400
- stat: 1
levels:
- 15
- 30
- 60
- 120
- 240
My Classes are listed in the CharacterClass script :
namespace RPG.Stats
{
public enum CharacterClass
{
Player,
Primitif,
peasant,
Raider,
Cannibal_Unarmed,
Cannibal_OneHandWeapon,
Cannibal_TwoHandsWeapon,
Merchant,
Wanderer,
scientist,
technoFan
}
}
My Progression Script:
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RPG.Stats
{
[CreateAssetMenu(fileName = "progression", menuName = "RPG Stats/New Progression", order = 0)]
public class Progression:ScriptableObject
{
[SerializeField] ProgressionCharacterClass[] characterClasses = null;
Dictionary<CharacterClass,Dictionary<Stat, float[]>> lookupTable = null;
public float GetStat(Stat stat,CharacterClass characterClass, int level)//Dans cet ordre comme dans le code ci-après :
{
BuildLookup();
float[] levels = lookupTable[characterClass][stat];
if(levels.Length < level)
{
return 0;
}
return levels[level-1];
}
private void BuildLookup()
{
if(lookupTable != null) return;
lookupTable = new Dictionary<CharacterClass,Dictionary<Stat, float[]>>();
foreach(ProgressionCharacterClass progressionClass in characterClasses)
{
var statLookupTable = new Dictionary<Stat, float[]>();
foreach(ProgressionStat progressionStat in progressionClass.stats)
{
statLookupTable[progressionStat.stat] = progressionStat.levels;
}
lookupTable[progressionClass.characterClass] = statLookupTable;
}
}
[System.Serializable]
class ProgressionCharacterClass
{
public CharacterClass characterClass;
public ProgressionStat[] stats;
}
[System.Serializable]
class ProgressionStat
{
public Stat stat;
public float[] levels;//L'array sert pour le niveau du personnage.Ca vie sera différente en fonctiond e son niveau.
}
}
}
Any Idea ?
Thanks.
François