Exemple #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityManager        m_entityManager  = SwarmOfIron.Instance.entityManager;
            NativeArray <float3> movePositionList = new NativeArray <float3>(Soldier.movePositionList.ToArray(), Allocator.TempJob);

            Entity target         = UnitControlHelpers.GetEntityTarget();
            float3 targetPosition = UnitControlHelpers.GetMousePosition();

            bool harvest = false;

            if (EntityManager.Exists(target))
            {
                harvest = EntityManager.HasComponent <RockComponent>(target);
            }

            EntityCommandBuffer.Concurrent entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();

            JobHandle jobHandle = Entities.WithAll <UnitSelectedComponent>().WithNone <CityHallComponent>().ForEach((Entity entity, int entityInQueryIndex, in Translation translation) =>
            {
                entityCommandBuffer.AddComponent(entityInQueryIndex, entity, new MoveToComponent
                {
                    harvest       = harvest,
                    startPosition = translation.Value,
                    endPosition   = (!harvest ? movePositionList[entityInQueryIndex] : 0) + targetPosition
                });
            }).Schedule(inputDeps);

            endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

            return(movePositionList.Dispose(jobHandle));
        }
Exemple #2
0
        protected override void OnUpdate()
        {
            // left click Down
            if (Input.GetMouseButtonDown(0))
            {
                this.OnLeftClickDown();
            }

            // Hold left click Down
            if (Input.GetMouseButton(0))
            {
                this.OnLeftClickMove();
            }

            if (this.currentAction == "HouseIcon")
            {
                SwarmOfIron.Instance.worldSelectionAreaTransform.position   = UnitControlHelpers.GetMousePosition() + new float3(-10, 1, 10);
                SwarmOfIron.Instance.worldSelectionAreaTransform.localScale = new Vector3(20, 1, 20);
                SwarmOfIron.Instance.selectionAreaTransform.localScale      = new Vector3(0, 0, 0);
            }


            // left click Up
            if (Input.GetMouseButtonUp(0) && !isUI)
            {
                this.OnLeftClickUp();
            }

            // right click
            if (Input.GetMouseButtonDown(1))
            {
                this.OnRightClickDown();
            }
        }
Exemple #3
0
 public void ExecuteCurrentAction(string action)
 {
     if (action == "ArrowIcon")
     {
         //move selected units
         SwarmOfIron.Instance.updateMoveToSystem.Update();
     }
     else if (action == "HouseIcon")
     {
         if (SwarmOfIron.Instance.goldAmount >= 100.0f)
         {
             SwarmOfIron.Instance.goldAmount -= 100.0f;
             CustomEntity.SpawnEntityAtPosition(typeof(CityHall), UnitControlHelpers.GetMousePosition());
         }
     }
 }
Exemple #4
0
        private void OnLeftClickMove()
        {
            float3 currentPositionScreen = Input.mousePosition;                     // Screen Position
            float3 currentPositionWorld  = UnitControlHelpers.GetMousePosition();   // World Position

            float3 selectionAeraSize = currentPositionScreen - startPositionScreen; // Resize SCREEN selection Area

            // Resize WORLD selection Area

            currentPositionWorld = RotatePointAroundPivot(currentPositionWorld, startPosition, Quaternion.Inverse(Camera.main.transform.rotation));
            //currentPositionWorld = RotatePointAroundPivot();
            float3 worldSelectionAeraSizetest = currentPositionWorld - startPosition;

            SwarmOfIron.Instance.selectionAreaTransform.localScale = selectionAeraSize;
            Vector3 scaleSelectObj = new Vector3(worldSelectionAeraSizetest[0], 3.0f, worldSelectionAeraSizetest[2]);

            selectionObj.transform.localScale = scaleSelectObj;
        }
Exemple #5
0
        private void OnLeftClickDown()
        {
            SwarmOfIron.Instance.ToggleSelectionArea(true);

            startPosition       = UnitControlHelpers.GetMousePosition(); // World Position
            startPositionScreen = Input.mousePosition;                   // Screen Position

            // selection OBJ Box
            selectionObj = SwarmOfIron.Instance.selectionObj;
            selectionObj.transform.position = startPosition;

            Vector3 cameraVec3 = Camera.main.transform.eulerAngles;

            selectionObj.transform.rotation = Quaternion.Euler(0.0f, cameraVec3.y, 0.0f);

            if (UserInterface.TryClickInterface(startPositionScreen, "Actions"))
            {
                // On a cliqué sur le menu des boutons d'actions
                isUI = true;

                // On récupère la coordonnée local du clique
                Vector3 localActionCoord = SwarmOfIron.Instance.listButtonGO.Find(el => el.name == "Actions").transform.InverseTransformPoint(startPositionScreen);

                // On récupère l'action & on met a jour
                this.currentAction = ActionHelpers.GetAction(localActionCoord, this.layers);
                ActionHelpers.UpdateActionUI(this.hasHubSelected, this.hasWorkerSelected, this.selectedEntityCount > 0, this.currentAction, ref this.layers);

                if (hasHubSelected)
                {
                    //Debug.Log("hello PeonIcon");
                    spawWorkers();
                    //Worker.SpawnWorker(new float3(0, 0, 0));
                }
            }
            else
            {
                isUI = false;

                SwarmOfIron.Instance.selectionAreaTransform.position      = startPositionScreen;                  // Zone de sélection    rectangle vert      (screen)
                SwarmOfIron.Instance.worldSelectionAreaTransform.rotation = Quaternion.Euler(0, SwarmOfIron.Instance.cameraRig.transform.eulerAngles.y, 0);
            }
        }