示例#1
0
        /// <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
            }
        }
            /// <summary>
            /// filters out the active (in use) ParticleSystems
            /// </summary>
            protected override JobHandle OnUpdate(JobHandle inputDeps)
            {
                i = particleSystemRequestQuery.CalculateEntityCount();
                if (i == 0 && particleSystemRemoveRequestQuery.CalculateEntityCount() == 0)
                {
                    return(inputDeps);
                }
                NativeArray <Entity> particleSystemEntityEntities = particleSystemEntityQuery.ToEntityArray(Allocator.TempJob);
                NativeArray <ParticleSystemEntity> pses           = particleSystemEntityQuery.ToComponentDataArray <ParticleSystemEntity>(Allocator.TempJob);

                //test if any one needs new particles
                if (i > 0)
                {
                    if (haveParticlePrefab)
                    {
                        NativeArray <Entity> particleSystemRequestEntities = particleSystemRequestQuery.ToEntityArray(Allocator.TempJob);
                        j = getActiveParticleSystems(pses);
                        requiresNewParticleSystems = j + particleSystemRequestEntities.Length > particleSystemEntityEntities.Length;
                        Debug.Log("detected " + j + " active particleSystems. current max: " + particleSystemEntityEntities.Length + " current requested: " + particleSystemRequestEntities.Length + " require new spawns = " + requiresNewParticleSystems);
                        //test to see if we need to make new particle systems
                        if (requiresNewParticleSystems)
                        {
                            //			Debug.Log("Detected a request in new entities!");
                            for (i = 0; i < j + particleSystemRequestEntities.Length - particleSystemEntityEntities.Length; i++)
                            {
                                createParticleSystemGameObject("ParticleSystem" + (i + particleSystemEntityEntities.Length), new float3(), new float4());
                            }
                            particleSystemEntityEntities.Dispose();
                            pses.Dispose();
                            particleSystemEntityEntities = particleSystemEntityQuery.ToEntityArray(Allocator.TempJob);
                            pses = particleSystemEntityQuery.ToComponentDataArray <ParticleSystemEntity>(Allocator.TempJob);
                        }
                        Debug.Log("Filling in Requests...");
                        //now we fill the requests
                        for (i = 0; i < particleSystemRequestEntities.Length; i++)
                        {
                            for (j = 0; j < pses.Length; j++)
                            {
                                if (!pses[j].isActive)
                                {
                                    pses[j] = new ParticleSystemEntity
                                    {
                                        id       = pses[j].id,
                                        isActive = true
                                    };
                                    Debug.Log("setting particle system " + pses[j].id + " to a entity");
                                    //assumes the eneity already has the ParticleSystemData
                                    EntityManager.RemoveComponent <ParticleSystemRequest>(particleSystemRequestEntities[i]);
                                    ParticleSystem ps = EntityManager.GetComponentObject <ParticleSystem>(particleSystemEntityEntities[j]) as ParticleSystem;
                                    if (ps == null)
                                    {
                                        Debug.LogError("FAILED TO GET PARTICLE SYSTEM");
                                    }
                                    //			else Debug.Log("particle position = "+ps.transform.position);
                                    if (EntityManager.HasComponent <ParticleSystemSpawnData>(particleSystemRequestEntities[i]))
                                    {
                                        ParticleSystemSpawnData pssd = EntityManager.GetComponentData <ParticleSystemSpawnData>(particleSystemRequestEntities[i]);
                                        if (pssd.paticleSystemName.A != 0)
                                        {
                                            GameObject temp = Resources.Load("Pokemon/PokemonMoves/" + (pssd.paticleSystemName) + "/" + (pssd.paticleSystemName) + "ParticleSystem") as GameObject;
                                            if (temp != null)
                                            {
                                                ps = temp.GetComponent <ParticleSystem>();
                                            }
                                            else
                                            {
                                                Debug.LogWarning("Failed to load ParticleSystem Preset: invalid ParticleSystem, got \"Pokemon/PokemonMoves/" + (pssd.paticleSystemName) + "ParticleSystem\"");
                                            }
                                        }
                                        else
                                        {
                                            Debug.LogWarning("Failed to load ParticleSystem Preset: invalid Name");
                                        }
                                        if (pssd.particleSystemSpawnDataShape.isValid)
                                        {
                                            var shape = ps.shape;
                                            shape.position = pssd.particleSystemSpawnDataShape.offsetPostiion;
                                            shape.rotation = pssd.particleSystemSpawnDataShape.offsetRotation;
                                            shape.scale    = pssd.particleSystemSpawnDataShape.offsetScale;
                                        }
                                    }
                                    else
                                    {
                                        Debug.LogWarning("No ParticleSystemDataSpawnData found, setting some defaults." + EntityManager.GetName(particleSystemRequestEntities[i]));
                                        var shape = ps.shape;
                                        shape.position = new float3();
                                        shape.rotation = new float3();
                                        shape.scale    = new float3(1f, 1f, 1f);
                                    }
                                    ps.Play();
                                    EntityManager.AddComponentObject(particleSystemRequestEntities[i], ps);
                                    EntityManager.SetComponentData(particleSystemRequestEntities[i],
                                                                   new ParticleSystemData
                                    {
                                        isFinished           = false,
                                        particleSystemEntity = pses[j]
                                    }
                                                                   );

                                    EntityManager.SetComponentData <ParticleSystemEntity>(particleSystemEntityEntities[j], pses[j]);
                                    break;
                                }
                            }
                        }
                        particleSystemRequestEntities.Dispose();
                    }
                    else
                    {
                        Debug.LogError("Cannot create new prefabs becuase we failed to laod thr original");
                    }
                }
                //test for any removal request
                if (particleSystemRemoveRequestQuery.CalculateEntityCount() > 0)
                {
                    //				Debug.Log("Detected "+ particleSystemRemoveRequestQuery.CalculateEntityCount()+" remove requests");
                    //now we test if there are any particlesystems that are finished being used
                    NativeArray <Entity> psds = particleSystemRemoveRequestQuery.ToEntityArray(Allocator.TempJob);
                    for (i = 0; i < psds.Length; i++)
                    {
                        ParticleSystemData psd = EntityManager.GetComponentData <ParticleSystemData>(psds[i]);
                        for (j = 0; j < pses.Length; j++)
                        {
                            //				Debug.Log("testing "+pses[j].id +" with "+ psd.particleSystemEntity.id);
                            if (pses[j].id == psd.particleSystemEntity.id)
                            {
                                //					Debug.Log("Preforming remove request on id " + pses[j].id);
                                EntityManager.SetComponentData(psds[i], new ParticleSystemData {
                                });
                                EntityManager.RemoveComponent <ParticleSystemRemoveRequest>(psds[i]);
                                EntityManager.SetComponentData(particleSystemEntityEntities[j], new ParticleSystemEntity
                                {
                                    id       = pses[j].id,
                                    isActive = false
                                });
                                break;
                            }
                        }
                    }
                    psds.Dispose();
                }
                pses.Dispose();
                particleSystemEntityEntities.Dispose();
                return(inputDeps);
            }