public static UdonComment Create(UdonGraphElementData elementData, UdonGraph graph) { var comment = new UdonComment(elementData.jsonData, graph); comment.UpdateFromData(); graph.MarkSceneDirty(); return(comment); }
// Called from Context menu public static UdonComment Create(string value, Rect position, UdonGraph graph) { var comment = new UdonComment("", graph); // make sure rect size is not 0 position.width = position.width > 0 ? position.width : 128; position.height = position.height > 0 ? position.height : 40; comment._customData.layout = position; comment._customData.title = value; comment.UpdateFromData(); graph.MarkSceneDirty(); return(comment); }
private UdonComment(string jsonData, UdonGraph graph) { title = "Comment"; name = "comment"; _graph = graph; capabilities |= Capabilities.Selectable | Capabilities.Movable | Capabilities.Deletable | Capabilities.Resizable; pickingMode = PickingMode.Ignore; type = UdonGraphElementType.UdonComment; if (!string.IsNullOrEmpty(jsonData)) { EditorJsonUtility.FromJsonOverwrite(jsonData, _customData); } _mainContainer = new VisualElement(); _mainContainer.StretchToParentSize(); _mainContainer.AddToClassList("mainContainer"); Add(_mainContainer); _label = new Label(); _label.RegisterCallback <MouseDownEvent>(OnLabelClick); _mainContainer.Add(_label); _textField = new TextField(1000, true, false, '*'); _textField.isDelayed = true; // Support IME _textField.RegisterCallback <FocusInEvent>(evt => { Input.imeCompositionMode = IMECompositionMode.On; }); _textField.RegisterCallback <FocusOutEvent>(evt => { SetText(_textField.text); Input.imeCompositionMode = IMECompositionMode.Auto; SwitchToEditMode(false); }); _textField.OnValueChanged((evt) => { SetText(evt.newValue); SwitchToEditMode(false); }); graph.MarkSceneDirty(); }