private void Monit(FileStream fs) { Process[] pAll = Process.GetProcesses(); foreach (var p in pAll) { if (p.MainWindowHandle.ToInt64() == 0) { continue; } string name = p.ProcessName; if (myMon != null) { DateTime dt = DateTime.Now; DateTime e = dt; DateTime cs = dt.AddSeconds(-step); DateTime s = p.StartTime > cs ? p.StartTime : cs; myMon(name, s, e); } SoftItem item = SList.Find(o => o.Name == name && !o.changed); if (item == null) { item = new SoftItem() { Name = name, Sign = SList.Count * 2, count = 0 }; SList.Add(item); } else { } byte[] count = new byte[2]; try { count = int2byte(item.count); } catch { count[1] = 0; count[0] = 0; } item.count++; add(ref count); fs.Seek(item.Sign, SeekOrigin.Begin); fs.Write(count, 0, 2); fs.Flush(true); item.changed = true; } foreach (var item in SList) { item.changed = false; } }
private void Start() { children = gameObject.GetComponentsInChildren <Transform>(); if (gameObject.GetComponent <Collider>() == true) { colliderItems.Add(gameObject); } foreach (Transform obj in children) { if (obj.gameObject.GetComponent <Collider>() == true) { colliderItems.Add(obj.gameObject); } } player = GameObject.Find("Player"); player.GetComponent <PlayerController>().RegisterObserver(this); PhysicsBehavior phys = null; switch (itemDensity) { case ItemDensity.HARD: phys = new HardItem(); break; case ItemDensity.HEAVY: phys = new HeavyItem(); break; case ItemDensity.SOFT: phys = new SoftItem(); break; case ItemDensity.RUBBERY: phys = new RubberyItem(); break; } phys.UpdatePhysicMaterial(gameObject); }
public void Initob() { if (state == 1) { if (clock != null && !clock.Enabled) { clock.Start(); } return; } string keyPath = Application.StartupPath + "\\key.dat"; if (!File.Exists(keyPath)) { FileStream temp = File.Create(keyPath); temp.Close(); } string tx = File.ReadAllText(keyPath, Encoding.Default); SList = Utility.StringToObject <List <SoftItem> >(tx); if (SList == null) { SList = new List <SoftItem>(); } string recodPath = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyyMMdd"); recodPath += "m"; if (!File.Exists(recodPath)) { FileStream fs = File.Create(recodPath); fs.Close(); } using (FileStream rd = File.OpenRead(recodPath)) { byte[] bd = new byte[2]; for (int i = 0; i < rd.Length; i += 2) { rd.Seek(i, SeekOrigin.Begin); rd.Read(bd, 0, 2); int ct = byte2int(bd); SoftItem item = SList.Find(o => o.Sign == i); if (item == null) { continue; } if (item.count != ct) { item.count = ct; } } } writer = File.OpenWrite(recodPath); clock = new Timer(); clock.Interval = step * 1000; clock.Tick += new EventHandler(t_Tick); clock.Start(); state = 1; myMon += new Mon(detailMon); }