static public unsafe void _polygonColliderCast(CollisionFilter _filter, CollisionWorld _collisionWorld, NativeList <ColliderCastHit> _allHits,
                                                   quaternion Orientation,
                                                   float3 Start,
                                                   float3 End,
                                                   float3 vertex0, float3 vertex1, float3 vertex2, float3 vertex3)
    {
        BlobAssetReference <Unity.Physics.Collider> _polygonCollider = Unity.Physics.PolygonCollider.CreateQuad(vertex0, vertex1, vertex2, vertex3);

        Unity.Physics.ColliderCastInput colliderCastInput = new ColliderCastInput()
        {
            Collider    = (Unity.Physics.Collider *)_polygonCollider.GetUnsafePtr(),
            Orientation = ECS_RTSControls.instance._camera.transform.rotation,
            Start       = ECS_RTSControls.instance._camera.transform.position,
            End         = ECS_RTSControls.instance._camera.transform.rotation * new Vector3(100, 0, 0)
        };

        ColliderCastJob _colliderCastJob = new ColliderCastJob();

        _colliderCastJob._collisionWorld = _collisionWorld;
        _colliderCastJob._allHits        = _allHits;


        _polygonCollider.Dispose();
    }
示例#2
0
    protected unsafe override void OnUpdate()
    {
        var _ecb                  = m_EntityCommandBufferSystem.CreateCommandBuffer();
        var _ecbo                 = m_EntityCommandBufferSystemo.CreateCommandBuffer();
        var _ecbEndSimilation     = m_endSimulationEntityCommandBufferSystem.CreateCommandBuffer();
        var _ecbBeginPresentation = m_beginPresentationEntityCommandBufferSystem.CreateCommandBuffer();

        var            _physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
        CollisionWorld _collisionWorld     = _physicsWorldSystem.PhysicsWorld.CollisionWorld;
        var            _physicsWorld       = _physicsWorldSystem.PhysicsWorld;

        float3 _startPosition      = ECS_RTSControls.instance._startScreenPosition;
        float3 _endPosition        = ECS_RTSControls.instance._endScreenPosition;
        float3 _lowerLeftPosition  = ECS_RTSControls.instance._lowerLeftScreenPosition;
        float3 _upperRightPosition = ECS_RTSControls.instance._upperRightScreenPosition;

        Dependency = JobHandle.CombineDependencies(Dependency, m_EndFramePhysicsSystem.GetOutputDependency());

        if (_inputReady)
        {
            if (Input_Mouse_0_Up == true && Input_Mouse_0_Up != EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity))
            {
                Input_Mouse_0_GetDown = true;
                Input_Mouse_0_Up      = false;
            }

            if (Input_Mouse_0_Up == false && (Input_Mouse_0_Up != EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity)))
            {
                Input_Mouse_0_GetUp = true;
                Input_Mouse_0_Up    = true;
            }

            if (Input_Mouse_1_Up == true && (Input_Mouse_1_Up != EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity)))
            {
                Input_Mouse_1_GetDown = true;
                Input_Mouse_1_Up      = false;
            }
            if (Input_Mouse_1_Up == false && (Input_Mouse_1_Up != EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity)))
            {
                Input_Mouse_1_GetUp = true;
                Input_Mouse_1_Up    = true;
            }
        }
        else
        {
            if (_queryInput.CalculateEntityCount() > 0)
            {
                _inputEntity     = _queryInput.GetSingletonEntity();
                _inputReady      = true;
                Input_Mouse_0_Up = EntityManager.HasComponent <Input_Mouse_0_Up>(_inputEntity);
                Input_Mouse_1_Up = EntityManager.HasComponent <Input_Mouse_1_Up>(_inputEntity);
            }
        }

        if (Time.ElapsedTime > 4)
        {
            /*this.Dependency =  Entities.WithoutBurst().ForEach((in Translation _translation, in UnitSelected _unitSelected, in Selectable _selectable, in GrisTag _grisTag, in Entity _entity) =>
             * {
             *   var e = _ecbEndSimilation.Instantiate(PrefabConvert._DalleVerte);
             *   _ecbEndSimilation.SetComponent<Translation>(e, _translation);
             *   _ecbEndSimilation.DestroyEntity(_entity);
             *   Debug.Log("Unity3d : 'va te faire foutre'");
             *
             * }).Schedule(this.Dependency);*/
        }

        if (Input_Mouse_0_GetUp == true)
        {
            bool  selectOnlyOneEntity  = false;
            float selectionAreaMinSize = 10f;
            float selectionAreaSize    = math.distance(_lowerLeftPosition, _upperRightPosition);
            if (selectionAreaSize < selectionAreaMinSize)
            {
                // Selection area too small
                _lowerLeftPosition  += new float3(-1, -1, 0) * (selectionAreaMinSize - selectionAreaSize) * .5f;
                _upperRightPosition += new float3(+1, +1, 0) * (selectionAreaMinSize - selectionAreaSize) * .5f;
                selectOnlyOneEntity  = true;
            }

            // Deselect all selected Entities
            this.Dependency = Entities.WithAll <UnitSelected>().ForEach((Entity entity) => {
                _ecb.RemoveComponent <UnitSelected>(entity);
            }).Schedule(this.Dependency);



            Unity.Physics.RaycastHit _hit1 = new Unity.Physics.RaycastHit();
            Unity.Physics.RaycastHit _hit2 = new Unity.Physics.RaycastHit();
            Unity.Physics.RaycastHit _hit3 = new Unity.Physics.RaycastHit();
            Unity.Physics.RaycastHit _hit4 = new Unity.Physics.RaycastHit();
            Unity.Physics.RaycastHit _hit5 = new Unity.Physics.RaycastHit();

            var _ray1 = ECS_RTSControls.instance._ray1;
            var _ray2 = ECS_RTSControls.instance._ray2;
            var _ray3 = ECS_RTSControls.instance._ray3;
            var _ray4 = ECS_RTSControls.instance._ray4;
            var _ray5 = ECS_RTSControls.instance._ray5;

            /*RaycastInput _inputo = new RaycastInput()
             * {
             *  Start = _ray1.origin,
             *  End = _ray1.origin + _ray1.direction * 1000,
             *  Filter = new CollisionFilter()
             *  {
             *      BelongsTo = (uint)10 << 10,
             *      CollidesWith = (uint)7 << 8,
             *      GroupIndex = 8
             *  }
             * };*/

            GetRaycastHit(_collisionWorld, _ray1, _ray2, _ray3, _ray4, _ray5, out _hit1, out _hit2, out _hit3, out _hit4, out _hit5);


            var _filter = new CollisionFilter()
            {
                BelongsTo    = ~1u,
                CollidesWith = ~1u, // all 1s, so all layers, collide with everything
                GroupIndex   = 0
            };

            NativeList <ColliderCastHit> _allHits = new NativeList <ColliderCastHit>(Allocator.TempJob);


            _polygonCollider = Unity.Physics.PolygonCollider.CreateQuad(_hit1.Position, _hit2.Position, _hit3.Position, _hit4.Position, _filter);

            /*SphereGeometry sphereGeometry = new SphereGeometry() { Center = float3.zero, Radius = 3 };
             * _sphereCollider = Unity.Physics.SphereCollider.Create(sphereGeometry, _filter);*/
            /*
             * Unity.Physics.ColliderCastInput colliderCastInput = new ColliderCastInput()
             * {
             *  Collider = (Unity.Physics.Collider*)_sphereCollider.GetUnsafePtr(),
             *  Orientation = ECS_RTSControls.instance._camera.transform.rotation,
             *  Start = ECS_RTSControls.instance._camera.transform.position,
             *  End = _ray1.origin + _ray1.direction * 1000
             * };*/
            var _moyPoly = new float3((_hit1.Position.x + _hit2.Position.x + _hit3.Position.x + _hit4.Position.x) / 4,
                                      (_hit1.Position.y + _hit2.Position.y + _hit3.Position.y + _hit4.Position.y) / 4,
                                      (_hit1.Position.z + _hit2.Position.z + _hit3.Position.z + _hit4.Position.z) / 4);



            Debug.Log(_moyPoly + "_moyPoly");

            //var  _pouitCollider = BlobAssetReference<Unity.Physics.Collider>.Create(_polygonCollider.GetUnsafePtr(), 1);

            /* this.Dependency = Job.WithoutBurst().WithCode(() =>
             * {
             *   var e = _ecb.Instantiate(PrefabConvert._CubeRouge);
             *   _ecb.SetComponent<Translation>(e, new Translation { Value = _hit1.Position + new float3(0, 5, 0) });
             *   e = _ecb.Instantiate(PrefabConvert._CubeRouge);
             *   _ecb.SetComponent<Translation>(e, new Translation { Value = _hit2.Position + new float3(0, 5, 0) });
             *   e = _ecb.Instantiate(PrefabConvert._CubeRouge);
             *   _ecb.SetComponent<Translation>(e, new Translation { Value = _hit3.Position + new float3(0, 5, 0) });
             *   e = _ecb.Instantiate(PrefabConvert._CubeRouge);
             *   _ecb.SetComponent<Translation>(e, new Translation { Value = _hit4.Position + new float3(0, 5, 0) });
             * }).Schedule(this.Dependency);
             * Debug.Log(_dalleSelectedQuery.CalculateEntityCount() + "_dalleSelectedQueryCount");
             * Debug.Log(_dalleQuery.CalculateEntityCount() + "_dalleQueryCount");
             *
             * /*Mesh _mesh = new Mesh { }
             *
             * RenderMesh huiaef = new RenderMesh { mesh = }
             *
             * this.Dependency.Complete();*/

            ColliderCastJob _colliderCastJob = new ColliderCastJob();
            _colliderCastJob.CollectAllHits   = true;
            _colliderCastJob.Collider         = (Unity.Physics.Collider *)_polygonCollider.GetUnsafePtr();
            _colliderCastJob.ColliderCastHits = _allHits;
            _colliderCastJob.End         = new float3(0, -2, 0); // _moyPoly;
            _colliderCastJob.Orientation = quaternion.identity;  //ECS_RTSControls.instance._camera.transform.rotation;
            _colliderCastJob.Start       = /*_moyPoly +*/ new float3(0, 5, 0);
            _colliderCastJob.World       = _physicsWorld;
            Dependency = _colliderCastJob.ScheduleSingle(_query, this.Dependency);

            //World.GetOrCreateSystem<StepPhysicsWorld>().FinalSimulationJobHandle.Complete();

            this.Dependency.Complete();

            /*Debug.Log(_query.CalculateEntityCount() + "_queryMovestats");
             * Debug.Log(_allHits.Length + "_allHits.Length");*/
            this.Dependency = Job.WithoutBurst().WithDisposeOnCompletion(_allHits).WithCode(() =>
            {
                for (int i = 0; i < _allHits.Length; i++)
                {
                    _ecbEndSimilation.AddComponent(_allHits[i].Entity, new UnitSelected());
                }

                Debug.Log(_allHits.Length + "entityHits");
            }).Schedule(this.Dependency);

            this.Dependency.Complete();
        }

        if (Input_Mouse_1_Up == false)
        {
            if (Time.ElapsedTime > 2)
            {
                Debug.Log("yoloZoulou");
                this.Dependency = Entities.WithoutBurst().WithAll <PlaneLayer>().WithAll <Player1>().ForEach((Entity entity) => {
                    _ecb.DestroyEntity(entity);//.RemoveComponent<UnitSelected>(entity);
                }).Schedule(this.Dependency);
            }

            //Debug.Log(Input.GetMouseButtonDown(1));
            // Right mouse button down
            float3        targetPosition   = UtilsClass.GetMouseWorldPosition();
            List <float3> movePositionList = GetPositionListAround(targetPosition, new float[] { 10f, 20f, 30f }, new int[] { 5, 10, 20 });
            int           positionIndex    = 0;
            Entities.WithAll <UnitSelected>().ForEach((Entity entity, ref MoveStats _moveStats) => {
                /*moveTo.position = movePositionList[positionIndex];
                 * positionIndex = (positionIndex + 1) % movePositionList.Count;
                 * moveTo.move = true;*/
            }).Schedule();
        }
        //m_EntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency);
        World.GetOrCreateSystem <StepPhysicsWorld>().FinalSimulationJobHandle.Complete();
        this.Dependency.Complete();
        m_EntityCommandBufferSystemo.AddJobHandleForProducer(this.Dependency);
        m_endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency);
        m_EntityCommandBufferSystemo.AddJobHandleForProducer(this.Dependency);

        if (_polygonCollider.IsCreated)
        {
            _polygonCollider.Dispose();
        }
        if (_sphereCollider.IsCreated)
        {
            _sphereCollider.Dispose();
        }
        Input_Mouse_0_GetUp   = false;
        Input_Mouse_0_GetDown = false;
    }