Ejemplo n.º 1
0
        public void BindEntity(EntityManager entityManager, Entity entity)
        {
            em  = entityManager;
            ent = entity;

            var components = gameObject.GetComponents <Component>();

            for (var i = 0; i != components.Length; i++)
            {
                var com       = components[i];
                var behaviour = com as Behaviour;
                if (behaviour != null && !behaviour.enabled)
                {
                    continue;
                }

                if (!(com is EntityMonoBehaviour) && com != null)
                {
                    em.AddComponentObject(ent, com);
                }
            }
        }
        protected override void OnUpdate()
        {
            Entity myActorEntity     = default;
            var    myPlayerSingleton = GetSingleton <MyPlayerSingleton>();

            if (myPlayerSingleton.playerEntity != default)
            {
                myActorEntity = EntityManager.GetComponentData <PlayerActorArray>(myPlayerSingleton.playerEntity).mainActorEntity;
            }



            Entities
            .WithAllReadOnly <Ship, OnCreateMessage, Transform>()
            .WithNone <Battery>()
            .ForEach((Entity actorEntity, Transform actorTransform) =>
            {
                var ui_AttributePanelT = actorTransform
                                         .GetChild(ShipSpawner.UI_TransformIndex)
                                         .GetChild(ShipSpawner.__UI_AttributePanel_TransformIndex);

                ui_AttributePanelT.gameObject.SetActive(myActorEntity == actorEntity);

                if (myActorEntity == actorEntity)
                {
                    EntityManager.AddComponentObject(actorEntity, ui_AttributePanelT.GetComponent <ShipAttributePanel>());
                }
            });

            Entities
            .WithAllReadOnly <ShipAttributePanel, Ship, ActorAttribute3 <_HP>, ActorAttribute3 <_Power> >()
            .WithNone <OnDestroyMessage>()
            .ForEach((ShipAttributePanel actorAttributeUI, ref ActorAttribute3 <_HP> hp, ref ActorAttribute3 <_Power> power) =>
            {
                actorAttributeUI.setAttributes(hp, power);
            });
        }
        SlotAngleLimitLines getShipSlotList()
        {
            //
            var myPlayerSingleton = GetSingleton <MyPlayerSingleton>();
            var myPlayerEntity    = myPlayerSingleton.playerEntity;

            if (myPlayerEntity == Entity.Null)
            {
                return(null);
            }
            if (EntityManager.HasComponent <PlayerActorArray>(myPlayerEntity) == false)
            {
                return(null);
            }
            var actors = EntityManager.GetComponentData <PlayerActorArray>(myPlayerEntity);

            if (actors.shipEntity == Entity.Null)
            {
                return(null);
            }


            SlotAngleLimitLines shipSlotList;

            if (EntityManager.HasComponent <SlotAngleLimitLines>(actors.shipEntity) == false)
            {
                var shipT = EntityManager.GetComponentObject <Transform>(actors.shipEntity);
                shipSlotList = shipT.gameObject.AddComponent <SlotAngleLimitLines>();
                EntityManager.AddComponentObject(actors.shipEntity, shipSlotList);
            }
            else
            {
                shipSlotList = EntityManager.GetComponentObject <SlotAngleLimitLines>(actors.shipEntity);
            }

            return(shipSlotList);
        }
    private void CreateNewGameObjects(SimAssetBank.Lookup simAssetBank)
    {
        Entities
        .WithAll <BindedViewType_GameObject>()
        .WithNone <BindedGameObjectTag>()
        .WithoutBurst()
        .WithStructuralChanges()
        .ForEach((Entity viewEntity, in SimAssetId id, in BindedSimEntity simEntity) =>
        {
            EntityManager.AddComponent <BindedGameObjectTag>(viewEntity);

            SimAsset simAsset = simAssetBank.GetSimAsset(id);

            if (simAsset.BindedViewPrefab != null)
            {
                GameObject viewGO = Object.Instantiate(simAsset.BindedViewPrefab);

                var bindedSimEntityManaged = viewGO.GetOrAddComponent <BindedSimEntityManaged>();
                bindedSimEntityManaged.Register(simEntity);

                EntityManager.AddComponentObject(viewEntity, bindedSimEntityManaged);
                EntityManager.AddComponentObject(viewEntity, viewGO.transform);
            }
        }).Run();
Ejemplo n.º 5
0
                protected override JobHandle OnUpdate(JobHandle inputDeps)
                {
                    i = VFXGParticleRequestQuery.CalculateEntityCount();
                    if (i == 0 && VFXGParticleRemoveRequestQuery.CalculateEntityCount() == 0)
                    {
                        return(inputDeps);
                    }
                    //get the current particle system entities/gameobject
                    NativeArray <Entity>             VFXGParticleEntities = VFXGParticleEntityQuery.ToEntityArray(Allocator.TempJob);
                    NativeArray <VFXGParticleEntity> particleEntities     = VFXGParticleEntityQuery.ToComponentDataArray <VFXGParticleEntity>(Allocator.TempJob);

                    //test for new particle requests
                    if (i > 0)
                    {
                        NativeArray <Entity> requestEntities = VFXGParticleRequestQuery.ToEntityArray(Allocator.TempJob);
                        //get the currently active/used VFXGParticles
                        j = GetActiveVFXGParticleCount(particleEntities);
                        //test if the request exceed the current amount of VFXG Particles
                        bool requireNewParticles = j + requestEntities.Length > VFXGParticleEntities.Length;
                        Debug.Log("detected " + j + " active VFXG Particles. current max: " + VFXGParticleEntities.Length + " current requested: " + requestEntities.Length + " require new spawns = " + requireNewParticles);
                        if (requireNewParticles)
                        {
                            //create needed amount of particles
                            for (i = 0; i < j + requestEntities.Length - VFXGParticleEntities.Length; i++)
                            {
                                CreateVFXGParticle("VFXGParticle" + (i + VFXGParticleEntities.Length), new float3(), new quaternion());
                            }
                            //"refresh" the current VFXG Particles
                            VFXGParticleEntities.Dispose();
                            VFXGParticleEntities = VFXGParticleEntityQuery.ToEntityArray(Allocator.TempJob);
                            particleEntities.Dispose();
                            particleEntities = VFXGParticleEntityQuery.ToComponentDataArray <VFXGParticleEntity>(Allocator.TempJob);
                        }
                        Debug.Log("VFXG: Filling in requests");
                        //now we fill in the requests
                        for (i = 0; i < requestEntities.Length; i++)
                        {
                            for (j = 0; j < particleEntities.Length; j++)
                            {
                                if (!particleEntities[j].isActive)
                                {
                                    particleEntities[j] = new VFXGParticleEntity
                                    {
                                        isActive = true,
                                        id       = particleEntities[j].id
                                    };
                                    Debug.Log("setting particle system " + particleEntities[j].id + " to a entity");
                                    //remove the request
                                    EntityManager.RemoveComponent <VFXGParticleRequest>(requestEntities[j]);
                                    VisualEffect vf = EntityManager.GetComponentObject <VisualEffect>(VFXGParticleEntities[j]) as VisualEffect;
                                    //assume the gameobject has a Visual Effect
                                    if (EntityManager.HasComponent <VFXGParticleSystemData>(requestEntities[i]))
                                    {
                                        //load the particleSystem
                                        VFXGParticleSystemData vfxgData = EntityManager.GetComponentData <VFXGParticleSystemData>(requestEntities[i]);
                                        if (vfxgData.Name.A != 0)
                                        {
                                            GameObject temp = Resources.Load("Core/ParticleSystem/VFXGParticles/" + (vfxgData.Name) + "/" + (vfxgData.Name)) as GameObject;
                                            if (temp != null)
                                            {
                                                vf = temp.GetComponent <VisualEffect>();
                                            }
                                            else
                                            {
                                                Debug.LogError("Failed to get GamObject for particle");
                                            }
                                            vf.Play();
                                            EntityManager.AddComponentObject(requestEntities[i], vf);
                                            //EntityManager.SetComponentData(requestEntities[i],new ParticleSystemData{ });
                                            EntityManager.SetComponentData(VFXGParticleEntities[j], particleEntities[j]);
                                        }
                                        else
                                        {
                                            Debug.LogError("Cannot found VFXG Particle with the name " + (vfxgData.Name));
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        //Clean Up
                        requestEntities.Dispose();
                    }
                    if (VFXGParticleRemoveRequestQuery.CalculateEntityCount() > 0)
                    {
                        Debug.Log("Detected Remove request");
                        NativeArray <Entity> removeEntities = VFXGParticleRemoveRequestQuery.ToEntityArray(Allocator.TempJob);
                        for (i = 0; i < removeEntities.Length; i++)
                        {
                            VFXGParticleEntity psd = EntityManager.GetComponentData <VFXGParticleEntity>(removeEntities[i]);
                            for (j = 0; j < VFXGParticleEntities.Length; j++)
                            {
                                if (particleEntities[j].id == psd.id)
                                {
                                    EntityManager.SetComponentData(removeEntities[i], new VFXGParticleEntity {
                                    });
                                }
                                EntityManager.RemoveComponent <VFXGParticleRemoveRequest>(removeEntities[i]);
                                EntityManager.SetComponentData(VFXGParticleEntities[j], new VFXGParticleEntity {
                                    id       = particleEntities[j].id,
                                    isActive = false
                                });
                            }
                        }
                        removeEntities.Dispose();
                    }
                    particleEntities.Dispose();
                    VFXGParticleEntities.Dispose();
                    return(inputDeps);
                }
        void ApplyLiveLink(SubScene scene)
        {
            //Debug.Log("ApplyLiveLink: " + scene.SceneName);

            var streamingSystem = World.GetExistingManager <SubSceneStreamingSystem>();

            var isFirstTime = scene.LiveLinkShadowWorld == null;

            if (scene.LiveLinkShadowWorld == null)
            {
                scene.LiveLinkShadowWorld = new World("LiveLink");
            }


            using (var cleanConvertedEntityWorld = new World("Clean Entity Conversion World"))
            {
                // Unload scene
                //@TODO: We optimally shouldn't be unloading the scene here. We should simply prime the shadow world with the scene that we originally loaded into the player (Including Entity GUIDs)
                //       This way we can continue the live link, compared to exactly what we loaded into the player.
                if (isFirstTime)
                {
                    foreach (var s in scene._SceneEntities)
                    {
                        streamingSystem.UnloadSceneImmediate(s);
                        EntityManager.DestroyEntity(s);
                    }

                    var sceneEntity = EntityManager.CreateEntity();
                    EntityManager.SetName(sceneEntity, "Scene (LiveLink): " + scene.SceneName);
                    EntityManager.AddComponentObject(sceneEntity, scene);
                    EntityManager.AddComponentData(sceneEntity, new SubSceneStreamingSystem.StreamingState {
                        Status = SubSceneStreamingSystem.StreamingStatus.Loaded
                    });
                    EntityManager.AddComponentData(sceneEntity, new SubSceneStreamingSystem.IgnoreTag( ));

                    scene._SceneEntities = new List <Entity>();
                    scene._SceneEntities.Add(sceneEntity);
                }

                // Convert scene
                GameObjectConversionUtility.ConvertScene(scene.LoadedScene, scene.SceneGUID, cleanConvertedEntityWorld, GameObjectConversionUtility.ConversionFlags.AddEntityGUID | GameObjectConversionUtility.ConversionFlags.AssignName);

                var convertedEntityManager = cleanConvertedEntityWorld.GetOrCreateManager <EntityManager>();

                var liveLinkSceneEntity = scene._SceneEntities[0];

                /// We want to let the live linked scene be able to reference the already existing Scene Entity (Specifically SceneTag should point to the scene Entity after live link completes)
                // Add Scene tag to all entities using the convertedSceneEntity that will map to the already existing scene entity.
                convertedEntityManager.AddSharedComponentData(convertedEntityManager.UniversalGroup, new SceneTag {
                    SceneEntity = liveLinkSceneEntity
                });

                WorldDiffer.DiffAndApply(cleanConvertedEntityWorld, scene.LiveLinkShadowWorld, World);

                convertedEntityManager.Debug.CheckInternalConsistency();
                scene.LiveLinkShadowWorld.GetOrCreateManager <EntityManager>().Debug.CheckInternalConsistency();

                var group = EntityManager.CreateComponentGroup(typeof(SceneTag), ComponentType.Exclude <EditorRenderData>());
                group.SetFilter(new SceneTag {
                    SceneEntity = liveLinkSceneEntity
                });

                EntityManager.AddSharedComponentData(group, new EditorRenderData()
                {
                    SceneCullingMask = m_LiveLinkEditGameViewMask, PickableObject = scene.gameObject
                });

                group.Dispose();

                scene.LiveLinkDirtyID = GetSceneDirtyID(scene.LoadedScene);
                EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
            }
        }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, GetComponent <CharacterController>());
 }
Ejemplo n.º 8
0
 public override void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, transform);
     Serialized.RotationOffset = quaternion.Euler(EulerOffset);
     base.Convert(entity, dstManager, conversionSystem);
 }
Ejemplo n.º 9
0
 void IConvertGameObjectToEntity.Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, WorldGrid);
     dstManager.AddComponentObject(entity, WorldTilemap);
 }
Ejemplo n.º 10
0
 void ISimWorldWriteAccessor.AddComponentObject(Entity entity, object componentData)
 => EntityManager.AddComponentObject(entity, componentData);
Ejemplo n.º 11
0
        public GameObject CreateDefaultGhostGameObject(Entity ent,
                                                       CreatedGameObjectDelegate onCreatedGameObject = null,
                                                       CreatedGameObjectDelegate onCreatedLinkTarget = null)
        {
            var ghost = EntityManager.GetComponentData <GhostComponent>(ent);

            bool isInterpolatedClient = !EntityManager.HasComponent <GhostPredictionComponent>(ent);
            bool isLocalOwner         = false;

            GameObject view;

            if (IsServer)
            {
                view = this.GetByServer(ghost.GhostType);
            }
            else
            {
                // 客户端频断是否是LocalOwner
                if (HasSingleton <NetworkIdComponent>() && EntityManager.HasComponent <GhostOwnerComponent>(ent))
                {
                    NetworkIdComponent  networkIdComponent = GetSingleton <NetworkIdComponent>();
                    GhostOwnerComponent ownerComponent     =
                        EntityManager.GetComponentData <GhostOwnerComponent>(ent);

                    // [客户端特有]
                    isLocalOwner = ownerComponent.Value == networkIdComponent.Value;
                }

                // 预制体集合取
                view = isInterpolatedClient
                    ? this.GetByInterpolated(ghost.GhostType)
                    : this.GetByPrediction(ghost.GhostType);
            }

            view = Object.Instantiate(view);

            // Entity标识,以便碰撞检测能找到对应的Entity
            var entityFlag = view.AddComponent <EntityHold>();

            entityFlag.Ent   = ent;
            entityFlag.World = World;

            SceneManager.MoveGameObjectToScene(view, World.GetLinkedScene());
            EntityManager.AddComponentData(ent, new GhostGameObjectSystemState());
            this.Add(ent, view);
            onCreatedGameObject?.Invoke(ghost.GhostType, view, this);

            var linkedGameObject = CreateLinkedGameObject(isInterpolatedClient, IsServer, view);

            if (linkedGameObject)
            {
                onCreatedLinkTarget?.Invoke(ghost.GhostType, linkedGameObject, this);
            }

            // 只能由一个此NetworkBehaviour
            NetworkBehaviour networkBehaviours = view.GetComponent <NetworkBehaviour>();

            if (networkBehaviours)
            {
                networkBehaviours.World      = World;
                networkBehaviours.SelfEntity = ent;
                networkBehaviours.IsServer   = IsServer;
                networkBehaviours.IsOwner    = isLocalOwner;
                EntityManager.AddComponentObject(ent, networkBehaviours);
                networkBehaviours.NetworkAwake();
            }

            return(view);
        }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, GetComponent <AnimationPlayer>());
     dstManager.AddComponent(entity, ComponentType.ReadOnly <CopyTransformToGameObject>());
 }
Ejemplo n.º 13
0
    protected override unsafe void OnUpdate()
    {
        if (!mFITLoaded)
        {
            MemoryMap map;
            {
                var tmp = mMemoryMapQuery.ToComponentDataArray <MemoryMap>(Allocator.TempJob);
                map = tmp[0];
                tmp.Dispose();
            }
            mFITLoaded = true;
            LoadFITLayer(map);
        }

        if (mState == State.Preparing)
        {
            UnityEngine.Profiling.Profiler.BeginSample("Preparing for job creation");
            mStartStreamTime = Time.realtimeSinceStartup;
            var ids      = mStreamingRequestQuery.ToEntityArray(Allocator.TempJob);
            var requests = mStreamingRequestQuery.ToComponentDataArray <StreamedInVoxel>(Allocator.TempJob);
            PostUpdateCommands.RemoveComponent(mStreamingRequestQuery, typeof(GFXRequest));


            for (int i = mOpaqueMeshes.Count; i < requests.Length; i++)
            {
                mOpaqueMeshes.Add(new SoAMesh(1, 1));
                mTransparentMeshes.Add(new SoAMesh(1, 1));
                mOpaqueGCHandles.Add(new MeshGCHandles());
                mTransparentGCHandles.Add(new MeshGCHandles());
            }

            mOpaqueResVerticesCountBuff.ResizeUninitialized(requests.Length);
            mOpaqueResIndicesCountBuff.ResizeUninitialized(requests.Length);
            mTransparentResVerticesCountBuff.ResizeUninitialized(requests.Length);
            mTransparentResIndicesCountBuff.ResizeUninitialized(requests.Length);

            mVerticesJobs.Clear();
            mVerticesJobsHandles.Clear();
            mCorrespondingEntities.Clear();

            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("Creating Jobs");
            MemoryMap map;
            {
                var tmp = mMemoryMapQuery.ToComponentDataArray <MemoryMap>(Allocator.TempJob);
                map = tmp[0];
                tmp.Dispose();
            }

            mBeginSSDLoadTime = Time.realtimeSinceStartup;
            int buffIdx = 0;
            for (int i = 0; i < requests.Length; i++)
            {
                if (CreateVoxelLoadingJob(requests[i].Value.Layer, requests[i].Value.Index, buffIdx, map, out LoadVerticesJob job))
                {
                    mVerticesJobs.Add(job);
                    mVerticesJobsHandles.Add(mVerticesJobs[mVerticesJobs.Length - 1].Schedule());
                    mCorrespondingEntities.Add(ids[i]);
                    buffIdx++;
                }
            }
            mCombinedVerticesJobHandle = JobHandle.CombineDependencies(mVerticesJobsHandles.AsArray());

            if (mVerticesJobs.Length > 0)
            {
                mState = State.LoadingVertices;
                World.Active.GetExistingSystem <VoxelStreamRequesterSystem>().NotifyBusy();
            }

            requests.Dispose();
            ids.Dispose();

            UnityEngine.Profiling.Profiler.EndSample();
        }
        else if (mState == State.LoadingVertices && mCombinedVerticesJobHandle.IsCompleted)
        {
            mBytesLoaded = 0;

            UnityEngine.Profiling.Profiler.BeginSample("Complete Jobs");
            mCombinedVerticesJobHandle.Complete();

            for (int i = 0; i < mVerticesJobs.Length; i++)
            {
                var job = mVerticesJobs[i];
                mOpaqueMeshes[job.BuffIdx].SetVertexCount(job.OpaqueResVerticesCount[job.BuffIdx]);
                mOpaqueMeshes[job.BuffIdx].SetIndexCount(job.OpaqueResIndicesCount[job.BuffIdx]);
                mBytesLoaded += (job.TransparentResVerticesCount[job.BuffIdx] + job.OpaqueResVerticesCount[job.BuffIdx]) * (sizeof(Vector3) + sizeof(Vector3) + sizeof(Color32));

                mTransparentMeshes[job.BuffIdx].SetVertexCount(job.TransparentResVerticesCount[job.BuffIdx]);
                mTransparentMeshes[job.BuffIdx].SetIndexCount(job.TransparentResIndicesCount[job.BuffIdx]);
                mBytesLoaded += (job.TransparentResIndicesCount[job.BuffIdx] + job.OpaqueResIndicesCount[job.BuffIdx]) * sizeof(int);

                mTransparentGCHandles[job.BuffIdx].Dispose();
                mOpaqueGCHandles[job.BuffIdx].Dispose();
            }

            Debug.Log($"{mBytesLoaded / Math.Pow(10, 6)} MB, loaded from disk: {(Time.realtimeSinceStartup - mBeginSSDLoadTime) * 1000.0}ms");

            mState            = State.InstantiatingMeshes;
            mInstantiateCount = 0;
            UnityEngine.Profiling.Profiler.EndSample();
        }
        else if (mState == State.InstantiatingMeshes)
        {
            UnityEngine.Profiling.Profiler.BeginSample("Instantiate Mesh");
            var job   = mVerticesJobs[mInstantiateCount];
            var owner = mCorrespondingEntities[mInstantiateCount];

            var gfxMeshes = PostUpdateCommands.AddBuffer <GFXMeshes>(owner);

            // One for transparent, one for opaque
            gfxMeshes.Reserve(2);

            UnityEngine.Profiling.Profiler.BeginSample("Create Go");
            if (job.OpaqueResVerticesCount[job.BuffIdx] != 0)
            {
                var go = CreateGameObject($"Layer {job.Layer}, idx {job.Index}, Opaque",
                                          mOpaqueMeshes[job.BuffIdx],
                                          Globals.Instance.data.OpaqueMaterial);

                var e = EntityManager.CreateEntity();
                EntityManager.AddComponentObject(e, go);
                PostUpdateCommands.AddComponent(e, new Unity.Transforms.Frozen());
                gfxMeshes.Add(new GFXMeshes {
                    Value = e
                });
            }
            if (job.TransparentResVerticesCount[job.BuffIdx] != 0)
            {
                var go = CreateGameObject($"Layer {job.Layer}, idx {job.Index}, Transparent",
                                          mTransparentMeshes[job.BuffIdx],
                                          Globals.Instance.data.TransparentMaterial);

                var e = EntityManager.CreateEntity();
                EntityManager.AddComponentObject(e, go);
                PostUpdateCommands.AddComponent(e, new Unity.Transforms.Frozen());
                gfxMeshes.Add(new GFXMeshes {
                    Value = e
                });
            }
            UnityEngine.Profiling.Profiler.EndSample();

            if (++mInstantiateCount >= mVerticesJobs.Length)
            {
                Debug.Log($"{mBytesLoaded / Math.Pow(10, 6)} MB, loaded and instantiated in: {(Time.realtimeSinceStartup - mStartStreamTime) * 1000.0}ms");
                mState = State.Preparing;
                World.Active.GetExistingSystem <VoxelStreamRequesterSystem>().NotifyReady();
            }
            UnityEngine.Profiling.Profiler.EndSample();
        }
    }
            /// <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);
            }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, new DummyManagedClassComponent {
         DummyValue = DummyValue
     });
 }
Ejemplo n.º 16
0
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, transform);
 }
Ejemplo n.º 17
0
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, this);
     dstManager.AddComponentData(entity, new PlayerSize());
 }
Ejemplo n.º 18
0
        public void UpdateSceneEntities(bool warnIfMissing = false)
        {
#if UNITY_EDITOR
            var sceneHeaderPath = EntityScenesPaths.GetLoadPath(SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1);
            m_SubSceneHeader = AssetDatabase.LoadAssetAtPath <SubSceneHeader>(sceneHeaderPath);
#endif
            if (warnIfMissing && m_SubSceneHeader == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning($"Sub-scene '{EditableScenePath}' has no valid header at '{sceneHeaderPath}'. Please rebuild the Entity Cache.", this);
#else
                Debug.LogWarning($"Sub-scene '{name}' has no valid header. Please rebuild the Entity Cache.", this);
#endif
            }


            if (_SceneEntityManager != null && _SceneEntityManager.IsCreated)
            {
                foreach (var sceneEntity in _SceneEntities)
                {
                    _SceneEntityManager.DestroyEntity(sceneEntity);
                }
            }
            _SceneEntities.Clear();
            _SceneEntityManager = null;

            DefaultWorldInitialization.DefaultLazyEditModeInitialize();
            if (World.Active != null)
            {
                _SceneEntityManager = World.Active.EntityManager;

                if (m_SubSceneHeader != null)
                {
                    for (int i = 0; i < m_SubSceneHeader.Sections.Length; ++i)
                    {
                        var sceneEntity = _SceneEntityManager.CreateEntity();
                        #if UNITY_EDITOR
                        _SceneEntityManager.SetName(sceneEntity, i == 0 ? $"Scene: {SceneName}" : $"Scene: {SceneName} ({i})");
                        #endif

                        _SceneEntities.Add(sceneEntity);
                        _SceneEntityManager.AddComponentObject(sceneEntity, this);

                        if (AutoLoadScene)
                        {
                            _SceneEntityManager.AddComponentData(sceneEntity, new RequestSceneLoaded());
                        }

                        _SceneEntityManager.AddComponentData(sceneEntity, m_SubSceneHeader.Sections[i]);
                        _SceneEntityManager.AddComponentData(sceneEntity, new SceneBoundingVolume {
                            Value = m_SubSceneHeader.Sections[i].BoundingVolume
                        });
                    }
                }
                else
                {
                    var sceneEntity = _SceneEntityManager.CreateEntity();
                    #if UNITY_EDITOR
                    _SceneEntityManager.SetName(sceneEntity, "Scene: {SceneName}");
                    #endif

                    _SceneEntities.Add(sceneEntity);
                    _SceneEntityManager.AddComponentObject(sceneEntity, this);
                }
            }
        }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, transform);
     dstManager.AddComponentObject(entity, GetComponent <FlyingCameraController>());
 }
Ejemplo n.º 20
0
        protected override void OnUpdate()
        {
            Entities
            .WithAllReadOnly <OnWeaponInstallMessage, Weapon, WeaponInstalledState, Transform>()
            .ForEach((Entity weaponEntity, Transform weaponT, ref WeaponInstalledState weaponInstalledState, ref Weapon weapon) =>
            {
                //把weapon约束到slot上
                var shipT = EntityManager.GetComponentObject <Transform>(weaponInstalledState.shipEntity);

                var slotsT = weapon.type == WeaponType.Attack ? shipT.GetChild(ShipSpawner.Slots_TransformIndex) : shipT.GetChild(ShipSpawner.AssistSlots_TransformIndex);

                var slotT = slotsT.GetChild(weaponInstalledState.slot.index);

                var dampedTransform = weaponT.gameObject.GetComponent <_DampedTransform>();
                if (dampedTransform == null)
                {
                    dampedTransform = weaponT.gameObject.AddComponent <_DampedTransform>();
                }

                dampedTransform.shipT  = shipT;
                dampedTransform.target = slotT;
                EntityManager.AddComponentObject(weaponEntity, dampedTransform);


                //
                var maskT = weaponT.GetChild(WeaponSpawner.Mask_TransformIndex);
                maskT.gameObject.SetActive(false);
            });

            Entities
            .WithAllReadOnly <OnWeaponUninstallMessage, WeaponInstalledState, Weapon, Transform>()
            .WithAll <TransformSmooth_In>()
            .ForEach((Entity weaponEntity, Transform weaponT, ref WeaponInstalledState weaponInstalledState, ref Weapon weapon, ref TransformSmooth_In transformSmooth_In) =>
            {
                //解除weapon的约束
                var dampedTransform    = weaponT.gameObject.GetComponent <_DampedTransform>();
                dampedTransform.shipT  = null;
                dampedTransform.target = null;

                EntityManager.RemoveComponent <_DampedTransform>(weaponEntity);
                transformSmooth_In.smoothTime = ActorSpawnerSpaceWar.smoothTime;


                //把weapon base 绑回weaponT上
                if (weapon.type == WeaponType.Attack)
                {
                    var shipT = EntityManager.GetComponentObject <Transform>(weaponInstalledState.shipEntity);

                    var slotT = shipT.GetChild(ShipSpawner.Slots_TransformIndex).GetChild(weaponInstalledState.slot.index);

                    var weaponBaseT = dampedTransform.weaponBaseT;
                    if (weaponBaseT != null)
                    {
                        dampedTransform.weaponBaseT = null;

                        weaponBaseT.SetParent(weaponT, false);
                        weaponBaseT.SetSiblingIndex(WeaponSpawner.BaseModel_TransformIndex);
                    }
                }


                //
                var maskT = weaponT.GetChild(WeaponSpawner.Mask_TransformIndex);
                maskT.gameObject.SetActive(true);
            });
        }
Ejemplo n.º 21
0
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     dstManager.AddComponentObject(entity, GetComponent <PlayerInput>());
 }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     //Track Camera movement via Object Field (Camera is still GameObject not ECS)
     dstManager.AddComponentObject(entity, transform);
 }