public void AddSkill(SkillBehaviour skill) { if (!skills.ContainsValue(skill)) { skill.Caster = this; skill.Initialize(); skills[skills.Count + 1] = skill; } }
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; } }