private void Initialize(AttachToPanelEvent evt) { // switch event to do some UI updates instead of initialization from here on out UnregisterCallback <AttachToPanelEvent>(Initialize); // this.RegisterCallback<AttachToPanelEvent>(OnAttach); // Add Header Add(new TextElement() { name = "intro", text = "Udon Graph", }); Add(new TextElement() { name = "header-message", text = "The Udon Graph is your gateway to creating amazing things in VRChat.\nCheck out the Readme and UdonExampleScene in the VRChat Examples folder to get started." }); var mainContainer = new VisualElement() { name = "main", }; Add(mainContainer); var template = EditorGUIUtility.Load("Assets/Udon/Editor/Resources/UdonChangelog.uxml") as VisualTreeAsset; var changelog = template.CloneTree(null); changelog.name = "changelog"; mainContainer.Add(changelog); var column2 = new VisualElement() { name = "column-2" }; mainContainer.Add(column2); // Add Button for Last Graph if (!string.IsNullOrEmpty(Settings.LastGraphGuid)) { _openLastGraphButton = new Button(() => { var assetPath = AssetDatabase.GUIDToAssetPath(Settings.LastGraphGuid); var graphName = assetPath.Substring(assetPath.LastIndexOf("/") + 1).Replace(".asset", ""); // Find actual asset from guid var asset = AssetDatabase.LoadAssetAtPath <UdonGraphProgramAsset>(assetPath); if (asset != null) { var w = EditorWindow.GetWindow <UdonGraphWindow>("Udon Graph", true, typeof(SceneView)); // get reference to saved UdonBehaviour if possible UdonBehaviour udonBehaviour = null; string gPath = Settings.LastUdonBehaviourPath; string sPath = Settings.LastUdonBehaviourScenePath; if (!string.IsNullOrEmpty(gPath) && !string.IsNullOrEmpty(sPath)) { var targetScene = EditorSceneManager.GetSceneByPath(sPath); if (targetScene != null && targetScene.isLoaded && targetScene.IsValid()) { var targetObject = GameObject.Find(gPath); if (targetObject != null) { udonBehaviour = targetObject.GetComponent <UdonBehaviour>(); } } } // Initialize graph with restored udonBehaviour or null if not found / not saved w.InitializeGraph(asset, udonBehaviour); } }); UpdateLastGraphButtonLabel(); column2.Add(_openLastGraphButton); } var settingsTemplate = EditorGUIUtility.Load("Assets/Udon/Editor/Resources/UdonSettings.uxml") as VisualTreeAsset; var settings = settingsTemplate.CloneTree(null); settings.name = "settings"; column2.Add(settings); // get reference to first settings section var section = settings.Q("section"); // Add Grid Snap setting var gridSnapContainer = new VisualElement(); gridSnapContainer.AddToClassList("settings-item-container"); var gridSnapField = new IntegerField(3) { value = Settings.GridSnapSize }; #if UNITY_2019_3_OR_NEWER gridSnapField.RegisterValueChangedCallback( #else gridSnapField.OnValueChanged( #endif e => { Settings.GridSnapSize = e.newValue; }); gridSnapContainer.Add(new Label("Grid Snap Size")); gridSnapContainer.Add(gridSnapField); section.Add(gridSnapContainer); var gridSnapLabel = new Label("Snap elements to a grid as you move them. 0 for No Snapping."); gridSnapLabel.AddToClassList("settings-label"); section.Add(gridSnapLabel); // Add Search On Selected Node settings var searchOnSelectedNode = (new Toggle() { text = "Focus Search On Selected Node", value = Settings.SearchOnSelectedNodeRegistry, }); #if UNITY_2019_3_OR_NEWER searchOnSelectedNode.RegisterValueChangedCallback( #else searchOnSelectedNode.OnValueChanged( #endif (toggleEvent) => { Settings.SearchOnSelectedNodeRegistry = toggleEvent.newValue; }); section.Add(searchOnSelectedNode); var searchOnLabel = new Label( "Highlight a node and press Spacebar to open a Search Window focused on nodes for that type. "); searchOnLabel.AddToClassList("settings-label"); section.Add(searchOnLabel); // Add Search On Noodle Drop settings var searchOnNoodleDrop = (new Toggle() { text = "Search On Noodle Drop", value = Settings.SearchOnNoodleDrop, }); #if UNITY_2019_3_OR_NEWER searchOnNoodleDrop.RegisterValueChangedCallback( #else searchOnNoodleDrop.OnValueChanged( #endif (toggleEvent) => { Settings.SearchOnNoodleDrop = toggleEvent.newValue; }); section.Add(searchOnNoodleDrop); var searchOnDropLabel = new Label("Drop a noodle into empty space to search for anything that can be connected."); searchOnDropLabel.AddToClassList("settings-label"); section.Add(searchOnDropLabel); // Add UseNeonStyle setting var useNeonStyle = (new Toggle() { text = "Use Neon Style", value = Settings.UseNeonStyle, }); #if UNITY_2019_3_OR_NEWER useNeonStyle.RegisterValueChangedCallback( #else useNeonStyle.OnValueChanged( #endif (toggleEvent) => { Settings.UseNeonStyle = toggleEvent.newValue; }); section.Add(useNeonStyle); var useNeonStyleLabel = new Label("Try out an experimental Neon Style. We will support User Styles in an upcoming version."); useNeonStyleLabel.AddToClassList("settings-label"); section.Add(useNeonStyleLabel); }
public BlackboardFieldPropertyView(AbstractMaterialGraph graph, IShaderProperty property) { m_Graph = graph; if (property is Vector1ShaderProperty) { VisualElement floatRow = new VisualElement(); VisualElement intRow = new VisualElement(); VisualElement modeRow = new VisualElement(); VisualElement minRow = new VisualElement(); VisualElement maxRow = new VisualElement(); FloatField floatField = null; var floatProperty = (Vector1ShaderProperty)property; if (floatProperty.floatType == FloatType.Integer) { var field = new IntegerField { value = (int)floatProperty.value }; field.OnValueChanged(intEvt => { floatProperty.value = (float)intEvt.newValue; DirtyNodes(); }); intRow = AddRow("Default", field); } else { floatField = new FloatField { value = floatProperty.value }; floatField.OnValueChanged(evt => { floatProperty.value = (float)evt.newValue; DirtyNodes(); }); floatRow = AddRow("Default", floatField); } var floatModeField = new EnumField((Enum)floatProperty.floatType); floatModeField.value = floatProperty.floatType; floatModeField.OnValueChanged(evt => { if (floatProperty.floatType == (FloatType)evt.newValue) { return; } floatProperty = (Vector1ShaderProperty)property; floatProperty.floatType = (FloatType)evt.newValue; switch (floatProperty.floatType) { case FloatType.Slider: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); var field = new FloatField { value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x) }; floatProperty.value = (float)field.value; field.OnValueChanged(defaultEvt => { floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); floatRow = AddRow("Default", field); field.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); modeRow = AddRow("Mode", floatModeField); var minField = new FloatField { value = floatProperty.rangeValues.x }; minField.OnValueChanged(minEvt => { floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); minRow = AddRow("Min", minField); var maxField = new FloatField { value = floatProperty.rangeValues.y }; maxField.OnValueChanged(maxEvt => { floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); maxRow = AddRow("Max", maxField); break; case FloatType.Integer: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); var intField = new IntegerField { value = (int)floatProperty.value }; intField.OnValueChanged(intEvt => { floatProperty.value = (float)intEvt.newValue; DirtyNodes(); }); intRow = AddRow("Default", intField); modeRow = AddRow("Mode", floatModeField); break; default: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); field = new FloatField { value = floatProperty.value }; field.OnValueChanged(defaultEvt => { floatProperty.value = (float)defaultEvt.newValue; DirtyNodes(); }); floatRow = AddRow("Default", field); modeRow = AddRow("Mode", floatModeField); break; } DirtyNodes(); }); modeRow = AddRow("Mode", floatModeField); if (floatProperty.floatType == FloatType.Slider) { var minField = new FloatField { value = floatProperty.rangeValues.x }; minField.OnValueChanged(minEvt => { floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); floatField.value = floatProperty.value; DirtyNodes(); }); minRow = AddRow("Min", minField); var maxField = new FloatField { value = floatProperty.rangeValues.y }; maxField.OnValueChanged(maxEvt => { floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); floatField.value = floatProperty.value; DirtyNodes(); }); maxRow = AddRow("Max", maxField); } } else if (property is Vector2ShaderProperty) { var vectorProperty = (Vector2ShaderProperty)property; var field = new Vector2Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Vector3ShaderProperty) { var vectorProperty = (Vector3ShaderProperty)property; var field = new Vector3Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Vector4ShaderProperty) { var vectorProperty = (Vector4ShaderProperty)property; var field = new Vector4Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ColorShaderProperty) { var colorProperty = (ColorShaderProperty)property; var colorField = new ColorField { value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR }; colorField.OnValueChanged(evt => { colorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", colorField); var colorModeField = new EnumField((Enum)colorProperty.colorMode); colorModeField.OnValueChanged(evt => { if (colorProperty.colorMode == (ColorMode)evt.newValue) { return; } colorProperty.colorMode = (ColorMode)evt.newValue; colorField.hdr = colorProperty.colorMode == ColorMode.HDR; colorField.MarkDirtyRepaint(); DirtyNodes(); }); AddRow("Mode", colorModeField); } else if (property is TextureShaderProperty) { var textureProperty = (TextureShaderProperty)property; var field = new ObjectField { value = textureProperty.value.texture, objectType = typeof(Texture) }; field.OnValueChanged(evt => { textureProperty.value.texture = (Texture)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is CubemapShaderProperty) { var cubemapProperty = (CubemapShaderProperty)property; var field = new ObjectField { value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap) }; field.OnValueChanged(evt => { cubemapProperty.value.cubemap = (Cubemap)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is BooleanShaderProperty) { var booleanProperty = (BooleanShaderProperty)property; Action onBooleanChanged = () => { booleanProperty.value = !booleanProperty.value; DirtyNodes(); }; var field = new Toggle(onBooleanChanged); field.SetValue(booleanProperty.value); AddRow("Default", field); } // AddRow("Type", new TextField()); // AddRow("Exposed", new Toggle(null)); // AddRow("Range", new Toggle(null)); // AddRow("Default", new TextField()); // AddRow("Tooltip", new TextField()); AddToClassList("sgblackboardFieldPropertyView"); }
// TODO: maybe move this to GraphView since it's so connected? private void SetupToolbar() { _toolbar = new Toolbar() { name = "UdonToolbar", }; _rootView.Add(_toolbar); _toolbar.Add(new ToolbarButton(() => { ReloadWelcome(); }) { text = "Welcome" }); _graphAssetName = new Label() { name = "assetName", }; _toolbar.Add(_graphAssetName); _toolbar.Add(new ToolbarFlexSpacer()); _updateOrderField = new VisualElement() { visible = false, }; _updateOrderField.Add(new Label("UpdateOrder")); _updateOrderIntField = new IntegerField() { name = "UpdateOrderIntegerField", value = (_graphAsset == null) ? 0 : _graphAsset.graphData.updateOrder, }; _updateOrderIntField.OnValueChanged(e => { _graphView.graphProgramAsset.graphData.updateOrder = e.newValue; _updateOrderField.visible = false; }); _updateOrderIntField.isDelayed = true; _updateOrderField.Add(_updateOrderIntField); _toolbar.Add(_updateOrderField); _toolbarOptions = new ToolbarMenu { text = "Settings" }; // Show Variables Window _toolbarOptions.menu.AppendAction("Show Variables", (m) => { _graphView.ToggleShowVariables(!_graphView.GetBlackboardVisible()); }, (s) => { return(BoolToStatus(_graphView.GetBlackboardVisible())); }); // Show Minimap _toolbarOptions.menu.AppendAction("Show MiniMap", (m) => { _graphView.ToggleShowMiniMap(!_graphView.GetMinimapVisible()); }, (s) => { return(BoolToStatus(_graphView.GetMinimapVisible())); }); _toolbarOptions.menu.AppendSeparator(); // Show Update Order _toolbarOptions.menu.AppendAction("Show UpdateOrder", (m) => { _updateOrderField.visible = !(m.status == DropdownMenu.MenuAction.StatusFlags.Checked); if (_updateOrderField.visible) { _updateOrderIntField.value = _graphAsset.graphData.updateOrder; } _updateOrderIntField.Focus(); _updateOrderIntField.SelectAll(); }, (s) => { return(BoolToStatus(_updateOrderField.visible)); }); // Search On Noodle Drop _toolbarOptions.menu.AppendAction("Search on Noodle Drop", (m) => { Settings.SearchOnNoodleDrop = !Settings.SearchOnNoodleDrop; }, (s) => { return(BoolToStatus(Settings.SearchOnNoodleDrop)); }); // Search On Selected Node _toolbarOptions.menu.AppendAction("Search on Selected Node", (m) => { Settings.SearchOnSelectedNodeRegistry = !Settings.SearchOnSelectedNodeRegistry; }, (s) => { return(BoolToStatus(Settings.SearchOnSelectedNodeRegistry)); }); _toolbar.Add(_toolbarOptions); _graphCompile = new ToolbarButton(() => { if (_graphAsset != null && _graphAsset is AbstractUdonProgramSource udonProgramSource) { UdonEditorManager.Instance.QueueAndRefreshProgram(udonProgramSource); } }) { text = "Compile" }; _toolbar.Add(_graphCompile); _graphReload = new ToolbarButton(() => { _graphView.Reload(); }) { text = "Reload" }; _toolbar.Add(_graphReload); _graphStatus = new UdonGraphStatus(_rootView); _toolbar.Add(_graphStatus); ShowGraphTools(false); }
public BlackboardFieldPropertyView(AbstractMaterialGraph graph, IShaderProperty property) { AddStyleSheetPath("Styles/ShaderGraphBlackboard"); m_Graph = graph; m_Property = property; m_ExposedToogle = new Toggle(() => { property.generatePropertyBlock = m_ExposedToogle.value; DirtyNodes(ModificationScope.Graph); }); m_ExposedToogle.value = property.generatePropertyBlock; AddRow("Exposed", m_ExposedToogle); m_ReferenceNameField = new TextField(512, false, false, ' '); m_ReferenceNameField.AddStyleSheetPath("Styles/PropertyNameReferenceField"); AddRow("Reference", m_ReferenceNameField); m_ReferenceNameField.value = property.referenceName; m_ReferenceNameField.isDelayed = true; m_ReferenceNameField.OnValueChanged(newName => { string newReferenceName = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid); property.overrideReferenceName = newReferenceName; m_ReferenceNameField.value = property.referenceName; if (string.IsNullOrEmpty(property.overrideReferenceName)) { m_ReferenceNameField.RemoveFromClassList("modified"); } else { m_ReferenceNameField.AddToClassList("modified"); } DirtyNodes(ModificationScope.Graph); UpdateReferenceNameResetMenu(); }); if (!string.IsNullOrEmpty(property.overrideReferenceName)) { m_ReferenceNameField.AddToClassList("modified"); } if (property is Vector1ShaderProperty) { VisualElement floatRow = new VisualElement(); VisualElement intRow = new VisualElement(); VisualElement modeRow = new VisualElement(); VisualElement minRow = new VisualElement(); VisualElement maxRow = new VisualElement(); FloatField floatField = null; var floatProperty = (Vector1ShaderProperty)property; if (floatProperty.floatType == FloatType.Integer) { var field = new IntegerField { value = (int)floatProperty.value }; field.OnValueChanged(intEvt => { floatProperty.value = (float)intEvt.newValue; DirtyNodes(); }); intRow = AddRow("Default", field); } else { floatField = new FloatField { value = floatProperty.value }; floatField.OnValueChanged(evt => { floatProperty.value = (float)evt.newValue; DirtyNodes(); }); floatRow = AddRow("Default", floatField); } var floatModeField = new EnumField((Enum)floatProperty.floatType); floatModeField.value = floatProperty.floatType; floatModeField.OnValueChanged(evt => { if (floatProperty.floatType == (FloatType)evt.newValue) { return; } floatProperty = (Vector1ShaderProperty)property; floatProperty.floatType = (FloatType)evt.newValue; switch (floatProperty.floatType) { case FloatType.Slider: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); var field = new FloatField { value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x) }; floatProperty.value = (float)field.value; field.OnValueChanged(defaultEvt => { floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); floatRow = AddRow("Default", field); field.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); modeRow = AddRow("Mode", floatModeField); var minField = new FloatField { value = floatProperty.rangeValues.x }; minField.OnValueChanged(minEvt => { floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); minRow = AddRow("Min", minField); var maxField = new FloatField { value = floatProperty.rangeValues.y }; maxField.OnValueChanged(maxEvt => { floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); field.value = floatProperty.value; DirtyNodes(); }); maxRow = AddRow("Max", maxField); break; case FloatType.Integer: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); var intField = new IntegerField { value = (int)floatProperty.value }; intField.OnValueChanged(intEvt => { floatProperty.value = (float)intEvt.newValue; DirtyNodes(); }); intRow = AddRow("Default", intField); modeRow = AddRow("Mode", floatModeField); break; default: RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow }); field = new FloatField { value = floatProperty.value }; field.OnValueChanged(defaultEvt => { floatProperty.value = (float)defaultEvt.newValue; DirtyNodes(); }); floatRow = AddRow("Default", field); modeRow = AddRow("Mode", floatModeField); break; } DirtyNodes(); }); modeRow = AddRow("Mode", floatModeField); if (floatProperty.floatType == FloatType.Slider) { var minField = new FloatField { value = floatProperty.rangeValues.x }; minField.OnValueChanged(minEvt => { floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); floatField.value = floatProperty.value; DirtyNodes(); }); minRow = AddRow("Min", minField); var maxField = new FloatField { value = floatProperty.rangeValues.y }; maxField.OnValueChanged(maxEvt => { floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue); floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); floatField.value = floatProperty.value; DirtyNodes(); }); maxRow = AddRow("Max", maxField); } } else if (property is Vector2ShaderProperty) { var vectorProperty = (Vector2ShaderProperty)property; var field = new Vector2Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Vector3ShaderProperty) { var vectorProperty = (Vector3ShaderProperty)property; var field = new Vector3Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Vector4ShaderProperty) { var vectorProperty = (Vector4ShaderProperty)property; var field = new Vector4Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ColorShaderProperty) { var colorProperty = (ColorShaderProperty)property; var colorField = new ColorField { value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR }; colorField.OnValueChanged(evt => { colorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", colorField); var colorModeField = new EnumField((Enum)colorProperty.colorMode); colorModeField.OnValueChanged(evt => { if (colorProperty.colorMode == (ColorMode)evt.newValue) { return; } colorProperty.colorMode = (ColorMode)evt.newValue; colorField.hdr = colorProperty.colorMode == ColorMode.HDR; colorField.MarkDirtyRepaint(); DirtyNodes(); }); AddRow("Mode", colorModeField); } else if (property is TextureShaderProperty) { var textureProperty = (TextureShaderProperty)property; var field = new ObjectField { value = textureProperty.value.texture, objectType = typeof(Texture) }; field.OnValueChanged(evt => { textureProperty.value.texture = (Texture)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Texture2DArrayShaderProperty) { var textureProperty = (Texture2DArrayShaderProperty)property; var field = new ObjectField { value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray) }; field.OnValueChanged(evt => { textureProperty.value.textureArray = (Texture2DArray)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is Texture3DShaderProperty) { var textureProperty = (Texture3DShaderProperty)property; var field = new ObjectField { value = textureProperty.value.texture, objectType = typeof(Texture3D) }; field.OnValueChanged(evt => { textureProperty.value.texture = (Texture3D)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is CubemapShaderProperty) { var cubemapProperty = (CubemapShaderProperty)property; var field = new ObjectField { value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap) }; field.OnValueChanged(evt => { cubemapProperty.value.cubemap = (Cubemap)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is BooleanShaderProperty) { var booleanProperty = (BooleanShaderProperty)property; Action onBooleanChanged = () => { booleanProperty.value = !booleanProperty.value; DirtyNodes(); }; var field = new Toggle(onBooleanChanged); field.value = booleanProperty.value; AddRow("Default", field); } // AddRow("Type", new TextField()); // AddRow("Exposed", new Toggle(null)); // AddRow("Range", new Toggle(null)); // AddRow("Default", new TextField()); // AddRow("Tooltip", new TextField()); AddToClassList("sgblackboardFieldPropertyView"); UpdateReferenceNameResetMenu(); }
public BlackboardFieldPropertyView(AbstractNodeGraph graph, INodeProperty property) { AddStyleSheetPath("Styles/NodeGraphBlackboard"); m_Graph = graph; m_Reference = new TextField(); m_Reference.OnValueChanged(evt => { property.reference = evt.newValue; DirtyNodes(ModificationScope.Graph); }); m_Reference.value = property.reference; AddRow("Reference", m_Reference); if (property is ValueProperty <float> ) { var floatProperty = (ValueProperty <float>)property; FloatField floatField = new FloatField { value = floatProperty.value }; floatField.OnValueChanged(evt => { floatProperty.value = (float)evt.newValue; DirtyNodes(); }); AddRow("Default", floatField); /*if (floatProperty.floatType == FloatType.Slider) * { * var minField = new FloatField { value = floatProperty.rangeValues.x }; * minField.OnValueChanged(minEvt => * { * floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y); * floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); * floatField.value = floatProperty.value; * DirtyNodes(); * }); * minRow = AddRow("Min", minField); * var maxField = new FloatField { value = floatProperty.rangeValues.y }; * maxField.OnValueChanged(maxEvt => * { * floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue); * floatProperty.value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x); * floatField.value = floatProperty.value; * DirtyNodes(); * }); * maxRow = AddRow("Max", maxField); * }*/ } else if (property is ValueProperty <int> ) { var intProperty = (ValueProperty <int>)property; var field = new IntegerField { value = intProperty.value }; field.OnValueChanged(intEvt => { intProperty.value = intEvt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <Vector2> ) { var vectorProperty = (ValueProperty <Vector2>)property; var field = new Vector2Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <Vector3> ) { var vectorProperty = (ValueProperty <Vector3>)property; var field = new Vector3Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <Vector4> ) { var vectorProperty = (ValueProperty <Vector4>)property; var field = new Vector4Field { value = vectorProperty.value }; field.OnValueChanged(evt => { vectorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <Color> ) { var colorProperty = (ValueProperty <Color>)property; //todo add HDR var colorField = new ColorField { value = (Color)property.defaultValue, showEyeDropper = false }; colorField.OnValueChanged(evt => { colorProperty.value = evt.newValue; DirtyNodes(); }); AddRow("Default", colorField); } else if (property is ValueProperty <Texture2D> ) { var textureProperty = (ValueProperty <Texture2D>)property; var field = new ObjectField { value = textureProperty.value, objectType = typeof(Texture2D) }; field.OnValueChanged(evt => { textureProperty.value = (Texture2D)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <Cubemap> ) { var cubemapProperty = (ValueProperty <Cubemap>)property; var field = new ObjectField { value = cubemapProperty.value, objectType = typeof(Cubemap) }; field.OnValueChanged(evt => { cubemapProperty.value = (Cubemap)evt.newValue; DirtyNodes(); }); AddRow("Default", field); } else if (property is ValueProperty <bool> ) { var booleanProperty = (ValueProperty <bool>)property; EventCallback <ChangeEvent <bool> > onBooleanChanged = evt => { booleanProperty.value = evt.newValue; DirtyNodes(); }; var field = new Toggle(); field.OnValueChanged(onBooleanChanged); field.value = booleanProperty.value; AddRow("Default", field); } // AddRow("Type", new TextField()); // AddRow("Exposed", new Toggle(null)); // AddRow("Range", new Toggle(null)); // AddRow("Default", new TextField()); // AddRow("Tooltip", new TextField()); AddToClassList("sgblackboardFieldPropertyView"); }