public void stopWork() { if (work != workType.idle) { work = workType.idle; } }
public void dowork(int hours, workType worktype) { // do work to notify cm work been perforemd for (int i = 0; i < hours; i++) { System.Threading.Thread.Sleep(1000); //suspends current th for 1 s onWorkPerformed(i + 1, worktype); } // Raise event onWorkCompleted(); }
private bool addWorker(ship_satellite _sat, List <ship_satellite> _workers, workType _wType, GameObject _owner) { bool _res = false; if (_sat != null && _workers != null) { _workers.Add(_sat); _sat.work = _wType; _sat.owner = _owner; _res = true; } return(_res); }
// Use this for initialization void Start() { zCoord = transform.position.z; shooter = GetComponent <MeteorShooter>(); Debug.Assert(shooter); work = workType.idle; lineRenderer = GetComponent <LineRenderer>(); if (lineRenderer != null) { lineRenderer.endColor = new Color(0, 0, 0, 0.2f); } workTimeMine_amount = workTimeMine; eye = transform.GetChild(0).gameObject; engine_left = transform.GetChild(1).gameObject; engine_right = transform.GetChild(2).gameObject; eyeState = false; }
// add seperate mehthod for each event protected virtual void onWorkPerformed(int hours, workType worktype) { //// way 1 //if (WorkPerformed != null) //{ // WorkPerformed(hours, worktype); //} Console.WriteLine("Work Performeded"); // var del = WorkPerformed as WorkPerformedHandler; var del = WorkPerformed as EventHandler <WorkPerformedEventArgs>; if (del != null) { // del(hours, worktype); // Raise event del(this, new WorkPerformedEventArgs(hours, worktype)); } }
// Update is called once per frame void Update() { if (ship == null) { Destroy(gameObject); return; } if (lineRenderer != null) { lineRenderer.SetPosition(0, transform.position); lineRenderer.SetPosition(1, ship.transform.position); float _dist = Vector2.Distance(transform.position, ship.transform.position) / maxDistance; lineRenderer.startColor = new Color(_dist, 0, 0, _dist); } float step = speed * Time.deltaTime; switch (work) { case workType.idle: transform.position = Vector2.MoveTowards(transform.position, ship.transform.position, step); if (Vector2.Distance(transform.position, ship.transform.position) <= minDistance) { var _ship = ship.GetComponent <Ship>(); if (_ship != null && mine_amount > 0) { _ship.addEnergy(mine_amount); mine_amount = 0; SoundController.playSound(GetComponent <AudioSource>(), sndGetEnergy); } } isDefing = false; isMining = false; setEye(true); shooter.SetActive(false); break; case workType.defer: if (ship != null) { if (isDefing) { transform.RotateAround(ship.transform.position, Vector3.forward, defRotateSpeed * Time.deltaTime); transform.rotation = Quaternion.identity; } else { transform.position = Vector2.MoveTowards(transform.position, ship.transform.position + Vector3.up * 10, step); if (Vector2.Distance(transform.position, ship.transform.position) >= defDistance) { isDefing = true; shooter.SetActive(true); setEye(false); } } } break; case workType.miner: if (owner != null && ship != null) { if (isMining) { workTimeMine_amount -= Time.deltaTime; if (workTimeMine_amount <= 0) { setEye(true); transform.position = Vector2.MoveTowards(transform.position, ship.transform.position, step); if (Vector2.Distance(transform.position, ship.transform.position) <= minDistance) { isMining = false; var _ship = ship.GetComponent <Ship>(); if (_ship != null) { _ship.addEnergy(mine_amount); } SoundController.playSound(GetComponent <AudioSource>(), sndGetEnergy); } } else { var _mine = owner.GetComponent <mine_meteor>(); if (_mine != null) { mine_amount += _mine.MineSpeed * Time.deltaTime; } transform.position = Vector2.MoveTowards(transform.position, owner.transform.position, step); } } else { transform.position = Vector2.MoveTowards(transform.position, owner.transform.position, step); if (Vector2.Distance(transform.position, owner.transform.position) <= minDistance) { isMining = true; workTimeMine_amount = workTimeMine; mine_amount = 0; setEye(false); } } } else { work = workType.idle; } break; } if (Vector2.Distance(transform.position, ship.transform.position) > maxDistance) { wrapDestroy(); } /// engine anim if (engine_left != null) { var _spr = engine_left.GetComponent <SpriteRenderer>(); engine_dir_left = Ship.engineAnim_ext(0, _spr, engine_left.transform, engine_dir_left); } if (engine_right != null) { var _spr = engine_right.GetComponent <SpriteRenderer>(); engine_dir_right = Ship.engineAnim_ext(0, _spr, engine_right.transform, engine_dir_right); } ResetZCoord(); }
public WorkPerformedEventArgs(int hours, workType worktype) { Hours = hours; WorkType = worktype; }