public PopupData buildData(PopupData pd, CNode n) { if (pd == null) { pd = new PopupData(); } int cnt = 0; foreach (Preset p in presets) { if (n.GetType().AssemblyQualifiedName == p.NodeID && n.Type == p.NodeType) { cnt++; } } if (pd.presets == null || pd.presets.Length != cnt) { pd.presets = new Preset[cnt]; pd.vals = new string[cnt]; } cnt = 0; foreach (Preset p in presets) { if (n.GetType().AssemblyQualifiedName == p.NodeID && n.Type == p.NodeType) { pd.presets [cnt] = p; pd.vals [cnt] = p.Name; cnt++; } } return(pd); }
// displays preset options, including loading and saving protected void renderPresets() { popupData = CNodeManager.presets.buildData(popupData, this); //GUILayout.Label ("Presets:"); if (popupData.vals.Length != 0) { GUILayout.BeginHorizontal(); GUILayout.Label(" Preset:", GUILayout.Width(labelSize)); popupData.index = EditorGUILayout.Popup(popupData.index, popupData.vals, GUILayout.Width(remainingSize)); GUILayout.EndHorizontal(); size.y += LStyle.FontSize * 1; //3 for presets } if (popupData.index != popupData.newIndex) { popupData.newIndex = popupData.index; popupData.getCurrentPreset().CopyTo(parameters); popupData.name = popupData.getCurrentPreset().Name; keys = rebuildDisplayParams(); PropagateChange(); } if (!editPresets) { return; } popupData.name = GUILayout.TextField(popupData.name, GUILayout.Width(rightSize.x)); // Deciding! if (GUILayout.Button("Save preset", GUILayout.Width(rightSize.x))) { CNodeManager.presets.AddPreset(this, parameters, popupData.name); CNodeManager.presets.Save(LStyle.PresetsFilename); } if (GUILayout.Button("Delete preset", GUILayout.Width(rightSize.x))) { CNodeManager.presets.RemovePreset(popupData.getCurrentPreset()); popupData.index = -1; CNodeManager.presets.Save(LStyle.PresetsFilename); } size.y += LStyle.FontSize * 3; //3 for presets }