// Retrial for parameters common to most LSystems are wrapped here for convenience. public bool GetCoreParameters(ParameterBundle bundle, out Sentence sentence, out CharGameObjectDict implementations, out RuleSet rules) { bool success = true; if (!bundle.Get("Sentence", out sentence)) { success = false; Debug.LogError("Default parameter 'Sentence' missing.", gameObject); } if (!bundle.Get("Implementations", out implementations)) { success = false; Debug.LogError("Default parameter 'Implementations' missing.", gameObject); } if (!bundle.Get("RuleSet", out rules)) { success = false; Debug.LogError("Default parameter 'RuleSet' missing.", gameObject); } return(success); }
protected void DrawImplementations() { CharGameObjectDict implementations = ((Seed)target).Implementations; List <char> keys = implementations.KeyList; List <GameObject> values = implementations.ValueList; if (values.Count != keys.Count) { Debug.LogError("Implementations value count (" + values.Count + ") not equal to key count(" + keys.Count + ")"); keys.Clear(); values.Clear(); } if ((implementationFoldout = EditorGUILayout.Foldout(implementationFoldout, "Implementations"))) { Rect controlRect; for (int i = 0; i < keys.Count; i++) { controlRect = EditorGUILayout.GetControlRect(false); Rect keyRect = new Rect(controlRect.position, new Vector2(controlRect.size.x / 2, controlRect.size.y)); Rect valueRect = new Rect(new Vector2(controlRect.position.x + controlRect.size.x / 2, controlRect.position.y), new Vector2(controlRect.size.x / 2 - 25, controlRect.size.y)); Rect removeRect = new Rect(new Vector2(controlRect.position.x + controlRect.size.x - 25, controlRect.position.y), new Vector2(25, controlRect.size.y)); string newKeyStr = EditorGUI.TextField(keyRect, "" + keys[i]); char newKey = (char)33; if (newKeyStr.Length > 0) { newKey = newKeyStr.ToCharArray()[0]; } //Make sure key is unique. if (newKey != keys[i]) { int max = 33; bool hit = false; for (int j = 0; j < keys.Count; j++) { if (keys[j] == newKey && i != j) { hit = true; } if (keys[j] > max) { max = keys[j]; } } if (hit) { newKey = (char)++max; } } keys[i] = newKey; values[i] = (GameObject)EditorGUI.ObjectField(valueRect, values[i], values[i].GetType(), false); if (!EditorGUI.Toggle(removeRect, true)) { keys.RemoveAt(i); values.RemoveAt(i); } } string[] allPaths = Directory.GetDirectories(Application.dataPath, "LSystem", SearchOption.AllDirectories); if (allPaths.Length > 1) { Debug.LogWarning("There is more than one LSystem directory in the project, Prefab root may be calculated incorrectly."); } if (allPaths.Length <= 0) { Debug.LogError("Cannot find LSystem Directory."); } DrawNewImplementations(keys, values, allPaths); DrawExistingImplementations(keys, values, allPaths); EditorGUILayout.Space(); } }