protected override JobHandle OnUpdate(JobHandle inputDeps) { int curEntityCnt = m_mobQuery.CalculateEntityCount(); if (na_rayCommands.Length != curEntityCnt) { mobMovementJH.Complete(); na_rayCommands.Dispose(); na_rayCommands = new NativeArray <RaycastCommand>(curEntityCnt, Allocator.Persistent); na_rayHits.Dispose(); na_rayHits = new NativeArray <RaycastHit>(curEntityCnt, Allocator.Persistent); } var setupRaycastJob = new SetupRaycastJob { layerMask = 1 << LayerMask.NameToLayer("Wall"), rayCommands = na_rayCommands, wallPos = GameManager.instance.Target.transform.position }; var setupJH = setupRaycastJob.Schedule(this, inputDeps); var raycastJH = RaycastCommand.ScheduleBatch(na_rayCommands, na_rayHits, 100, setupJH); var mobMovementJob = new MobMovementJob { deltaTime = Time.deltaTime, hits = na_rayHits }; mobMovementJH = mobMovementJob.Schedule(this, raycastJH); mobMovementJH.Complete(); var entities = m_mobQuery.ToEntityArray(Allocator.TempJob); for (int i = 0; i < entities.Length; ++i) { if (EntityManager.GetComponentData <MobStateData>(entities[i]).Value == MobState.Throw) { Vector3 curPos = EntityManager.GetComponentData <Translation>(entities[i]).Value; SpearBehavior spear = PoolManager.instance.SpearPool.SpawnObject(curPos + SettingsManager.ThrowingPoint, Quaternion.Euler(SettingsManager.ThrowingRotation)) as SpearBehavior; spear.Throw(); EntityManager.SetComponentData(entities[i], new MobStateData { Value = MobState.FromTarget }); } } entities.Dispose(); return(mobMovementJH); }
protected override void OnUpdate() { int curEntityCnt = m_mobQuery.CalculateEntityCount(); if (na_rayCommands.Length != curEntityCnt) { mobMovementJH.Complete(); na_rayCommands.Dispose(); na_rayCommands = new NativeArray <RaycastInput>(curEntityCnt, Allocator.Persistent); na_rayHits.Dispose(); na_rayHits = new NativeArray <Unity.Physics.RaycastHit>(curEntityCnt, Allocator.Persistent); } /*var setupRaycastJob = new SetupRaycastJob * { * layerMask = 1 << LayerMask.NameToLayer("Wall"), * rayCommands = na_rayCommands, * wallPos = GameManager.instance.Target * };*/ //var setupJH = setupRaycastJob.Schedule(this, buildPhysicsWorldSystem.FinalJobHandle); //var raycastJH = ScheduleBatchRayCast(buildPhysicsWorldSystem.PhysicsWorld.CollisionWorld, na_rayCommands, na_rayHits, setupJH); var mobMovementJob = new MobMovementJob { deltaTime = Time.deltaTime, hits = na_rayHits }; //mobMovementJH = mobMovementJob.Schedule(this, raycastJH); mobMovementJH = mobMovementJob.Schedule(this); mobMovementJH.Complete(); var entities = m_mobQuery.ToEntityArray(Allocator.TempJob); for (int i = 0; i < entities.Length; ++i) { if (EntityManager.GetComponentData <MobStateData>(entities[i]).Value == MobState.Throw) { var spearEntity = PostUpdateCommands.Instantiate(ECSManager.Instance.SpearPrefab); Vector3 startPoint = EntityManager.GetComponentData <Translation>(entities[i]).Value + (float3)SettingsManager.ThrowingPoint; Quaternion initialRotation = Quaternion.Euler(SettingsManager.ThrowingRotation); Vector3 initialVelocity = initialRotation * Vector3.forward * 75.0f; PostUpdateCommands.SetComponent(spearEntity, new Translation { Value = startPoint }); PostUpdateCommands.SetComponent(spearEntity, new Rotation { Value = initialRotation }); PostUpdateCommands.SetComponent(spearEntity, new PhysicsVelocity { Linear = initialVelocity }); PostUpdateCommands.SetComponent(entities[i], new MobStateData { Value = MobState.FromTarget }); } } entities.Dispose(); }
private void Update() { if (!taa_mobs.isCreated || taa_mobs.length == 0 || nl_startPos.Length != taa_mobs.length || nl_targetPos.Length != taa_mobs.length || na_mobStates.Length != taa_mobs.length) { return; } #region ARRAY_SETUP if (!na_rayCommands.IsCreated || na_rayCommands.Length != taa_mobs.length) { movementJH.Complete(); if (na_rayCommands.IsCreated) { na_rayCommands.Dispose(); } if (na_rayHits.IsCreated) { na_rayHits.Dispose(); } na_rayCommands = new NativeArray <RaycastCommand>(taa_mobs.length, Allocator.Persistent); na_rayHits = new NativeArray <RaycastHit>(taa_mobs.length, Allocator.Persistent); } if (!na_spearRayCommands.IsCreated || na_spearRayCommands.Length != taa_spears.length) { spearMovementJH.Complete(); if (na_spearRayCommands.IsCreated) { na_spearRayCommands.Dispose(); } if (na_spearRayHits.IsCreated) { na_spearRayHits.Dispose(); } na_spearRayCommands = new NativeArray <RaycastCommand>(taa_spears.length, Allocator.Persistent); na_spearRayHits = new NativeArray <RaycastHit>(taa_spears.length, Allocator.Persistent); } #endregion var setupRaycastJob = new SetupRaycastJob { layerMask = 1 << LayerMask.NameToLayer("Wall"), rayCommands = na_rayCommands, targetPos = nl_targetPos, wallPos = GameManager.instance.Target.transform.position }; var setupJH = setupRaycastJob.Schedule(taa_mobs); var raycastJH = RaycastCommand.ScheduleBatch(na_rayCommands, na_rayHits, 100, setupJH); var mobMovementJob = new MobMovementJob { deltaTime = Time.deltaTime, hits = na_rayHits, mobStates = na_mobStates, startPos = nl_startPos, targetPos = nl_targetPos }; movementJH = mobMovementJob.Schedule(taa_mobs, raycastJH); var spearGravityJob = new SpearGravityJob { deltaTime = Time.deltaTime, Gravity = Physics.gravity, State = na_spearState, Velocities = na_spearVelocities }; var spearGravityJH = spearGravityJob.Schedule(taa_spears, movementJH); var spearRaycastSetup = new SpearRaycastSetupJob { deltaTime = Time.deltaTime, layer = 1 << LayerMask.NameToLayer("Wall"), Raycasts = na_spearRayCommands, Velocities = na_spearVelocities }; var spearRaySetupJH = spearRaycastSetup.Schedule(taa_spears, spearGravityJH); var spearRaycastBatchJH = RaycastCommand.ScheduleBatch(na_spearRayCommands, na_spearRayHits, 100, spearRaySetupJH); var spearCollisionResponse = new SpearCalculateResponse { Hits = na_spearRayHits, States = na_spearState, Velocities = na_spearVelocities }; var responseJH = spearCollisionResponse.Schedule(taa_spears.length, 100, spearRaycastBatchJH); var spearMovementJob = new SpearMovementJob { DeltaTime = Time.deltaTime, Hits = na_spearRayHits, State = na_spearState, Velocities = na_spearVelocities }; spearMovementJH = spearMovementJob.Schedule(taa_spears, responseJH); spearMovementJH.Complete(); for (int i = 0; i < na_mobStates.Length; ++i) { if (na_mobStates[i] == MobState.Throw) { SpearBehaviorExt spear = PoolManager.instance.SpearPool.SpawnObject(taa_mobs[i].position + SettingsManager.ThrowingPoint, Quaternion.Euler(SettingsManager.ThrowingRotation)) as SpearBehaviorExt; if (spear) { int spearIndex = PoolManager.instance.SpearPool.IndexOf(spear); na_spearState[spearIndex] = SpearState.Starting; taa_spears[spearIndex].position = taa_mobs[i].position + SettingsManager.ThrowingPoint; taa_spears[spearIndex].rotation = Quaternion.Euler(SettingsManager.ThrowingRotation); na_mobStates[i] = MobState.FromTarget; } } } for (int i = 0; i < na_spearState.Length; ++i) { if (na_spearState[i] == SpearState.Inactive) { var spear = PoolManager.Instance.SpearPool.GetAt(i); if (spear && spear.isActiveAndEnabled) { PoolManager.Instance.SpearPool.ReturnToPool(spear); } } } }
private void Update() { if (!taa_mobs.isCreated || taa_mobs.length == 0 || nl_startPos.Length != taa_mobs.length || nl_targetPos.Length != taa_mobs.length || na_mobStates.Length != taa_mobs.length) { return; } if (!na_rayCommands.IsCreated || na_rayCommands.Length != taa_mobs.length) { movementJH.Complete(); if (na_rayCommands.IsCreated) { na_rayCommands.Dispose(); } if (na_rayHits.IsCreated) { na_rayHits.Dispose(); } na_rayCommands = new NativeArray <RaycastCommand>(taa_mobs.length, Allocator.Persistent); na_rayHits = new NativeArray <RaycastHit>(taa_mobs.length, Allocator.Persistent); } var setupRaycastJob = new SetupRaycastJob { layerMask = 1 << LayerMask.NameToLayer("Wall"), rayCommands = na_rayCommands, targetPos = nl_targetPos, wallPos = GameManager.instance.Target.transform.position }; var setupJH = setupRaycastJob.Schedule(taa_mobs); var raycastJH = RaycastCommand.ScheduleBatch(na_rayCommands, na_rayHits, 100, setupJH); var mobMovementJob = new MobMovementJob { deltaTime = Time.deltaTime, hits = na_rayHits, mobStates = na_mobStates, startPos = nl_startPos, targetPos = nl_targetPos }; movementJH = mobMovementJob.Schedule(taa_mobs, raycastJH); movementJH.Complete(); for (int i = 0; i < na_mobStates.Length; ++i) { if (na_mobStates[i] == MobState.Throw) { SpearBehavior spear = PoolManager.instance.SpearPool.SpawnObject(taa_mobs[i].position + SettingsManager.ThrowingPoint, Quaternion.Euler(SettingsManager.ThrowingRotation)) as SpearBehavior; spear.Throw(); na_mobStates[i] = MobState.FromTarget; } } }