public override void OnInspectorGUI() { AutomataCelular3Estados automata = target as AutomataCelular3Estados; string[] opciones = new string[automata.reglasIniciales.Length]; for (int i = 0; i < opciones.Length; i++) { opciones[i] = automata.reglasIniciales[i].name; } EditorGUI.BeginChangeCheck(); ushort opc = (ushort)EditorGUILayout.Popup("Set Regla Global", automata.DistrubucionReglas == null?-1:automata.DistrubucionReglas[0], opciones); if (EditorGUI.EndChangeCheck() && automata.DistrubucionReglas != null) { if (modohalf) { for (int x = 0; x < automata.ancho; x++) { for (int y = 0; y < automata.alto; y++) { if ((ladoA && x < automata.ancho / 2) || (!ladoA && x >= automata.ancho / 2)) { automata.SetRegla(x + automata.ancho / 4, y, opc); } } } ladoA = !ladoA; } else { automata.SetReglaGlobal(opc); } } modohalf = EditorGUILayout.Toggle("Modo Mitad Reglas", modohalf); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Ruido Global")) { automata.RuidoGlobal(); } if (GUILayout.Button("Ruido Central")) { automata.RuidoCentral(); } if (GUILayout.Button("Ruido Central Aditivo")) { automata.RuidoCentral(true); } EditorGUILayout.EndHorizontal(); DrawDefaultInspector(); }
private void OnEnable() { if (!automata) { enabled = false; return; } if (automata.Reglas == null) { enabled = false; return; } puntos.Clear(); List <uint> colors = new List <uint>(); for (int i = 0; i < automata.Reglas.Length * repeticiones; i++) { colors.Add(0); puntos.Add(new Vector2(Random.value * automata.ancho, Random.value * automata.alto)); } float minDgen = (automata.ancho * automata.alto); float minD = minDgen; float d = minDgen; ushort id = 0; for (ushort x = 0; x < automata.ancho; x++) { for (ushort y = 0; y < automata.alto; y++) { id = 0; minD = (x - puntos[0].x) * (x - puntos[0].x) + (y - puntos[0].y) * (y - puntos[0].y); for (ushort p = 1; p < puntos.Count; p++) { d = (x - puntos[p].x) * (x - puntos[p].x) + (y - puntos[p].y) * (y - puntos[p].y); if (d < minD) { minD = d; id = (ushort)(p % automata.reglasIniciales.Length); } } automata.SetRegla(x, y, id); } } //voronoi = new Voronoi(puntos,colors,new Rect(0,0,automata.ancho,automata.alto)); }