public void Execute() { for (i = 0; i < pokemonMoveDatas.Length; i++) { if (!pokemonMoveDatas[i].isValid) { //we have a valid pokemon move data if (parents[i].isValid) { //remove EntityChild from parent ecb.RemoveComponent <EntityChild>(parents[i].entity); //lets remove the PokemonMoveDataEntity Component so it no longer fires the PokemonMoveDataEntity Job ecb.RemoveComponent <PokemonMoveDataEntity>(parents[i].entity); // ecb.RemoveComponent<EntityChild>(parents[i].entity); <-outdated (EntityChild was removed) GroupIndexInfo gii = parentInfos[i]; gii.Revert = true; gii.Update = true; ecb.SetComponent(parents[i].entity, gii); } //remove the EntityParent Component so the Entity no longer follows the Pokemon Entity ecb.RemoveComponent <EntityParent>(pokemonMoveDataEntities[i]); //if the Pokemon Move has particles then request to get them removed if (pokemonMoveDatas[i].hasParticles) { ecb.AddComponent(pokemonMoveDataEntities[i], new ParticleSystemRemoveRequest { }); } //add the pokemon remove request ecb.AddComponent(pokemonMoveDataEntities[i], new PokemonMoveEntityRemoveRequest { }); } } for (i = 0; i < pokemonMoveEntityEntities.Length; i++) { //destroy entities that match these conditions if (!pokemonMoveRemoveDatas[i].hasParticles) { ecb.DestroyEntity(pokemonMoveEntityEntities[i]); } else if (!hasParticleRemoveRequest.Exists(pokemonMoveEntityEntities[i])) { ecb.DestroyEntity(pokemonMoveEntityEntities[i]); } } }
/// <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 } }