private void ApplyItemsSelection() { CubeTreeNode node = null; node = Tree.SelectedItem as CubeTreeNode; //Запоминаем выбранный элемент m_SelectedInfo = node != null ? node.Info as CubeDefInfo : null; }
public void Randomize(int maxDepth, int totalDepth) { for (int i = 0; i < 20; i++) { if (Random.Range(0, 100) < (12 / totalDepth * maxDepth) && maxDepth > 0 && i != parent) { children[i] = new CubeTreeNode(Random.Range(0, children.Length)); children[i].children [children[i].parent] = this; children [i].Randomize(maxDepth - 1, totalDepth); } } }
void Loader_DataLoaded(object sender, DataLoaderEventArgs e) { CustomTreeNode parentNode = e.UserState as CustomTreeNode; if (parentNode != null) { parentNode.IsWaiting = false; } else { Tree.IsWaiting = false; } if (e.Error != null) { ShowErrorInTree(parentNode); LogManager.LogError(this, e.Error.ToString()); return; } if (e.Result.ContentType == InvokeContentType.Error) { ShowErrorInTree(parentNode); LogManager.LogError(this, e.Result.Content); return; } List <CubeDefInfo> cubes = XmlSerializationUtility.XmlStr2Obj <List <CubeDefInfo> >(e.Result.Content); if (cubes != null) { foreach (CubeDefInfo info in cubes) { if (ShowAllCubes || info.Type == CubeInfoType.Cube) { CubeTreeNode node = new CubeTreeNode(info); // Кубы будут конечными узлами. Двойной клик на них будет равнозначен выбору node.Expanded += new RoutedEventHandler(node_Expanded); node.Collapsed += new RoutedEventHandler(node_Collapsed); if (parentNode == null) { Tree.Items.Add(node); } else { parentNode.Items.Add(node); } } } } }
public static Monster ReadFromFile(string filename) { System.IO.FileStream f = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); Monster m = new Monster(true); try{ byte[] bytes = new byte[8]; f.Read(bytes, 0, 4); m.fitness = System.BitConverter.ToSingle(bytes, 0); f.Read(bytes, 0, 4); int icount = System.BitConverter.ToInt32(bytes, 0); List <Instruction> il = new List <Instruction> (); for (int i = 0; i < icount; i++) { f.Read(bytes, 0, 4); int n = System.BitConverter.ToInt32(bytes, 0); f.Read(bytes, 0, 4); float s = System.BitConverter.ToSingle(bytes, 0); il.Add(new Instruction(n, s)); } m.set = new InstructionSet(il); f.Read(bytes, 0, 4); int ncount = System.BitConverter.ToInt32(bytes, 0); Debug.Log("NCOUNT: " + ncount); List <MonsterTreeNode> mtnl = new List <MonsterTreeNode> (); int[,] links = new int[ncount, 20]; for (int i = 0; i < ncount; i++) { CubeTreeNode mtn = new CubeTreeNode(); f.Read(bytes, 0, 4); mtn.parent = System.BitConverter.ToInt32(bytes, 0); f.Read(bytes, 0, 4); mtn.scale.x = System.BitConverter.ToSingle(bytes, 0); f.Read(bytes, 0, 4); mtn.scale.y = System.BitConverter.ToSingle(bytes, 0); f.Read(bytes, 0, 4); mtn.scale.z = System.BitConverter.ToSingle(bytes, 0); for (int j = 0; j < 20; j++) { f.Read(bytes, 0, 4); links[i, j] = System.BitConverter.ToInt32(bytes, 0); } mtnl.Add(mtn); } //Now actually link them for (int i = 0; i < ncount; i++) { MonsterTreeNode mtn = mtnl [i]; for (int j = 0; j < 20; j++) { if (links[i, j] == -1) { mtn.children [j] = null; } else { mtn.children [j] = mtnl [links [i, j]]; } } } MonsterTree mt = new MonsterTree(); mt.nodes = mtnl; mt.root = mtnl [0]; mt.monster = m; m.tree = mt; }catch { m = null; } f.Close(); return(m); }