Ejemplo n.º 1
0
 public override void Initialize()
 {
     serializeContext = delegate(bool pretty)
     {
         //TODO: create info field (optimization)
         CharacterData info = new CharacterData();
         info.Name             = Name;
         info.DataType         = typeof(CharacterData).ToString();
         info.ReferenceId      = ReferenceId;
         info.Position         = transform.position.Round(6);
         info.Rotation         = transform.rotation.eulerAngles.Round(3);
         info.Size             = transform.localScale;
         info.Groups           = Groups.ToArray();
         info.CurrentAnimation = CurrentAnimation;
         List <StatData> statsData = new List <StatData>();
         foreach (KeyValuePair <string, Stat> pair in stats)
         {
             StatData data = new StatData();
             data.Name  = pair.Key;
             data.Value = pair.Value.EffectiveValue;
             statsData.Add(data);
         }
         info.IsDead          = IsDead;
         info.LookingPos      = headLookingPos.Round(4);
         info.OwnerName       = Owner.Name;
         info.EquipedWeaponId = (EquipedWeapon != null) ? EquipedWeapon.Settings.Id : -1;
         return(JsonUtility.ToJson(info, pretty));
     };
     for (int i = 0; i < CharacterClass.SkillIds.Length; i++)
     {
         ScriptInfo     info  = ScriptDatabase.GetInstance().GetScript(CharacterClass.SkillIds[i]);
         SkillBehaviour skill = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour;
         AddSkill(skill);
     }
 }
Ejemplo n.º 2
0
 public void DecodeJson(string json)
 {
     //TODO: Strategy Pattern
     try
     {
         PacketData jsonData = JsonUtility.FromJson <PacketData>(json);
         if (jsonData.DataType == typeof(CharacterData).ToString())
         {
             CharacterData charData = JsonUtility.FromJson <CharacterData>(json);
             otherPlayerLastData = charData;
             NetUpdate();
         }
         else
         {
             if (jsonData.DataType == typeof(ScriptableData).ToString())
             {
                 ScriptableData scriptData = JsonUtility.FromJson <ScriptableData>(json);
                 ScriptInfo     info       = ScriptDatabase.GetInstance().GetScript(scriptData.ScriptId);
                 SkillBehaviour skill      = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour;
                 skill.Caster = otherPlayer;
                 skill.Initialize();
                 if (skill.OnCast != null)
                 {
                     Debug.Log("Cast");
                     skill.OnCast.RunContext();
                 }
             }
             else if (jsonData.DataType == typeof(ProjectileSpawnData).ToString())
             {
                 ProjectileSpawnData projData = JsonUtility.FromJson <ProjectileSpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnProjectile(projData.PrefabResourcePath, projData);
                 });
             }
             else
             {
                 SpawnData objSpawnData = JsonUtility.FromJson <SpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnObject(objSpawnData.PrefabResourcePath, objSpawnData);
                 });
             }
         }
     }
     catch
     {
         return;
     }
 }