protected override void OnCreate() { ecbs = World.GetOrCreateSystem <EntityCommandBufferSystem>(); pokemonMoveQuery = GetEntityQuery(ComponentType.ReadOnly(typeof(PlayerInput)), typeof(PokemonEntityData), typeof(Translation), typeof(Rotation), typeof(PhysicsVelocity)); pokemonMoveArchtype = EntityManager.CreateArchetype( typeof(Translation), typeof(Rotation), typeof(PokemonMoveDataEntity), typeof(RenderMesh), typeof(LocalToWorld), typeof(PhysicsCollider), typeof(PhysicsVelocity), typeof(PokemonMoveEntity), typeof(EntityParent), typeof(TranslationProxy), typeof(RotationProxy) ); groupIndexSystem = World.GetExistingSystem <GroupIndexSystem>(); }
/// <summary> /// Sets the RenderMesh of the given parameters /// </summary> /// <param name="entityManager">EntityManager</param> /// <param name="entity">PokemonMove Entity</param> /// <param name="pokemonMoveName">name of the pokemonMove</param> /* public static void SetPokemonMoveRenderMesh(EntityManager entityManager,Entity entity, string pokemonMoveName) * { * // Debug.Log("Pokemon/PokemonMoves/" + pokemonMoveName + "/" + pokemonMoveName); * GameObject go = Resources.Load("Pokemon/PokemonMoves/"+pokemonMoveName+"/"+pokemonMoveName) as GameObject; * if (go != null) * { * entityManager.SetSharedComponentData(entity, new RenderMesh * { * mesh = go.GetComponent<MeshFilter>().sharedMesh, * castShadows = UnityEngine.Rendering.ShadowCastingMode.On, * material = go.GetComponent<MeshRenderer>().sharedMaterial, * receiveShadows = true * }); * } * else Debug.LogError("Failed to load pokemon move mesh"); * }*/ /// <summary> /// Initializes the pokemon move entity /// </summary> /// <param name="entityManager">EntityManager</param> /// <param name="name">name of the pokemon move</param> /// <param name="orgEntity">the Entity that executed the move</param> /// <param name="entity">the PokemonMove Entity</param> /// <param name="ped">PokemonEntityData</param> public static void ExecutePokemonMove(EntityManager entityManager, string name, ByteString30 pokemonName, Entity orgEntity, Entity entity, PokemonEntityData ped, GroupIndexSystem groupIndexSystem) { //test if a move is already being executed on the entity parent if (!entityManager.HasComponent <EntityChild>(orgEntity)) { entityManager.AddComponentData <EntityChild>(orgEntity, new EntityChild { entity = entity, isValid = true, followChild = false }); if (groupIndexSystem == null) { Debug.LogError("GroupIndexSystem is null"); } Debug.Log("executing pokemon move \"" + name + "\""); PokemonMoveDataSpawn pmds = getPokemonMoveDataSpawn(entityManager, name, orgEntity, ped); PlayerInput pi = entityManager.GetComponentData <PlayerInput>(orgEntity); PokemonMoveDataEntity pmde = GetPokemonMoveDataEntity(new ByteString30(name), ped, pi.forward); if (pmds.hasEntity) { entityManager.SetComponentData(entity, new EntityParent { entity = orgEntity, isValid = true, followParent = true }); if (pmds.projectOnParentInstead) { // if (pmde.isValid) Debug.Log("It be valid!"); entityManager.AddComponentData(orgEntity, pmde); pmde.preformActionsOn = false; } } CoreData cd = entityManager.GetComponentData <CoreData>(orgEntity); entityManager.AddComponentData <CoreData>(entity, new CoreData(new ByteString30(name), new ByteString30("PokemonMove"), cd.size, cd.scale)); //get Pokemon's GroupIndex GroupIndexInfo gii = entityManager.GetComponentData <GroupIndexInfo>(orgEntity); gii.CurrentGroupIndex = groupIndexSystem.GetNextEmptyGroup(); gii.Update = true; entityManager.SetComponentData(orgEntity, gii); int a = groupIndexSystem.ExludeGroupIndexNumber(gii.CurrentGroupIndex); // Debug.Log("AAAAAAAAAAAAA "+a); //add group index but we want this to gii = new GroupIndexInfo { CurrentGroupIndex = gii.CurrentGroupIndex, OldGroupIndex = 0, OriginalGroupIndex = gii.CurrentGroupIndex, Update = true, }; entityManager.AddComponentData(entity, gii); //add/set collider if (pmds.hasCollider) { if (entityManager.HasComponent <PhysicsCollider>(entity)) { entityManager.SetComponentData(entity, pmds.physicsCollider); } else { entityManager.AddComponentData(entity, pmds.physicsCollider); } } if (pmds.hasDamping) { if (entityManager.HasComponent <PhysicsDamping>(entity)) { entityManager.SetComponentData(entity, pmds.physicsDamping); } else { entityManager.AddComponentData(entity, pmds.physicsDamping); } } if (pmds.hasGravityFactor) { if (entityManager.HasComponent <PhysicsGravityFactor>(entity)) { entityManager.SetComponentData(entity, pmds.physicsGravityFactor); } else { entityManager.AddComponentData(entity, pmds.physicsGravityFactor); } } if (pmds.hasMass) { if (entityManager.HasComponent <PhysicsMass>(entity)) { entityManager.SetComponentData(entity, pmds.physicsMass); } else { entityManager.AddComponentData(entity, pmds.physicsMass); } } if (entityManager.HasComponent <PokemonMoveDataEntity>(entity)) { entityManager.SetComponentData(entity, pmde); } else { entityManager.AddComponentData(entity, pmde); } if (pmds.hasPhysicsVelocity) { if (entityManager.HasComponent <PhysicsVelocity>(entity)) { entityManager.SetComponentData(entity, pmds.physicsVelocity); } else { entityManager.AddComponentData(entity, pmds.physicsVelocity); } } if (entityManager.HasComponent <Translation>(entity)) { entityManager.SetComponentData(entity, pmds.translation); } else { entityManager.AddComponentData(entity, pmds.translation); } if (entityManager.HasComponent <Rotation>(entity)) { entityManager.SetComponentData(entity, pmds.rotation); } else { entityManager.AddComponentData(entity, pmds.rotation); } //add particle stuff ParticleSystemSpawnData pssd = PokemonMoves.getPokemonMoveParticleSystemData(ped.PokedexNumber, name); if (pssd.isValid) { Debug.Log("detected particleSystemspawn data"); entityManager.AddComponentData(entity, pssd); } else { Debug.LogWarning("ExecutePokemonMove: Failed to get ParticleSystemSpawnData!"); } if (pmds.hasParticles) { entityManager.AddComponentData(entity, new ParticleSystemRequest { }); entityManager.AddComponentData(entity, new ParticleSystemData { }); } if (!entityManager.HasComponent <Scale>(entity)) { entityManager.AddComponentData <Scale>(entity, new Scale { Value = 1f }); } else { entityManager.SetComponentData <Scale>(entity, new Scale { Value = 1f }); } switch (name) { case "ThunderBolt": Debug.Log("Spawning ThunderBolt"); //set name and render mesg entityManager.SetName(entity, name); //entityManager.SetSharedComponentData(entity, renderMesh); PokemonDataClass.SetRenderMesh(entityManager, entity, pokemonName, 1); break; case "Tackle": entityManager.SetName(entity, name); break; default: Debug.Log("Failed to set pokemon move data for \"" + name + "\""); break; } // PhysicsCollider op = entityManager.GetComponentData <PhysicsCollider>(orgEntity); op = entityManager.GetComponentData <PhysicsCollider>(orgEntity); PhysicsCollider tmpA = entityManager.GetComponentData <PhysicsCollider>(entity); // Debug.Log("Chaned original entities collision filter to " + op.Value.Value.Filter.GroupIndex.ToString() + " with entity index = " + tmpA.Value.Value.Filter.GroupIndex.ToString()); } else { //maybe cancel but for now we do nothing } }
protected override void OnCreate() { GravityQuery = GetEntityQuery(typeof(PhysicsStep)); inputDefinitionsClass = new InputDefinitionsClass(); groupIndexSystem = World.GetOrCreateSystem <GroupIndexSystem>(); }