override public void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //Get the ElementBase for which this Property Drawer is used. ElementBase eb = fieldInfo.GetValue(property.serializedObject.targetObject) as ElementBase; //Add the diagram ID in the label. if (eb?.DiagMapping != null) { //label.text += " [" + eb.DiagMapping.DiagramElementID + "]"; } label = EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, label); //This will change the value of position (see docs of PrefixLabel). //Get Scriptable Object with Control Panel Graphics. if (cpGraphics == null) { string assetGUID = AssetDatabase.FindAssets("t:MnCPanelGraphics")[0]; string path = AssetDatabase.GUIDToAssetPath(assetGUID); cpGraphics = (MnCPanelGraphics)AssetDatabase.LoadAssetAtPath <ScriptableObject>(path); } else { //Draw the Machinations Icon. GUIContent icon = new GUIContent(cpGraphics.MachinationsIcon); Rect iconPosition = new Rect(position); iconPosition.x -= 42; //Because 42 :). EditorGUI.LabelField(iconPosition, icon); } //Get the Base Value from ElementBase's member. SerializedProperty baseValueProp = property.FindPropertyRelative("_serializableValue"); //Store it here. int baseValue = baseValueProp.intValue; //Can only proceed if we have an ElementBase to work with. if (eb == null) { return; } //Edit. EditorGUI.BeginChangeCheck(); int newValue = EditorGUI.IntField(position, baseValue); //Get new value. if (EditorGUI.EndChangeCheck()) { /* * baseValueProp.intValue = newValue; //Store the new value. * L.D("Set basevalue to " + newValue); * L.D("The element's value is " + eb.CurrentValue); */ baseValueProp.intValue = newValue; L.T("Set basevalue to " + newValue); eb.ChangeValueFromEditor(newValue); L.T("The element's value is " + eb.CurrentValue); } EditorGUI.EndProperty(); }
/// <summary> /// Draws the Machionations Control Panel GUI. /// </summary> void OnGUI() { //Wait until MnConfig instance is created. if (MnConfig.Instance == null && MnConfig.HasSettings) { return; } if (!_restoredFromSettings && MnConfig.HasSettings && MnConfig.Instance != null) { _restoredFromSettings = true; _APIURL = MnConfig.Instance.APIURL; _userKey = MnConfig.Instance.UserKey; _gameName = MnConfig.Instance.GameName; _diagramToken = MnConfig.Instance.DiagramToken; } EditorGUI.BeginChangeCheck(); GUILayout.Label("Machinations.io Connection Settings", EditorStyles.boldLabel); _APIURL = EditorGUILayout.TextField("API URL", _APIURL); _userKey = EditorGUILayout.TextField("User Key", _userKey); _gameName = EditorGUILayout.TextField("Game Name", _gameName); _diagramToken = EditorGUILayout.TextField("Diagram Token", _diagramToken); PopupSearchList.DrawLineInInspector(Color.black, 2, 10); //If it's not there yet, get Scriptable Object with Control Panel Graphics. if (_cpGraphics == null) { string assetGUID = AssetDatabase.FindAssets("t:MnCPanelGraphics")[0]; string path = AssetDatabase.GUIDToAssetPath(assetGUID); _cpGraphics = (MnCPanelGraphics)AssetDatabase.LoadAssetAtPath <ScriptableObject>(path); } //Now we can initialize the list of MachinationsElementType (which inherit from ITagProvider, used to provide custom //graphics to the PopupSearchList component). else { //Initialize only if required. if (_usedTypes == null) { _usedTypes = new Dictionary <string, MnElementTypeTagProvider> { { "Pool", new MnElementTypeTagProvider { Aspect = _cpGraphics.Pool, Name = "Pool" } }, { "Drain", new MnElementTypeTagProvider { Aspect = _cpGraphics.Drain, Name = "Drain" } }, { "State Connection", new MnElementTypeTagProvider { Aspect = _cpGraphics.StateConnection, Name = "State Connection" } }, { "Resource Connection", new MnElementTypeTagProvider { Aspect = _cpGraphics.ResourceConnection, Name = "Resource Connection" } }, { "End Condition", new MnElementTypeTagProvider { Aspect = _cpGraphics.EndCondition, Name = "End Condition" } }, { "Delay", new MnElementTypeTagProvider { Aspect = _cpGraphics.Delay, Name = "Delay" } }, { "Register", new MnElementTypeTagProvider { Aspect = _cpGraphics.Register, Name = "Register" } }, { "Converter", new MnElementTypeTagProvider { Aspect = _cpGraphics.Converter, Name = "Converter" } }, { "Trader", new MnElementTypeTagProvider { Aspect = _cpGraphics.Trader, Name = "Trader" } }, { "Gate", new MnElementTypeTagProvider { Aspect = _cpGraphics.Gate, Name = "Gate" } }, { "Source", new MnElementTypeTagProvider { Aspect = _cpGraphics.Source, Name = "Source" } }, }; } } //Setup PopupSearchList for importing Machinations Elements. if (_usedTypes != null && GUILayout.Button("Import Elements", GUILayout.Width(200))) { List <DiagramMapping> currentMappings = MnDataLayer.GetRegisteredMappings(); List <SearchListItem> searchListItems = new List <SearchListItem>(); foreach (DiagramMapping dm in currentMappings) { //No type specified? Cannot show such items. if (dm.Type == null) { continue; } //Handling NULL labels. if (dm.Label == null) { dm.Label = "[no label]"; } //Temporary fix of corrupted diagram elements. dm.Label = dm.Label.Replace("<span>", ""); dm.Label = dm.Label.Replace("</span>", ""); dm.Label = dm.Label.Replace("<span/>", ""); dm.Label = dm.Label.Replace("<br>", ""); dm.Label = dm.Label.Replace("</br>", ""); dm.Label = dm.Label.Replace("<br/>", ""); //Now create the SearchListItem. var sli = new SearchListItem { ID = dm.DiagramElementID, Name = dm.Label, TagProvider = _usedTypes[dm.Type], AttachedObject = dm }; searchListItems.Add(sli); } //The Popup will be shown immediately next to the button. PopupWindow.Show(_btnImportElementsRect, new PopupSearchList(Screen.width, searchListItems, new List <ITagProvider>(_usedTypes.Values))); } //Save buttonRect position so that we know where to place the PopupSearchList. //GetLastRect will return the Rect of the last-painted element, which in this case is the call to GUILayout.Button above. if (Event.current.type == EventType.Repaint) { _btnImportElementsRect = GUILayoutUtility.GetLastRect(); } EditorGUILayout.Separator(); if (GUI.changed) { SaveMachinationsConfig(); } }