コード例 #1
0
ファイル: WorkerTaskAI.cs プロジェクト: ztw312/Unity-Script
 private void ExecuteTask_Victory(Task.Victory task)
 {
     CMDebug.TextPopup("ExecuteTask_Victory", transform.position);
     worker.PlayVictoryAnimation(() =>
     {
         state = State.WaitingForNextTask;
     });
 }
コード例 #2
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         // Spawn a pistol and queue the task to take it to a slot when possible
         GameObject pistolGameObject = SpawnPistolSprite(UtilsClass.GetMouseWorldPosition());
         taskSystem.EnqueueTask(() => {
             foreach (WeaponSlot weaponSlot in weaponSlotList)
             {
                 if (weaponSlot.IsEmpty())
                 {
                     // If the weapon slot is empty lets create the task to take it there
                     weaponSlot.SetHasWeaponIncoming(true);
                     Task task = new Task.TakeWeaponToWeaponSlot {
                         weaponPosition     = pistolGameObject.transform.position,
                         weaponSlotPosition = weaponSlot.GetPosition(),
                         grabWeapon         = (CM_WorkerTaskAI weaponWorkerTaskAI) => {
                             // Grab weapon, parent the weapon to the worker
                             pistolGameObject.transform.SetParent(weaponWorkerTaskAI.transform);
                         },
                         dropWeapon = () => {
                             // Drop weapon, set parent back to null
                             pistolGameObject.transform.SetParent(null);
                             // Notify the weapon slot that the weapon has arrived
                             weaponSlot.SetWeaponTransform(pistolGameObject.transform);
                         },
                     };
                     return(task);
                 }
                 // Weapon slot not empty, keep looking
             }
             // No weapon slot is empty, try again later
             return(null);
         });
         //CMDebug.TextPopupMouse("Add Task: ShellFloorCleanUp, 5s delay");
         //SpawnFloorShellsWithTask(UtilsClass.GetMouseWorldPosition());
     }
     if (Input.GetMouseButtonDown(1))
     {
         CMDebug.TextPopupMouse("Add Task: MoveToPosition");
         //CM_TaskSystem.Task task = new CM_TaskSystem.Task.Victory { };
         //taskSystem.AddTask(task);
         Task task = new Task.MoveToPosition {
             targetPosition = UtilsClass.GetMouseWorldPosition()
         };
         taskSystem.AddTask(task);
     }
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         CMDebug.TextPopupMouse("Add Task: Victory");
         Task task = new Task.Victory {
         };
         taskSystem.AddTask(task);
     }
 }
コード例 #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            type = 1;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            type = 2;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            type = 3;
        }
        if (Input.GetMouseButtonDown(0))
        {
            switch (type)
            {
            case 1:
                GameObject weapon = CreateWeapon(UtilityClass.GetMouseWorldPos());
                taskSystem.EnqueueTask(() =>
                {
                    if (weaponSlot.IsEmpty())
                    {
                        weaponSlot.SetHasWeaponIncoming(true);
                        Task task = new Task.TaskWeaponToWeaponSlot
                        {
                            weaponPosition     = weapon.transform.position,
                            weaponSlotPosition = weaponSlot.GetPosition(),
                            grabWeapon         = (WorkerTaskAI workerAI) =>
                            {
                                weapon.transform.SetParent(workerAI.transform);
                            },
                            dropWeapon = () =>
                            {
                                weaponSlot.SetWeaponTransform(weapon.transform);
                            }
                        };
                        return(task);
                    }
                    else
                    {
                        return(null);
                    }
                });
                break;

            case 2: CreateWeaponSlot(UtilityClass.GetMouseWorldPos()); break;

            case 3: CreateTask(); break;

            default:
                break;
            }
        }
        if (Input.GetMouseButtonDown(1))
        {
            Task task = new Task.Victory
            {
            };
            taskSystem.AddTask(task);
        }
    }