示例#1
0
        /// <summary>
        /// Generates int and GUIContent arrays for use in IntPopup. Returns Node with the same value as <paramref name="findVal"/> if one is found.
        /// </summary>
        /// <param name="n">Node whos children will be processed</param>
        /// <param name="intVals">Value array to populate</param>
        /// <param name="labelVals">Name/Description array to populate</param>
        /// <param name="min">Min value allowed. Allows us to ignore wildcards used in the map(-1)</param>
        /// <param name="max">Max value allowed.</param>
        /// <param name="findVal">Value to search for and return found node.</param>
        /// <returns>Found node with the value <paramref name="findVal"/></returns>
        private Node GeneratePopupOptions(Node n, out int[] intVals, out GUIContent[] labelVals, int min, int max, int findVal)
        {
            Node FoundNd = null;

            if (n != null)
            {
                intVals   = new int[n.children.Count];
                labelVals = new GUIContent[n.children.Count];
                for (int i = 0; i < n.children.Count; ++i)
                {
                    Node currentNd = n.children[i];
                    if (currentNd.value < min || currentNd.value > max)
                    {
                        continue;                                                  // Ignore invalid values
                    }
                    intVals[i]   = currentNd.value;
                    labelVals[i] = new GUIContent(currentNd.name);

                    // Is this value currently selected?
                    if (findVal == currentNd.value)
                    {
                        FoundNd = currentNd;
                    }
                }
            }
            else
            {
                intVals   = new int[0];
                labelVals = new GUIContent[0];
            }
            return(FoundNd);
        }
示例#2
0
        /// <summary>
        /// Updates the popup choices for the 7 fields.
        /// </summary>
        private void UpdateChoices()
        {
            if (Map != null)
            {
                Node n = GeneratePopupOptions(Map.Root, out ints[0], out descriptions[0], byte.MinValue, byte.MaxValue, properties[0].intValue);
                for (int i = 1; i < properties.Length; ++i)
                {
                    if (properties[i].hasMultipleDifferentValues)
                    {
                        // Set to no data for remaining
                        for (int j = i; j < 7; ++j)
                        {
                            descriptions[j] = new GUIContent[0];
                            ints[j]         = new int[0];
                        }
                        return;
                    }

                    // Country is a ushort
                    if (i == 2)
                    {
                        n = GeneratePopupOptions(n, out ints[i], out descriptions[i], ushort.MinValue, ushort.MaxValue, properties[i].intValue);
                    }
                    else
                    {
                        n = GeneratePopupOptions(n, out ints[i], out descriptions[i], byte.MinValue, byte.MaxValue, properties[i].intValue);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Show a nodes contents and its child nodes if expanded.
        /// </summary>
        /// <param name="n"></param>
        private void ShowNode(Node n)
        {
            if (n.children != null)
            {
                for (int i = 0; i < n.children.Count; ++i)
                {
                    Node  ch     = n.children[i];
                    float indent = EditorGUI.indentLevel * 15;

                    EditorGUILayout.BeginHorizontal();

                    EditorGUILayout.BeginHorizontal(GUILayout.Width(30 + indent));
                    Color defaultBgCol = GUI.backgroundColor;
                    GUI.backgroundColor = ch.children.Count > 0 ? defaultBgCol : new Color(defaultBgCol.r, defaultBgCol.g, defaultBgCol.b, 0.1f);   // Use colour to indicate if a node has child nodes.
                    ch.isExpanded       = EditorGUILayout.Foldout(ch.isExpanded, string.Empty);
                    GUI.backgroundColor = defaultBgCol;
                    EditorGUILayout.EndHorizontal();

                    //GUI.contentColor = colors[EditorGUI.indentLevel % colors.Length];

                    ch.value = EditorGUILayout.IntField(ch.value, GUI.skin.label, GUILayout.Width(30 + indent));
                    ch.name  = EditorGUILayout.TextField(ch.name, EditorStyles.label);

                    // Add/Remove node?
                    if (EditorGUI.indentLevel < 7)
                    {
                        if (GUILayout.Button("+", EditorStyles.toolbarButton))
                        {
                            ch.children.Insert(0, new Node(-1, "Any"));
                            ch.isExpanded = true;
                        }
                    }

                    if (GUILayout.Button("-", EditorStyles.toolbarButton))
                    {
                        n.children.Remove(ch);
                        break;
                    }

                    // Object field
                    ch.obj = EditorGUILayout.ObjectField(ch.obj, typeof(GameObject), false) as GameObject;

                    EditorGUILayout.EndHorizontal();

                    // Draw children?
                    if (ch.isExpanded)
                    {
                        EditorGUI.indentLevel++;
                        ShowNode(ch);
                        EditorGUI.indentLevel--;
                    }
                }
            }
        }