From eb84bb298d2b95aec7b2ae12cbf25ac64f25379a Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 6 Nov 2022 15:12:42 -0500 Subject: move to self host --- .../Scripts/Editor/ModularShaderSystem.meta | 8 + .../Editor/ModularShaderSystem/Editors.meta | 8 + .../ModularShaderSystem/Editors/Components.meta | 8 + .../Editors/Components/FunctionTimeline.cs | 651 +++++++++++++++ .../Editors/Components/FunctionTimeline.cs.meta | 11 + .../Editors/Components/TemplateGraph.cs | 293 +++++++ .../Editors/Components/TemplateGraph.cs.meta | 11 + .../ModularShaderSystem/Editors/Drawers.meta | 8 + .../Editors/Drawers/EnablePropertyDrawer.cs | 30 + .../Editors/Drawers/EnablePropertyDrawer.cs.meta | 11 + .../Editors/Drawers/FunctionPropertyDrawer.cs | 32 + .../Editors/Drawers/FunctionPropertyDrawer.cs.meta | 11 + .../Drawers/ModuleTemplatePropertyDrawer.cs | 29 + .../Drawers/ModuleTemplatePropertyDrawer.cs.meta | 11 + .../Editors/Drawers/PropertyAttributeDrawer.cs | 52 ++ .../Drawers/PropertyAttributeDrawer.cs.meta | 11 + .../Editors/Drawers/ShaderPropertyDrawer.cs | 289 +++++++ .../Editors/Drawers/ShaderPropertyDrawer.cs.meta | 11 + .../Editors/Drawers/VariablePropertyDrawer.cs | 43 + .../Editors/Drawers/VariablePropertyDrawer.cs.meta | 11 + .../ModularShaderSystem/Editors/Elements.meta | 8 + .../Editors/Elements/CodeViewElement.cs | 104 +++ .../Editors/Elements/CodeViewElement.cs.meta | 11 + .../Editors/Elements/InspectorList.cs | 324 +++++++ .../Editors/Elements/InspectorList.cs.meta | 11 + .../Editors/Elements/LabelField.cs | 56 ++ .../Editors/Elements/LabelField.cs.meta | 11 + .../Editors/Elements/ModuleInspectorList.cs | 315 +++++++ .../Editors/Elements/ModuleInspectorList.cs.meta | 11 + .../Editors/Elements/VariableField.cs | 30 + .../Editors/Elements/VariableField.cs.meta | 11 + .../ModularShaderSystem/Editors/Inspectors.meta | 8 + .../Editors/Inspectors/ModularShaderEditor.cs | 68 ++ .../Editors/Inspectors/ModularShaderEditor.cs.meta | 11 + .../Editors/Inspectors/ShaderModuleEditor.cs | 23 + .../Editors/Inspectors/ShaderModuleEditor.cs.meta | 11 + .../Editors/Inspectors/TemplateAssetEditor.cs | 20 + .../Editors/Inspectors/TemplateAssetEditor.cs.meta | 11 + .../ModularShaderSystem/Editors/Windows.meta | 8 + .../Editors/Windows/Migrator.cs | 814 ++++++++++++++++++ .../Editors/Windows/Migrator.cs.meta | 11 + .../Editors/Windows/ModularShaderDebugger.cs | 153 ++++ .../Editors/Windows/ModularShaderDebugger.cs.meta | 11 + .../Editors/Windows/TextPopup.cs | 20 + .../Editors/Windows/TextPopup.cs.meta | 11 + .../Scripts/Editor/ModularShaderSystem/LICENSE | 21 + .../Editor/ModularShaderSystem/LICENSE.meta | 7 + .../Editor/ModularShaderSystem/MSSConstants.cs | 21 + .../ModularShaderSystem/MSSConstants.cs.meta | 11 + .../ModularShaderSystemDefinition.asmdef | 15 + .../ModularShaderSystemDefinition.asmdef.meta | 7 + .../Editor/ModularShaderSystem/Resources.meta | 8 + .../ModularShaderSystem/Resources/POIMSS.meta | 8 + .../Resources/POIMSS/MSSDeleteIcon.png | Bin 0 -> 2891 bytes .../Resources/POIMSS/MSSDeleteIcon.png.meta | 104 +++ .../Resources/POIMSS/MSSDownIcon.png | Bin 0 -> 1578 bytes .../Resources/POIMSS/MSSDownIcon.png.meta | 104 +++ .../Resources/POIMSS/MSSUIElements.meta | 8 + .../POIMSS/MSSUIElements/EnablePropertyDrawer.uxml | 6 + .../MSSUIElements/EnablePropertyDrawer.uxml.meta | 10 + .../MSSUIElements/FunctionPropertyDrawer.uxml | 9 + .../MSSUIElements/FunctionPropertyDrawer.uxml.meta | 10 + .../POIMSS/MSSUIElements/FunctionTimelineStyle.uss | 173 ++++ .../MSSUIElements/FunctionTimelineStyle.uss.meta | 3 + .../POIMSS/MSSUIElements/FunctionView.uxml | 9 + .../POIMSS/MSSUIElements/FunctionView.uxml.meta | 10 + .../POIMSS/MSSUIElements/InspectorList.uss | 139 +++ .../POIMSS/MSSUIElements/InspectorList.uss.meta | 11 + .../POIMSS/MSSUIElements/MigratorDark.uss | 43 + .../POIMSS/MSSUIElements/MigratorDark.uss.meta | 3 + .../POIMSS/MSSUIElements/MigratorLight.uss | 42 + .../POIMSS/MSSUIElements/MigratorLight.uss.meta | 3 + .../MSSUIElements/ModularShaderDebuggerStyle.uss | 37 + .../ModularShaderDebuggerStyle.uss.meta | 3 + .../POIMSS/MSSUIElements/ModularShaderEditor.uxml | 17 + .../MSSUIElements/ModularShaderEditor.uxml.meta | 10 + .../ModuleTemplatePropertyDrawer.uxml | 6 + .../ModuleTemplatePropertyDrawer.uxml.meta | 10 + .../POIMSS/MSSUIElements/PropertyView.uxml | 6 + .../POIMSS/MSSUIElements/PropertyView.uxml.meta | 10 + .../POIMSS/MSSUIElements/ShaderModuleEditor.uxml | 16 + .../MSSUIElements/ShaderModuleEditor.uxml.meta | 10 + .../POIMSS/MSSUIElements/ShaderPropertyDrawer.uxml | 9 + .../MSSUIElements/ShaderPropertyDrawer.uxml.meta | 10 + .../POIMSS/MSSUIElements/TemplateGraphStyle.uss | 15 + .../MSSUIElements/TemplateGraphStyle.uss.meta | 3 + .../MSSUIElements/VariablePropertyDrawer.uxml | 5 + .../MSSUIElements/VariablePropertyDrawer.uxml.meta | 10 + .../Resources/POIMSS/MSSUpIcon.png | Bin 0 -> 1572 bytes .../Resources/POIMSS/MSSUpIcon.png.meta | 104 +++ .../Resources/POIMSS/ModularShaderIcon.png | Bin 0 -> 8796 bytes .../Resources/POIMSS/ModularShaderIcon.png.meta | 104 +++ .../Resources/POIMSS/RobotoMono-Regular.ttf | Bin 0 -> 86908 bytes .../Resources/POIMSS/RobotoMono-Regular.ttf.meta | 3 + .../Resources/POIMSS/ShaderModuleIcon.png | Bin 0 -> 3518 bytes .../Resources/POIMSS/ShaderModuleIcon.png.meta | 104 +++ .../Resources/POIMSS/TemplateCollectionIcon.png | Bin 0 -> 5121 bytes .../POIMSS/TemplateCollectionIcon.png.meta | 104 +++ .../Resources/POIMSS/TemplateIcon.png | Bin 0 -> 1470 bytes .../Resources/POIMSS/TemplateIcon.png.meta | 104 +++ .../Editor/ModularShaderSystem/Scriptables.meta | 8 + .../Scriptables/EnableProperty.cs | 60 ++ .../Scriptables/EnableProperty.cs.meta | 11 + .../Scriptables/ModularShader.cs | 41 + .../Scriptables/ModularShader.cs.meta | 11 + .../Scriptables/ModuleTemplate.cs | 19 + .../Scriptables/ModuleTemplate.cs.meta | 11 + .../ModularShaderSystem/Scriptables/Property.cs | 89 ++ .../Scriptables/Property.cs.meta | 11 + .../Scriptables/ShaderFunction.cs | 25 + .../Scriptables/ShaderFunction.cs.meta | 11 + .../Scriptables/ShaderModule.cs | 34 + .../Scriptables/ShaderModule.cs.meta | 11 + .../Scriptables/TemplateAsset.cs | 48 ++ .../Scriptables/TemplateAsset.cs.meta | 11 + .../Scriptables/TemplateAssetImporter.cs | 39 + .../Scriptables/TemplateAssetImporter.cs.meta | 11 + .../Scriptables/TemplateCollectionAsset.cs | 47 ++ .../Scriptables/TemplateCollectionAsset.cs.meta | 11 + .../Scriptables/TemplateCollectionAssetImporter.cs | 86 ++ .../TemplateCollectionAssetImporter.cs.meta | 11 + .../ModularShaderSystem/Scriptables/Variable.cs | 138 +++ .../Scriptables/Variable.cs.meta | 11 + .../Editor/ModularShaderSystem/ShaderGenerator.cs | 930 +++++++++++++++++++++ .../ModularShaderSystem/ShaderGenerator.cs.meta | 11 + .../ShaderStringBuilderExtensions.cs | 103 +++ .../ShaderStringBuilderExtensions.cs.meta | 11 + 127 files changed, 6906 insertions(+) create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ModularShaderEditor.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ModularShaderEditor.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ShaderModuleEditor.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ShaderModuleEditor.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/TemplateAssetEditor.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/TemplateAssetEditor.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/Migrator.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/Migrator.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/ModularShaderDebugger.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/ModularShaderDebugger.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/TextPopup.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Windows/TextPopup.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/LICENSE create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/LICENSE.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/MSSConstants.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/MSSConstants.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ModularShaderSystemDefinition.asmdef create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ModularShaderSystemDefinition.asmdef.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSDeleteIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSDeleteIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSDownIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSDownIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/EnablePropertyDrawer.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/EnablePropertyDrawer.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionPropertyDrawer.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionPropertyDrawer.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionTimelineStyle.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionTimelineStyle.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionView.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/FunctionView.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/InspectorList.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/InspectorList.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/MigratorDark.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/MigratorDark.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/MigratorLight.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/MigratorLight.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModularShaderDebuggerStyle.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModularShaderDebuggerStyle.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModularShaderEditor.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModularShaderEditor.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModuleTemplatePropertyDrawer.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ModuleTemplatePropertyDrawer.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/PropertyView.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/PropertyView.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ShaderModuleEditor.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ShaderModuleEditor.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ShaderPropertyDrawer.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/ShaderPropertyDrawer.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/TemplateGraphStyle.uss create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/TemplateGraphStyle.uss.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/VariablePropertyDrawer.uxml create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUIElements/VariablePropertyDrawer.uxml.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUpIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/MSSUpIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/ModularShaderIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/ModularShaderIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/RobotoMono-Regular.ttf create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/RobotoMono-Regular.ttf.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/ShaderModuleIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/ShaderModuleIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/TemplateCollectionIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/TemplateCollectionIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/TemplateIcon.png create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Resources/POIMSS/TemplateIcon.png.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/EnableProperty.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/EnableProperty.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ModularShader.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ModularShader.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ModuleTemplate.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ModuleTemplate.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/Property.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/Property.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ShaderFunction.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ShaderFunction.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ShaderModule.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/ShaderModule.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateAsset.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateAsset.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateAssetImporter.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateCollectionAsset.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/TemplateCollectionAssetImporter.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/Variable.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Scriptables/Variable.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ShaderGenerator.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ShaderGenerator.cs.meta create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ShaderStringBuilderExtensions.cs create mode 100644 VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/ShaderStringBuilderExtensions.cs.meta (limited to 'VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor') diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem.meta new file mode 100644 index 00000000..1ad97692 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b6214b5cc59f18046a3a257c6d8731cc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors.meta new file mode 100644 index 00000000..6d4a06a0 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ba88caeb15a1b0469773b278aa26bab +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components.meta new file mode 100644 index 00000000..1352cc98 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 13fa33428f9f4a84b8e3dc4bfedd6e64 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs new file mode 100644 index 00000000..101adaa6 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs @@ -0,0 +1,651 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using Poiyomi.ModularShaderSystem.UI; + +namespace Poiyomi.ModularShaderSystem.Debug +{ + public class FunctionTimeline : IModularShaderDebuggerTab + { + public VisualElement TabContainer { get; set; } + public string TabName { get; set; } + + public FunctionTimeline() + { + TabName = "Function Timeline"; + TabContainer = new VisualElement(); + + var styleSheet = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/FunctionTimelineStyle"); + TabContainer.styleSheets.Add(styleSheet); + TabContainer.style.flexGrow = 1; + } + + public void UpdateTab(ModularShader shader) + { + TabContainer.Clear(); + if (shader == null) return; + TabContainer.Add(new TimelineContainer(shader)); + } + } + + internal class FunctionItem : VisualElement + { + public ShaderFunction Function { get; } + public TimelineRow Row { get; set; } + public int Size { get; } + public int Offset { get; } + + private TimelineRoot _root; + + public FunctionItem(TimelineRoot root, ShaderFunction function, int size, int offset) + { + _root = root; + Function = function; + Size = size; + Offset = offset; + + style.left = Offset; + style.width = Size; + + var label = new Label(Function.Name); + label.AddToClassList("function-header-name"); + var queue = new Label("" + Function.Queue); + queue.AddToClassList("function-header-queue"); + Add(label); + Add(queue); + + RegisterCallback(evt => + { + if (evt.button != 0) return; + _root.SelectedFunction = this; + }); + } + } + + internal class TimelineRow : VisualElement + { + public ShaderModule Module { get; } + + public List Functions { get; set; } + + private VisualElement _title; + public VisualElement _content; + public List _contentChilden; + + public TimelineRow(ShaderModule module) + { + Module = module; + + Functions = new List(); + _contentChilden = new List(); + + _title = new VisualElement(); + _content = new VisualElement(); + _title.AddToClassList("timeline-title"); + _content.AddToClassList("timeline-content"); + + _title.Add(new Label(Module.Name)); + + Add(_content); + Add(_title); + } + + public void SetContentSize(int size) + { + _content.style.width = size; + } + + public void ApplyFunctionsToTimeline() + { + _content.Clear(); + _contentChilden.Clear(); + + for (int index = Functions.Count - 1; index >= 0; index--) + { + FunctionItem function = Functions[index]; + int counter = 0; + bool found = false; + var functionStart = function.Offset; + var functionEnd = function.Offset + function.Size; + while (counter < _contentChilden.Count) + { + if (!TimelineBusyAt(_contentChilden[counter], functionStart, functionEnd)) + { + _contentChilden[counter].Add(function); + function.Row = this; + found = true; + break; + } + counter++; + } + if (found) continue; + var newRow = new VisualElement(); + newRow.AddToClassList("timeline-content-row"); + _contentChilden.Add(newRow); + _content.Add(newRow); + newRow.Add(function); + function.Row = this; + } + } + + private static bool TimelineBusyAt(VisualElement content, int functionStart, int functionEnd) + { + return content.Children().Cast().Any(x => functionStart < x.Offset + x.Size && functionStart > x.Offset && functionEnd <= x.Offset + x.Size); + } + + public void SetRowsHeight() + { + foreach (VisualElement element in _contentChilden) + element.style.height = element[0].resolvedStyle.height + 8; + } + } + + internal class TimelineRoot : VisualElement + { + public List Rows { get; set; } + public List Functions { get; set; } + + public FunctionItem SelectedFunction + { + get => _selectedFunction; + set + { + _selectedFunction = value; + ResetSelectedClass(); + OnSelectedFunctionChanged?.Invoke(_selectedFunction); + } + } + + public string Keyword { get; } + + public Action OnSelectedFunctionChanged { get; set; } + public Action OnTimelineFirstDispatch { get; set; } + + private readonly Dictionary _moduleByFunction; + private FunctionItem _selectedFunction; + + public TimelineRoot(Dictionary moduleByFunction, List allFunctions, string rootKeyword) + { + Keyword = rootKeyword; + Rows = new List(); + Functions = new List(); + int offset = 0; + _moduleByFunction = moduleByFunction; + foreach (var fn in allFunctions.Where(x => x.AppendAfter.Equals(rootKeyword)).OrderBy(x => x.Queue)) + { + offset += CreateFunctionHierarchy(allFunctions, fn, offset); + } + + foreach (TimelineRow row in Rows) + { + Add(row); + row.SetContentSize(offset + 30); + row.ApplyFunctionsToTimeline(); + } + + RegisterCallback(GeometryChangedCallback); + } + + private void GeometryChangedCallback(GeometryChangedEvent evt) + { + UnregisterCallback(GeometryChangedCallback); + + foreach (TimelineRow row in Rows) + { + row.SetRowsHeight(); + } + + OnTimelineFirstDispatch?.Invoke(); + } + + private int CreateFunctionHierarchy(List functions, ShaderFunction function, int offset) + { + int size = 0; + var module = _moduleByFunction[function]; + var row = Rows.FirstOrDefault(x => x.Module == module); + if (row == null) + { + row = new TimelineRow(module); + Rows.Add(row); + } + + foreach (var fn in functions.Where(x => x.AppendAfter.Equals(function.Name)).OrderBy(x => x.Queue)) + size += CreateFunctionHierarchy(functions, fn, offset + size + 30); + + if (size == 0) size = 224; + else size += 30; + + var functionItem = new FunctionItem(this, function, size - 4, offset); + row.Functions.Add(functionItem); + Functions.Add(functionItem); + + return size; + } + + public float GetScrollAdjustment() + { + float factor = 1.1f; + if (Rows.Count <= 0) return factor; + + var width = Rows[0]._content.style.width.value.value; + var screenWidth = Rows[0]._content.resolvedStyle.width; + factor = screenWidth / width; + + return factor; + } + + public void Scroll(float f) + { + foreach (TimelineRow row in Rows) + { + var width = row._content.style.width.value.value; + var screenWidth = row._content.resolvedStyle.width; + if(width > screenWidth) + row._content.style.left = -((width- screenWidth) * f); + } + } + + public void ResetSelectedClass() + { + foreach (FunctionItem function in Functions) + { + if (function == SelectedFunction && !function.ClassListContains("selected-function")) + function.AddToClassList("selected-function"); + else if (function != SelectedFunction && function.ClassListContains("selected-function")) + function.RemoveFromClassList("selected-function"); + } + } + } + + internal class VariablesViewer : VisualElement + { + public Action OnVariableSelected { get; set; } + + private List _variables; + + public VariablesViewer(ModularShader shader) + { + var variables = shader.BaseModules.Concat(shader.AdditionalModules).SelectMany(x => x.Functions).SelectMany(x => x.UsedVariables).Distinct().OrderBy(x => x.Type).ThenBy(x => x.Name); + + var title = new Label("Variables List"); + title.AddToClassList("area-title"); + var content = new ScrollView(ScrollViewMode.Vertical); + content.AddToClassList("area-content"); + + _variables = new List(); + + foreach (Variable variable in variables) + { + var element = new VariableField(variable); + _variables.Add(element); + content.Add(element); + + element.RegisterCallback(evt => + { + if (evt.button != 0) return; + foreach (VariableField field in _variables) + { + if (field.ClassListContains("selected-variable-global")) + field.RemoveFromClassList("selected-variable-global"); + } + + element.AddToClassList("selected-variable-global"); + OnVariableSelected?.Invoke(element.Variable); + }); + } + + Add(title); + Add(content); + } + } + + internal class FunctionViewer : VisualElement + { + public ShaderFunction SelectedItem + { + get => _selectedItem; + set + { + _selectedItem = value; + _appendAfter.Value = _selectedItem?.AppendAfter; + _name.Value = _selectedItem?.Name; + _queue.Value = "" + _selectedItem?.Queue; + + _variables.Clear(); + _variablesFoldout.Clear(); + _variableKeywordsFoldout.Clear(); + _codeKeywordsFoldout.Clear(); + if (_selectedItem == null) + { + OnVariableSelected?.Invoke(null); + return; + } + + foreach (Variable variable in _selectedItem.UsedVariables) + { + var element = new VariableField(variable); + _variables.Add(element); + _variablesFoldout.Add(element); + + element.RegisterCallback(evt => + { + if (evt.button != 0) return; + foreach (VariableField field in _variables) + { + if (field.ClassListContains("selected-variable")) + field.RemoveFromClassList("selected-variable"); + } + element.AddToClassList("selected-variable"); + OnVariableSelected?.Invoke(element.Variable); + }); + } + + + foreach (string keyword in _selectedItem.VariableKeywords) + _variableKeywordsFoldout.Add(new Label(keyword)); + if(_variableKeywordsFoldout.childCount == 0) + _variableKeywordsFoldout.Add(new Label("None")); + + foreach (string keyword in _selectedItem.CodeKeywords) + _codeKeywordsFoldout.Add(new Label(keyword)); + if(_codeKeywordsFoldout.childCount == 0) + _codeKeywordsFoldout.Add(new Label("None")); + } + } + + public Action OnVariableSelected { get; set; } + + private LabelField _appendAfter; + private LabelField _name; + private LabelField _queue; + private ShaderFunction _selectedItem; + private Foldout _variablesFoldout; + private List _variables; + private readonly Foldout _variableKeywordsFoldout; + private readonly Foldout _codeKeywordsFoldout; + + public FunctionViewer() + { + var title = new Label("Selected function information"); + title.AddToClassList("area-title"); + var content = new ScrollView(ScrollViewMode.Vertical); + content.AddToClassList("area-content"); + + _name = new LabelField("Name", ""); + _appendAfter = new LabelField("Append After", ""); + _queue = new LabelField("Queue", ""); + + _variablesFoldout = new Foldout(); + _variablesFoldout.text = "Variables"; + _variables = new List(); + + _variableKeywordsFoldout = new Foldout(); + _variableKeywordsFoldout.text = "Variable Keywords"; + + _codeKeywordsFoldout = new Foldout(); + _codeKeywordsFoldout.text = "Code Keywords"; + + Add(title); + Add(content); + content.Add(_name); + content.Add(_appendAfter); + content.Add(_queue); + content.Add(_variablesFoldout); + content.Add(_variableKeywordsFoldout); + content.Add(_codeKeywordsFoldout); + } + } + + internal class ModuleViewer : VisualElement + { + public ShaderModule SelectedItem + { + get => _selectedItem; + set + { + _selectedItem = value; + if (_selectedItem == null) + { + _name.Value = null; + _id.Value = null; + _description.Value =null; + _author.Value = null; + _version.Value = null; + if(_content.Contains(_selectButton)) _content.Remove(_selectButton); + return; + } + _name.Value = _selectedItem.Name; + _id.Value = _selectedItem.Id; + _description.Value = _selectedItem.Description; + _author.Value = _selectedItem.Author; + _version.Value = _selectedItem.Version; + + if(!_content.Contains(_selectButton)) _content.Add(_selectButton); + } + } + + private ShaderModule _selectedItem; + private readonly LabelField _name; + private readonly LabelField _id; + private readonly LabelField _author; + private readonly LabelField _description; + private readonly LabelField _version; + private Button _selectButton; + private ScrollView _content; + + public ModuleViewer() + { + var title = new Label("Function's module base info"); + title.AddToClassList("area-title"); + var content = new ScrollView(ScrollViewMode.Vertical); + _content = content; + _content.AddToClassList("area-content"); + + _name = new LabelField("Name", ""); + _id = new LabelField("Id", ""); + _author = new LabelField("Author", ""); + _description = new LabelField("Description", ""); + _version = new LabelField("Version", ""); + + _selectButton = new Button(() => + { + if (_selectedItem == null) return; + Selection.SetActiveObjectWithContext(_selectedItem,_selectedItem); + }); + + _selectButton.text = "Select module in inspector"; + + Add(title); + Add(_content); + + _content.Add(_name); + _content.Add(_id); + _content.Add(_author); + _content.Add(_description); + _content.Add(_version); + } + } + + internal class FunctionTemplateViewer : VisualElement + { + public string SelectedItem + { + get => _selectedItem; + set + { + _selectedItem = value; + _viewer.Text = _selectedItem; + } + } + + private CodeViewElement _viewer; + private string _selectedItem; + + public FunctionTemplateViewer() + { + _viewer = new CodeViewElement(); + + var title = new Label("Function code template"); + title.AddToClassList("area-title"); + + Add(title); + Add(_viewer); + } + } + + internal class TimelineContainer : VisualElement + { + private List _roots; + private PopupField _popup; + + public TimelineContainer(ModularShader shader) + { + var left = new VisualElement(); + var right = new VisualElement(); + var bot = new VisualElement(); + var templateViewer = new FunctionTemplateViewer(); + var variablesViewer = new VariablesViewer(shader); + var functionViewer = new FunctionViewer(); + var moduleViewer = new ModuleViewer(); + + left.style.flexShrink = 0; + left.style.width = new StyleLength(Length.Percent(70)); + right.style.width = new StyleLength(Length.Percent(30)); + bot.style.height = new StyleLength(Length.Percent(50)); + bot.style.flexDirection = FlexDirection.Row; + style.flexDirection = FlexDirection.Row; + Add(left); + Add(right); + + var scroller = new Scroller(0,1,f => + { + _popup.value.Scroll(f); + }, SliderDirection.Horizontal); + + _roots = new List(); + var functions = new List(); + Dictionary moduleByFunction = new Dictionary(); + + foreach (var module in shader.BaseModules) + { + functions.AddRange(module.Functions); + foreach (var function in module.Functions) + if (!moduleByFunction.ContainsKey(function)) + moduleByFunction.Add(function, module); + } + + foreach (var module in shader.AdditionalModules) + { + functions.AddRange(module.Functions); + foreach (var function in module.Functions) + if (!moduleByFunction.ContainsKey(function)) + moduleByFunction.Add(function, module); + } + + foreach (var keyword in functions.Select(x => x.AppendAfter).Distinct().Where(x => x.StartsWith("#K#"))) + { + var root = new TimelineRoot(moduleByFunction, functions, keyword); + root.OnSelectedFunctionChanged = item => + { + functionViewer.SelectedItem = item.Function; + moduleViewer.SelectedItem = item.Row.Module; + templateViewer.SelectedItem = item.Function.ShaderFunctionCode == null ? null : item.Function.ShaderFunctionCode.Template; + + variablesViewer.OnVariableSelected = variable => + { + foreach (FunctionItem f in root.Functions) + { + bool toHighlight = f.Function.UsedVariables.Any(x => x == variable); + + if(toHighlight && !f.ClassListContains("contains-variable-global")) + f.AddToClassList("contains-variable-global"); + if(!toHighlight && f.ClassListContains("contains-variable-global")) + f.RemoveFromClassList("contains-variable-global"); + } + }; + + functionViewer.OnVariableSelected = variable => + { + foreach (FunctionItem f in root.Functions) + { + bool toHighlight = f.Function.UsedVariables.Any(x => x == variable); + + if(toHighlight && !f.ClassListContains("contains-variable")) + f.AddToClassList("contains-variable"); + if(!toHighlight && f.ClassListContains("contains-variable")) + f.RemoveFromClassList("contains-variable"); + } + }; + + foreach (FunctionItem f in root.Functions) + { + if(f.ClassListContains("contains-variable")) + f.RemoveFromClassList("contains-variable"); + } + }; + root.OnTimelineFirstDispatch = () => + { + scroller.Adjust(root.GetScrollAdjustment()); + }; + _roots.Add(root); + } + + var timelineContent = new VisualElement(); + if (_roots.Count == 0) + { + Label label = new Label("No roots found"); + left.Add(label); + return; + } + timelineContent.Add(_roots[0]); + + variablesViewer.OnVariableSelected = variable => + { + foreach (FunctionItem f in _roots[0].Functions) + { + bool toHighlight = f.Function.UsedVariables.Any(x => x == variable); + + if(toHighlight && !f.ClassListContains("contains-variable-global")) + f.AddToClassList("contains-variable-global"); + if(!toHighlight && f.ClassListContains("contains-variable-global")) + f.RemoveFromClassList("contains-variable-global"); + } + }; + + var timelineScroll = new ScrollView(ScrollViewMode.Vertical); + timelineScroll.AddToClassList("timeline"); + timelineScroll.style.flexGrow = 1; + timelineScroll.Add(timelineContent); + + _popup = new PopupField("Root keywords", _roots, 0, root => { return root.Keyword; }, root => { return root.Keyword; }); + _popup.RegisterValueChangedCallback(evt => + { + timelineContent.Clear(); + timelineContent.Add(evt.newValue); + functionViewer.SelectedItem = evt.newValue?.SelectedFunction?.Function; + moduleViewer.SelectedItem = evt.newValue?.SelectedFunction?.Row.Module; + templateViewer.SelectedItem = evt.newValue?.SelectedFunction?.Function.ShaderFunctionCode.Template; + scroller.Adjust(evt.newValue.GetScrollAdjustment()); + scroller.value = 0; + evt.newValue.Scroll(0); + }); + + scroller.Adjust(_popup.value.GetScrollAdjustment()); + + timelineScroll.Add(timelineContent); + + left.Add(_popup); + left.Add(timelineScroll); + left.Add(scroller); + left.Add(bot); + right.Add(templateViewer); + bot.Add(variablesViewer); + bot.Add(functionViewer); + bot.Add(moduleViewer); + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs.meta new file mode 100644 index 00000000..0a9be293 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/FunctionTimeline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c2e7f0b3ef37bf24bb90cfc0bb1c6de0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs new file mode 100644 index 00000000..9bf8b430 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs @@ -0,0 +1,293 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.Experimental.GraphView; +using UnityEngine; +using UnityEngine.UIElements; +using Poiyomi.ModularShaderSystem.UI; + + +namespace Poiyomi.ModularShaderSystem.Debug +{ + public class TemplateGraph : IModularShaderDebuggerTab + { + public VisualElement TabContainer { get; set; } + public string TabName { get; set; } + + internal TemplateGraphView _graph; + + public TemplateGraph() + { + TabName = "Template graph"; + TabContainer = new VisualElement(); + TabContainer.StretchToParentSize(); + var styleSheet = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/TemplateGraphStyle"); + TabContainer.styleSheets.Add(styleSheet); + } + + public void UpdateTab(ModularShader shader) + { + TabContainer.Clear(); + if (shader == null) return; + _graph = new TemplateGraphView(shader); + + + + TabContainer.Add(_graph); + } + } + + internal class TemplateGraphView : GraphView + { + public List Nodes; + public List BaseNodes; + + private List _modules; + private ModularShader _shader; + + private static TextPopup _popup; + + public TemplateGraphView(ModularShader shader) + { + Nodes = new List(); + BaseNodes = new List(); + + _modules = shader.BaseModules.Concat(shader.AdditionalModules).ToList(); + _shader = shader; + + SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); + this.AddManipulator(new ContentDragger()); + var grid = new GridBackground(); + + Insert(0, grid); + grid.StretchToParentSize(); + this.StretchToParentSize(); + + AddBaseTemplateNode("Shader", _shader.ShaderTemplate); + + if (_shader.UseTemplatesForProperties) + { + var keywords = new []{"#K#" + MSSConstants.TEMPLATE_PROPERTIES_KEYWORD}; + AddBaseTemplateNode("ShaderPropertiesRoot", new TemplateAsset{ Template = "", Keywords = keywords, name = "Properties Template Root"}); + if (_shader.ShaderPropertiesTemplate != null) AddTemplateNode("ShaderPropertiesTemplate", _shader.ShaderTemplate, keywords); + + } + + var moduleByTemplate = new Dictionary(); + foreach (var module in _shader.BaseModules.Concat(_shader.AdditionalModules)) + foreach (var template in module.Templates) + moduleByTemplate.Add(template, module); + + foreach (var template in _shader.BaseModules.Concat(_shader.AdditionalModules).SelectMany(x => x.Templates).OrderBy(x => x.Queue)) + { + if (template.Template == null) continue; + var module = moduleByTemplate[template]; + AddTemplateNode(module.Id, template); + } + + ScheduleNodesPositionReset(); + } + + public void AddBaseTemplateNode(string moduleId, TemplateAsset template) + { + var baseNode = new TemplateNode(moduleId, template, ""); + AddElement(baseNode); + Nodes.Add(baseNode); + BaseNodes.Add(baseNode); + } + + public void AddTemplateNode(string moduleId, ModuleTemplate template) + { + + var tempList = new List(); + foreach ((TemplateNode parent, string key) in Nodes.SelectMany(item => template.Keywords.Where(y => IsKeywordValid(moduleId, item, y)).Select(y => (item, y))).Where(x => !string.IsNullOrEmpty(x.Item2))) + { + var node = new TemplateNode(moduleId, template, key); + AddElement(node); + tempList.Add(node); + LinkTemplateNodes(parent, node, key); + } + Nodes.AddRange(tempList); + } + + public void AddTemplateNode(string moduleId, TemplateAsset template, string[] keywords) + { + var tempList = new List(); + foreach ((TemplateNode parent, string key) in Nodes.SelectMany(item => keywords.Where(y => IsKeywordValid(moduleId, item, y)).Select(y => (item, y))).Where(x => !string.IsNullOrEmpty(x.Item2))) + { + var node = new TemplateNode(moduleId, template, key); + AddElement(node); + tempList.Add(node); + LinkTemplateNodes(parent, node, key); + } + Nodes.AddRange(tempList); + } + + public void ScheduleNodesPositionReset() + { + RegisterCallback(GeometryChangedCallback); + } + + public override void BuildContextualMenu(ContextualMenuPopulateEvent evt) + { + var items = evt.menu.MenuItems(); + for (int i = 0; i < items.Count; i++) + evt.menu.RemoveItemAt(0); + + if (evt.target is TemplateNode node) + { + evt.menu.InsertAction(0,"View template code", action => + { + if (_popup != null) _popup.Close(); + _popup = ScriptableObject.CreateInstance(); + _popup.Text = node.TemplateAsset.Template; + var position = GUIUtility.GUIToScreenRect(node.worldBound); + int lineCount = _popup.Text == null ? 5 : _popup.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Length; + _popup.ShowAsDropDown(position, new Vector2(600, Math.Min(lineCount * 16, 800))); + }); + if (node.ModuleId.Equals("Shader") || node.ModuleId.Equals("ShaderPropertiesRoot")) + { + evt.menu.InsertAction(1, "Select relative modular shader asset", action => + { + Selection.SetActiveObjectWithContext(_shader, _shader); + }); + } + else + { + evt.menu.InsertAction(1, "Select relative module asset", action => + { + var module = _modules.Find(x => x.Id.Equals(node.ModuleId)); + if(module != null) + Selection.SetActiveObjectWithContext(module, module); + }); + } + + } + } + + private void GeometryChangedCallback(GeometryChangedEvent evt) + { + UnregisterCallback(GeometryChangedCallback); + + if(BaseNodes.Count == 0) return; + + float top = 0; + foreach (TemplateNode node in BaseNodes) + top += node.Reposition(2, top, 100*(Nodes.Count/70 + 1)); + + var newPosition = new Vector3(BaseNodes[0].style.left.value.value + viewport.resolvedStyle.width/2 - BaseNodes[0].resolvedStyle.width/2, + -BaseNodes[0].style.top.value.value + viewport.resolvedStyle.height/2 - BaseNodes[0].resolvedStyle.height/2, + viewTransform.position.z); + viewTransform.position = newPosition; + } + + private static bool IsKeywordValid(string moduleId, TemplateNode item, string y) + { + if (item.ContainsKeyword("#K#"+y)) return true; + return item.ContainsKeyword("#KI#"+y) && moduleId.Equals(item.ModuleId); + } + + private void LinkTemplateNodes(TemplateNode left, TemplateNode right, string key) + { + var edge = new Edge + { + output = left.Outputs[key], + input = right.Input + }; + + edge.input.Connect(edge); + edge.output.Connect(edge); + edge.SetEnabled(false); + Add(edge); + } + } + + internal sealed class TemplateNode : Node + { + public TemplateAsset TemplateAsset { get; set; } + public string ModuleId { get; set; } + public Port Input { get; set; } + public Dictionary Outputs { get; set; } + + private ModuleTemplate _template; + + public TemplateNode(string moduleId, ModuleTemplate template, string key) : this (moduleId, template.Template, key) + { + _template = template; + + if (_template == null) return; + var priority = new Label("" +_template.Queue); + priority.AddToClassList("node-header-queue"); + titleContainer.Add(priority); + } + + public TemplateNode(string moduleId, TemplateAsset templateAsset, string key) + { + ModuleId = moduleId; + TemplateAsset = templateAsset; + title = TemplateAsset.name; + var idLabel = new Label($"({ModuleId})"); + idLabel.AddToClassList("node-header-id"); + titleContainer.Insert(1, idLabel); + Outputs = new Dictionary(); + + if (!string.IsNullOrEmpty(key)) + { + Input = InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(string)); + Input.portName = key; + Input.portColor = Color.cyan; + Input.edgeConnector.activators.Clear(); + inputContainer.Add(Input); + } + + foreach (string keyword in TemplateAsset.Keywords) + { + var port = InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(string)); + + string sanitizedKeyword = keyword.Replace("#K#", "").Replace("#KI#", ""); + bool isInternal = keyword.StartsWith("#KI#"); + port.portName = sanitizedKeyword + (isInternal ? "(i)" : ""); + port.portColor = Color.cyan; + port.edgeConnector.activators.Clear(); + Outputs.Add(sanitizedKeyword, port); + outputContainer.Add(port); + } + + RefreshExpandedState(); + RefreshPorts(); + } + + public float Reposition(float right, float top, float offset) + { + float width = resolvedStyle.width; + float height = resolvedStyle.height; + + float childrenHeight = 0; + float newTop = top; + + foreach (var output in Outputs.Values) + { + foreach (var edge in output.connections) + { + var node = edge.input.node as TemplateNode; + if (node != null) + { + childrenHeight += node.Reposition(right + width + offset, newTop, offset); + newTop = top + childrenHeight; + } + } + } + SetPosition(new Rect(right, top + Math.Max((childrenHeight - height)/2, 0), 100, 100)); + RefreshExpandedState(); + RefreshPorts(); + + return Math.Max(height, childrenHeight) + 4; + } + + public bool ContainsKeyword(string keyword) + { + return TemplateAsset.Keywords.Contains(keyword); + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs.meta new file mode 100644 index 00000000..e4084c2c --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Components/TemplateGraph.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a58025042953bc1429b3e1a8684be12f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers.meta new file mode 100644 index 00000000..8c8efc2c --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1a80f0c817257bb43bc624af1073b13f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs new file mode 100644 index 00000000..f33a10cb --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs @@ -0,0 +1,30 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + [CustomPropertyDrawer(typeof(EnableProperty))] + public class EnablePropertyDrawer : PropertyDrawer + { + private VisualElement _root; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + _root = new VisualElement(); + + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/EnablePropertyDrawer"); + VisualElement template = visualTree.CloneTree(); + var foldout = new Foldout(); + foldout.text = property.displayName; + foldout.RegisterValueChangedCallback((e) => property.isExpanded = e.newValue); + foldout.value = property.isExpanded; + + foldout.Add(template); + _root.Add(foldout); + + return _root; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs.meta new file mode 100644 index 00000000..5f11f5c6 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/EnablePropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ffc75a109a78eb846a6b3708786e1a50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs new file mode 100644 index 00000000..d84eb1e4 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs @@ -0,0 +1,32 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + [CustomPropertyDrawer(typeof(ShaderFunction))] + public class FunctionPropertyDrawer : PropertyDrawer + { + private VisualElement _root; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + _root = new VisualElement(); + + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/FunctionPropertyDrawer"); + VisualElement template = visualTree.CloneTree(); + var foldout = new Foldout(); + foldout.text = property.displayName; + foldout.RegisterValueChangedCallback((e) => property.isExpanded = e.newValue); + foldout.value = property.isExpanded; + + var nameField = template.Q("Name"); + nameField.RegisterValueChangedCallback(evt => foldout.text = evt.newValue); + + foldout.Add(template); + _root.Add(foldout); + + return _root; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs.meta new file mode 100644 index 00000000..e8fb2bf6 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/FunctionPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24f1782728098f349aee99d57e62f501 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs new file mode 100644 index 00000000..2d2c77b8 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs @@ -0,0 +1,29 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + [CustomPropertyDrawer(typeof(ModuleTemplate))] + public class ModuleTemplatePropertyDrawer : PropertyDrawer + { + private VisualElement _root; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + _root = new VisualElement(); + + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/ModuleTemplatePropertyDrawer"); + VisualElement template = visualTree.CloneTree(); + var foldout = new Foldout(); + foldout.text = property.displayName; + foldout.RegisterValueChangedCallback((e) => property.isExpanded = e.newValue); + foldout.value = property.isExpanded; + foldout.Add(template); + _root.Add(foldout); + + return _root; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs.meta new file mode 100644 index 00000000..4f655a68 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ModuleTemplatePropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 21bc47d4c53206845ba7ea3ecdada7d0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs new file mode 100644 index 00000000..2221cd03 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs @@ -0,0 +1,52 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public class PropertyAttributeAttribute : PropertyAttribute + { + } + [CustomPropertyDrawer(typeof(PropertyAttributeAttribute))] + public class PropertyAttributeDrawer : PropertyDrawer + { + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + var root = new VisualElement(); + + var value = new TextField(); + value.SetValueWithoutNotify(property.stringValue); + root.Add(value); + + /*value.RegisterValueChangedCallback(evt => + { + property.stringValue = evt.newValue; + property.serializedObject.ApplyModifiedProperties(); + });*/ + value.RegisterCallback(evt => + { + string v = value.value; + if (v[v.Length - 1] == ']') + { + v = v.Remove(v.Length - 1, 1); + } + if (v[0] == '[') + { + v = v.Remove(0, 1); + } + property.stringValue = v; + value.SetValueWithoutNotify(property.stringValue); + property.serializedObject.ApplyModifiedProperties(); + }); + + /*customTypeField.style.display = ((VariableType)typeField.value) == VariableType.Custom ? DisplayStyle.Flex : DisplayStyle.None; + + typeField.RegisterValueChangedCallback(e => + { + customTypeField.style.display = ((VariableType)e.newValue) == VariableType.Custom ? DisplayStyle.Flex : DisplayStyle.None; + });*/ + + return root; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs.meta new file mode 100644 index 00000000..105176a5 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/PropertyAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3a66ad23d96a7a849ad93d53ea328d0e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs new file mode 100644 index 00000000..a41154a4 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs @@ -0,0 +1,289 @@ +using System; +using System.Linq; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine.Analytics; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public enum DefaultTextureValue + { + White, + Black, + Gray, + Bump, + } + + [CustomPropertyDrawer(typeof(Property))] + public class ShaderPropertyDrawer : PropertyDrawer + { + private VisualElement _root; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + _root = new VisualElement(); + + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/ShaderPropertyDrawer"); + VisualElement template = visualTree.CloneTree(); + var foldout = new Foldout(); + foldout.text = property.displayName; + foldout.RegisterValueChangedCallback((e) => property.isExpanded = e.newValue); + foldout.value = property.isExpanded; + + var nameField = template.Q("Name"); + nameField.RegisterValueChangedCallback(evt => foldout.text = evt.newValue); + var enumField = template.Q("TypeField"); + var valueContainer = template.Q("ValueContainer"); + + var type = property.FindPropertyRelative("Type"); + var defaultValue = property.FindPropertyRelative("DefaultValue"); + + var propType = GetPropertyTypeFromSerializedProperty(type.stringValue); + + enumField.Init(propType); + + enumField.value = propType; + + enumField.RegisterValueChangedCallback(e => + { + SetPropType(type, (PropertyType)e.newValue); + SetPropDefaultValue(defaultValue,""); + UpdateValueContainer(property, defaultValue, type, (PropertyType)e.newValue, type.stringValue, defaultValue.stringValue, valueContainer); + }); + + UpdateValueContainer(property, defaultValue, type, propType, type.stringValue, defaultValue.stringValue, valueContainer); + + foldout.Add(template); + _root.Add(foldout); + return _root; + } + + private void SetPropDefaultValue(SerializedProperty defaultValue, string v) + { + defaultValue.stringValue = v; + defaultValue.serializedObject.ApplyModifiedProperties(); + } + + private void SetPropType(SerializedProperty type, string v) + { + type.stringValue = v; + type.serializedObject.ApplyModifiedProperties(); + } + + private void SetPropType(SerializedProperty propType, PropertyType type) + { + string typeString = ""; + switch (type) + { + case PropertyType.Int: typeString = "Int"; break; + case PropertyType.Float: typeString = "Float"; break; + case PropertyType.Range: typeString = "Range(0, 1)"; break; + case PropertyType.Vector: typeString = "Vector"; break; + case PropertyType.Color: typeString = "Color"; break; + case PropertyType.Texture2D: typeString = "2D"; break; + case PropertyType.Texture2DArray: typeString = "2DArray"; break; + case PropertyType.Cube: typeString = "Cube"; break; + case PropertyType.CubeArray: typeString = "CubeArray"; break; + case PropertyType.Texture3D: typeString = "3d"; break; + } + + propType.stringValue = typeString; + propType.serializedObject.ApplyModifiedProperties(); + } + + private void UpdateValueContainer(SerializedProperty property, SerializedProperty defaultValue, SerializedProperty type, PropertyType propType, string propTypeString, string propValue, VisualElement element) + { + VisualElement field = null; + switch (propType) + { + case PropertyType.Float: + float floatValue = 0; + if (float.TryParse(propValue, out float f)) floatValue = f; + else SetPropDefaultValue(defaultValue,"" + floatValue); + var flfield = new FloatField{ value = floatValue, label = "Default value"}; + flfield.RegisterValueChangedCallback(e => SetPropDefaultValue(defaultValue, "" + e.newValue)); + field = flfield; + break; + case PropertyType.Range: + + field = new VisualElement(); + var rangeLimits = new Vector2(0, 1); + float rangeValue = 0; + + string[] prt = propTypeString.Replace("Range(","").Replace(")","").Split(','); + float[] prv = new float[2]; + bool pfi = true; + for (int i = 0; i < 2; i++) + { + if (float.TryParse(prt[i], out float v)) + { + prv[i] = v; + } + else + { + pfi = false; + break; + } + } + if (pfi) rangeLimits = new Vector2(prv[0], prv[1]); + else SetPropType(type, $"Range({prv[0]}, {prv[1]})"); + + var limits = new Vector2Field { label = "Range limits", value = rangeLimits }; + + if (float.TryParse(propValue, out float r)) rangeValue = r; + else SetPropDefaultValue(defaultValue,"" + rangeValue); + var horizontalElement = new VisualElement(); + horizontalElement.style.flexDirection = FlexDirection.Row; + + var valueSlider = new Slider + { + value = rangeValue, + lowValue = Math.Min(rangeLimits[0], rangeLimits[1]), + highValue = Math.Max(rangeLimits[0], rangeLimits[1]), + + label = "Default value" + }; + valueSlider.style.flexGrow = 1; + var valueField = new FloatField { value = rangeValue }; + valueField.style.width = 30; + + limits.RegisterValueChangedCallback(e => + { + valueSlider.lowValue = Math.Min(e.newValue[0], e.newValue[1]); + valueSlider.highValue = Math.Max(e.newValue[0], e.newValue[1]); + SetPropType(type,$"Range({valueSlider.lowValue}, {valueSlider.highValue})"); + }); + + valueField.RegisterValueChangedCallback(e => + { + if (e.newValue > valueSlider.highValue || e.newValue < valueSlider.lowValue) + { + e.StopImmediatePropagation(); + e.PreventDefault(); + valueField.SetValueWithoutNotify(e.previousValue); + return; + } + valueSlider.SetValueWithoutNotify(e.newValue); + SetPropDefaultValue(defaultValue,"" + e.newValue); + }); + valueSlider.RegisterValueChangedCallback(e => + { + valueField.SetValueWithoutNotify(e.newValue); + SetPropDefaultValue(defaultValue,"" + e.newValue); + }); + + field.Add(limits); + horizontalElement.Add(valueSlider); + horizontalElement.Add(valueField); + field.Add(horizontalElement); + + break; + case PropertyType.Int: + int intValue = 0; + if (int.TryParse(propValue, out int iv)) intValue = iv; + else SetPropDefaultValue(defaultValue,"" + intValue); + var ivfield = new IntegerField{ value = intValue, label = "Default value"}; + field = ivfield; + ivfield.RegisterValueChangedCallback(e => SetPropDefaultValue(defaultValue,"" + e.newValue)); + break; + case PropertyType.Color: + Color colorValue = Color.white; + string[] clvl = propValue.Replace("(","").Replace(")","").Split(','); + float[] fv = new float[4]; + bool vfi = true; + for (int i = 0; i < 4; i++) + { + if (float.TryParse(clvl[i], out float v)) + { + fv[i] = v; + } + else + { + vfi = false; + break; + } + } + + if (vfi) colorValue = new Color(fv[0], fv[1], fv[2], fv[3]); + else SetPropDefaultValue(defaultValue,$"({colorValue[0]}, {colorValue[1]}, {colorValue[2]}, {colorValue[3]})"); + var clfield = new ColorField { value = colorValue, label = "Default value" }; + field = clfield; + clfield.RegisterValueChangedCallback(e => SetPropDefaultValue(defaultValue,$"({e.newValue[0]}, {e.newValue[1]}, {e.newValue[2]}, {e.newValue[3]})")); + break; + case PropertyType.Vector: + Vector4 vectorValue = Vector4.zero; + string[] vvl = propValue.Replace("(","").Replace(")","").Split(','); + float[] vv = new float[4]; + bool vvi = true; + for (int i = 0; i < 4; i++) + { + if (float.TryParse(vvl[i], out float v)) + { + vv[i] = v; + } + else + { + vvi = false; + break; + } + } + if (vvi) vectorValue = new Vector4(vv[0], vv[1], vv[2] ,vv[3]); + else SetPropDefaultValue(defaultValue,$"({vv[0]}, {vv[1]}, {vv[2]}, {vv[3]})"); + var vlfield = new Vector4Field{ value = vectorValue, label = "Default value" }; + field = vlfield; + vlfield.RegisterValueChangedCallback(e => SetPropDefaultValue(defaultValue,$"({e.newValue[0]}, {e.newValue[1]}, {e.newValue[2]}, {e.newValue[3]})")); + break; + case PropertyType.Texture2D: + var texValue = DefaultTextureValue.White; + if (propValue.Contains("white")) texValue = DefaultTextureValue.White; + if (propValue.Contains("gray")) texValue = DefaultTextureValue.Gray; + if (propValue.Contains("black")) texValue = DefaultTextureValue.Black; + if (propValue.Contains("bump")) texValue = DefaultTextureValue.Bump; + SetPropDefaultValue(defaultValue,$"\"{Enum.GetName(typeof(DefaultTextureValue), texValue)?.ToLower()}\" {{}}"); + var txfield = new EnumField { label = "Default value" }; + txfield.Init(texValue); + var textureAsset = new PropertyField(property.FindPropertyRelative("DefaultTextureAsset"), "Texture Override"); + textureAsset.Bind(property.serializedObject); + var vl = new VisualElement(); + vl.Add(txfield); + vl.Add(textureAsset); + field = vl; + txfield.RegisterValueChangedCallback(e => SetPropDefaultValue(defaultValue,$"\"{Enum.GetName(typeof(DefaultTextureValue), e.newValue)?.ToLower()}\" {{}}")); + break; + case PropertyType.Texture2DArray: + case PropertyType.CubeArray: + case PropertyType.Texture3D: + SetPropDefaultValue(defaultValue,"\"\"{}"); + break; + case PropertyType.Cube: + SetPropDefaultValue(defaultValue,"\"\"{}"); + var textureCubeAsset = new PropertyField(property.FindPropertyRelative("DefaultTextureAsset"), "Texture Override"); + textureCubeAsset.Bind(property.serializedObject); + field = textureCubeAsset; + break; + } + + element.Clear(); + if (field != null) element.Add(field); + } + + private static PropertyType GetPropertyTypeFromSerializedProperty(string propType) + { + switch (propType.Trim()) + { + case "Float": return PropertyType.Float; + case "Int": return PropertyType.Int; + case "Color": return PropertyType.Color; + case "Vector": return PropertyType.Vector; + case "2D": return PropertyType.Texture2D; + case "3D": return PropertyType.Texture3D; + case "Cube": return PropertyType.Cube; + case "2DArray": return PropertyType.Texture2DArray; + case "CubeArray": return PropertyType.CubeArray; + default: return propType.Trim().StartsWith("Range") ? PropertyType.Range : PropertyType.Float; + } + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs.meta new file mode 100644 index 00000000..a638df90 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/ShaderPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eef114f99927e5d4b98ba893786d3838 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs new file mode 100644 index 00000000..3bdfd831 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs @@ -0,0 +1,43 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + [CustomPropertyDrawer(typeof(Variable))] + public class VariablePropertyDrawer : PropertyDrawer + { + private VisualElement _root; + + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + _root = new VisualElement(); + + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/VariablePropertyDrawer"); + VisualElement template = visualTree.CloneTree(); + var foldout = new Foldout(); + foldout.text = property.displayName; + foldout.RegisterValueChangedCallback((e) => property.isExpanded = e.newValue); + foldout.value = property.isExpanded; + foldout.Add(template); + _root.Add(foldout); + + var nameField = template.Q("Name"); + nameField.RegisterValueChangedCallback(evt => foldout.text = evt.newValue); + var typeField = template.Q("Type"); + var customTypeField = template.Q("CustomType"); + + typeField.Init(VariableType.Float); + + customTypeField.style.display = ((VariableType)typeField.value) == VariableType.Custom ? DisplayStyle.Flex : DisplayStyle.None; + + typeField.RegisterValueChangedCallback(e => + { + customTypeField.style.display = ((VariableType)e.newValue) == VariableType.Custom ? DisplayStyle.Flex : DisplayStyle.None; + }); + + return _root; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs.meta new file mode 100644 index 00000000..b6b5f0fa --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Drawers/VariablePropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d92791b337f5ca4984e6d33748e19a3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements.meta new file mode 100644 index 00000000..ec87ef6f --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 593f19fde7643b4429fd5f6a8503214b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs new file mode 100644 index 00000000..3ad05abf --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs @@ -0,0 +1,104 @@ +using System; +using System.Linq; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public class CodeViewElement : VisualElement + { + private class LineItem : VisualElement + { + private static Font TextFont + { + get + { + if (_font == null) + _font = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/RobotoMono-Regular"); + return _font; + } + } + + private static Font _font; + private Label _lineNumber; + private Label _line; + public string Text { get; } + + public LineItem() : this(0, "") {} + + public LineItem(int number, string text, int digits = 0) + { + Text = text; + _lineNumber = new Label("" + number); + _lineNumber.style.color = Color.gray; + _lineNumber.style.width = digits == 0 ? 30 : digits * 8; + _lineNumber.style.unityTextAlign = TextAnchor.MiddleRight; + _lineNumber.style.unityFont = TextFont; + _lineNumber.style.marginRight = 4; + _lineNumber.style.marginLeft = 4; + + _line = new Label(text); + _line.style.flexGrow = 1; + _line.style.unityFont = TextFont; + + style.flexDirection = FlexDirection.Row; + Add(_lineNumber); + Add(_line); + } + + public void SetText(int i, string textLine, int digits) + { + _lineNumber.text = "" + i; + _lineNumber.style.width = digits == 0 ? 30 : digits * 8; + _line.text = textLine; + _line.MeasureTextSize(textLine, 0, MeasureMode.Exactly, 0, MeasureMode.Exactly); + } + } + + public string Text + { + get => string.Join("\n", _textLines); + set + { + _textLines = value == null ? Array.Empty() : value.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + _digits = (int)Math.Floor(Math.Log10(_textLines.Length) + 1); + _listView.itemsSource = _textLines; + + float width =((_textLines.Length == 0 ? 0 : _textLines.Max(x => x.Length)) + _digits + 1) * 10; + _listView.contentContainer.style.width = width; + } + } + + public int LineCount => _textLines.Length; + + private Label _templateLabel; + private string[] _textLines; + private ListView _listView; + private int _digits; + + public CodeViewElement() + { + ScrollView s = new ScrollView(ScrollViewMode.Horizontal); + _listView = new ListView(); + _listView.itemHeight = 15; + _listView.AddToClassList("unity-base-text-field__input"); + _listView.AddToClassList("unity-text-field__input"); + _listView.AddToClassList("unity-base-field__input"); + _listView.style.flexGrow = 1; + _listView.contentContainer.style.flexGrow = 1; + + Func makeItem = () => new LineItem(); + Action bindItem = (e, i) => (e as LineItem).SetText(i+1, _textLines[i], _digits); + + _listView.makeItem = makeItem; + _listView.bindItem = bindItem; + _listView.selectionType = SelectionType.None; + s.Add(_listView); + Add(s); + s.style.flexGrow = 1; + s.contentContainer.style.flexGrow = 1; + + style.flexGrow = 1; + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs.meta new file mode 100644 index 00000000..69417247 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/CodeViewElement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 248ba9991fe7ba44d8ed907de6a5e4d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs new file mode 100644 index 00000000..60eff417 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs @@ -0,0 +1,324 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public interface IInspectorList + { + InspectorListItem draggedElement { get; set; } + void HighlightDrops(); + void DeHighlightDrops(); + } + + public class InspectorList : BindableElement, IInspectorList + { + Foldout _listContainer; + Button _addButton; + SerializedProperty _array; + private bool _showElementsButtons; + + private bool _hasFoldingBeenForced; + + public InspectorListItem draggedElement { get; set; } + public bool _highlightDrops; + + private List _drops; + + private VisualElement _currentDrop; + + public InspectorList() + { + _drops = new List(); + _listContainer = new Foldout(); + _listContainer.text = "Unbound List"; + _listContainer.contentContainer.AddToClassList("inspector-list-container"); + _listContainer.value = false; + _listContainer.RegisterCallback(e => Drop()); + _listContainer.RegisterCallback(e => Drop()); + + _addButton = new Button(AddItem); + _addButton.text = "Add"; + _addButton.AddToClassList("inspector-list-add-button"); + Add(_listContainer); + if (enabledSelf) + _listContainer.Add(_addButton); + _listContainer.RegisterValueChangedCallback((e) => _array.isExpanded = e.newValue); + var styleSheet = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/InspectorList"); + styleSheets.Add(styleSheet); + } + + private void Drop() + { + if (draggedElement == null) return; + draggedElement.RemoveFromClassList("inspector-list-drag-enabled"); + + if (_highlightDrops) + { + DeHighlightDrops(); + int dropIndex = _drops.IndexOf(_currentDrop); + + if (dropIndex == -1) + { + draggedElement = null; + return; + } + + if (dropIndex > draggedElement.index) dropIndex--; + _array.MoveArrayElement(draggedElement.index, dropIndex); + bool expanded = _array.GetArrayElementAtIndex(dropIndex).isExpanded; + _array.GetArrayElementAtIndex(dropIndex).isExpanded = _array.GetArrayElementAtIndex(draggedElement.index).isExpanded; + _array.GetArrayElementAtIndex(draggedElement.index).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + UpdateList(); + } + draggedElement = null; + } + + public void HighlightDrops() + { + foreach (var item in _drops) + item.AddToClassList("inspector-list-drop-area-highlight"); + + _highlightDrops = true; + } + + public void DeHighlightDrops() + { + foreach (var item in _drops) + item.RemoveFromClassList("inspector-list-drop-area-highlight"); + + _highlightDrops = false; + } + + public override void HandleEvent(EventBase evt) + { + var type = evt.GetType(); //SerializedObjectBindEvent is internal, so need to use reflection here + if ((type.Name == "SerializedPropertyBindEvent") && !string.IsNullOrWhiteSpace(bindingPath)) + { + var obj = type.GetProperty("bindProperty")?.GetValue(evt) as SerializedProperty; + _array = obj; + if (obj != null) + { + if (_hasFoldingBeenForced) obj.isExpanded = _listContainer.value; + else _listContainer.value = obj.isExpanded; + } + UpdateList(); + } + base.HandleEvent(evt); + } + + public void UpdateList() + { + _listContainer.Clear(); + _drops.Clear(); + + if (_array == null) + return; + _listContainer.text = _array.displayName; + CreateDrop(); + for (int i = 0; i < _array.arraySize; i++) + { + int index = i; + var element = new PropertyField(_array.GetArrayElementAtIndex(index)); + element.Bind(_array.GetArrayElementAtIndex(index).serializedObject); + var item = new InspectorListItem(this, element, _array, index, _showElementsButtons); + item.removeButton.RegisterCallback((evt) => RemoveItem(index)); + item.upButton.RegisterCallback((evt) => MoveUpItem(index)); + item.downButton.RegisterCallback((evt) => MoveDownItem(index)); + _listContainer.Add(item); + CreateDrop(); + } + if (enabledSelf) + _listContainer.Add(_addButton); + } + + private void CreateDrop() + { + VisualElement dropArea = new VisualElement(); + dropArea.AddToClassList("inspector-list-drop-area"); + dropArea.RegisterCallback(e => + { + if (_highlightDrops) + { + dropArea.AddToClassList("inspector-list-drop-area-selected"); + _currentDrop = dropArea; + } + }); + dropArea.RegisterCallback(e => + { + if (_highlightDrops) + { + dropArea.RemoveFromClassList("inspector-list-drop-area-selected"); + if (_currentDrop == dropArea) _currentDrop = null; + } + }); + + _listContainer.Add(dropArea); + _drops.Add(dropArea); + } + + public void RemoveItem(int index) + { + if (_array != null) + { + if (index < _array.arraySize - 1) + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index + 1).isExpanded; + _array.DeleteArrayElementAtIndex(index); + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void MoveUpItem(int index) + { + if (_array != null && index > 0) + { + _array.MoveArrayElement(index, index - 1); + bool expanded = _array.GetArrayElementAtIndex(index).isExpanded; + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index - 1).isExpanded; + _array.GetArrayElementAtIndex(index - 1).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void MoveDownItem(int index) + { + if (_array != null && index < _array.arraySize - 1) + { + _array.MoveArrayElement(index, index + 1); + bool expanded = _array.GetArrayElementAtIndex(index).isExpanded; + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index + 1).isExpanded; + _array.GetArrayElementAtIndex(index + 1).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void AddItem() + { + if (_array != null) + { + _array.InsertArrayElementAtIndex(_array.arraySize); + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void SetFoldingState(bool open) + { + _listContainer.value = open; + if (_array != null) _array.isExpanded = open; + else _hasFoldingBeenForced = true; + } + + public new class UxmlFactory : UxmlFactory { } + + public new class UxmlTraits : BindableElement.UxmlTraits + { + UxmlBoolAttributeDescription showElements = + new UxmlBoolAttributeDescription { name = "show-elements-text", defaultValue = true }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + + if (ve is InspectorList ate) ate._showElementsButtons = showElements.GetValueFromBag(bag, cc); + } + } + + } + + public class InspectorListItem : VisualElement + { + public Button removeButton; + public Button upButton; + public Button downButton; + + public VisualElement dragArea; + + public Vector2 startPosition; + + public int index; + + private IInspectorList _list; + public InspectorListItem(IInspectorList list, VisualElement element, SerializedProperty array, int index, bool showButtonsText) + { + this.index = index; + _list = list; + AddToClassList("inspector-list-item-container"); + + dragArea = new VisualElement(); + dragArea.AddToClassList("inspector-list-drag-handle"); + + dragArea.RegisterCallback(e => + { + if (_list.draggedElement == this) + { + e.StopImmediatePropagation(); + return; + } + + _list.draggedElement = this; + _list.HighlightDrops(); + AddToClassList("inspector-list-drag-enabled"); + }); + + VisualElement buttonsArea = new VisualElement(); + + RegisterCallback(e => + { + buttonsArea.ClearClassList(); + if (e.newRect.height > 60) + { + buttonsArea.AddToClassList("inspector-list-buttons-container-vertical"); + buttonsArea.Add(removeButton); + buttonsArea.Add(upButton); + buttonsArea.Add(downButton); + } + else + { + buttonsArea.AddToClassList("inspector-list-buttons-container-horizontal"); + buttonsArea.Add(upButton); + buttonsArea.Add(downButton); + buttonsArea.Add(removeButton); + } + }); + + upButton = new Button(); + upButton.name = "UpInspectorListItem"; + upButton.AddToClassList("inspector-list-up-button"); + if (index == 0) + upButton.SetEnabled(false); + downButton = new Button(); + downButton.name = "DownInspectorListItem"; + downButton.AddToClassList("inspector-list-down-button"); + if (index >= array.arraySize - 1) + downButton.SetEnabled(false); + removeButton = new Button(); + removeButton.name = "RemoveInspectorListItem"; + removeButton.AddToClassList("inspector-list-remove-button"); + + if (showButtonsText) + { + upButton.text = "up"; + downButton.text = "down"; + removeButton.text = "-"; + } + + var property = array.GetArrayElementAtIndex(index); + element.AddToClassList("inspector-list-item"); + + Add(dragArea); + Add(element); + Add(buttonsArea); + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs.meta new file mode 100644 index 00000000..5839937e --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/InspectorList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e402c0aaa42fe944802ceaf7d55be05 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs new file mode 100644 index 00000000..6f2f9955 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs @@ -0,0 +1,56 @@ +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public class LabelField : VisualElement + { + public string Label + { + get => _label; + set + { + _label = value; + _labelField.text = _label; + } + } + + public string Value + { + get => _value; + set + { + _value = value; + _valueField.text = _value; + } + } + + private Label _labelField; + private Label _valueField; + private string _label; + private string _value; + + public LabelField(string label, string value) + { + _label = label; + _value = value; + _labelField = new Label(label); + _valueField = new Label(value); + + AddToClassList("unity-base-field"); + AddToClassList("unity-base-text-field"); + AddToClassList("unity-text-field"); + + _labelField.AddToClassList("unity-text-element"); + _labelField.AddToClassList("unity-label"); + _labelField.AddToClassList("unity-base-field__label"); + _labelField.AddToClassList("unity-base-text-field__label"); + _labelField.AddToClassList("unity-text-field__label"); + _labelField.AddToClassList("label-field-title"); + _valueField.AddToClassList("label-field-value"); + + Add(_labelField); + Add(_valueField); + + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs.meta new file mode 100644 index 00000000..f7dffca5 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/LabelField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af8a36edfa0c0a44d971881746edc521 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs new file mode 100644 index 00000000..7a80493e --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs @@ -0,0 +1,315 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + + public class ModuleInspectorList : BindableElement, IInspectorList + { + Foldout _listContainer; + Button _addButton; + SerializedProperty _array; + private bool _showElementsButtons; + private List _loadedModules; + + private bool _hasFoldingBeenForced; + + public InspectorListItem draggedElement { get; set; } + public bool _highlightDrops; + + private List _drops; + + private VisualElement _currentDrop; + + public ModuleInspectorList() + { + _drops = new List(); + _listContainer = new Foldout(); + _listContainer.text = "Unbound List"; + _listContainer.contentContainer.AddToClassList("inspector-list-container"); + _listContainer.value = false; + _listContainer.RegisterCallback(e => Drop()); + _listContainer.RegisterCallback(e => Drop()); + + _addButton = new Button(AddItem); + _addButton.text = "Add"; + _addButton.AddToClassList("inspector-list-add-button"); + Add(_listContainer); + if (enabledSelf) + _listContainer.Add(_addButton); + _listContainer.RegisterValueChangedCallback((e) => _array.isExpanded = e.newValue); + var styleSheet = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/InspectorList"); + styleSheets.Add(styleSheet); + } + + private void Drop() + { + if (draggedElement == null) return; + draggedElement.RemoveFromClassList("inspector-list-drag-enabled"); + + if (_highlightDrops) + { + DeHighlightDrops(); + int dropIndex = _drops.IndexOf(_currentDrop); + + if (dropIndex == -1) + { + draggedElement = null; + return; + } + + if (dropIndex > draggedElement.index) dropIndex--; + _array.MoveArrayElement(draggedElement.index, dropIndex); + bool expanded = _array.GetArrayElementAtIndex(dropIndex).isExpanded; + _array.GetArrayElementAtIndex(dropIndex).isExpanded = _array.GetArrayElementAtIndex(draggedElement.index).isExpanded; + _array.GetArrayElementAtIndex(draggedElement.index).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + UpdateList(); + } + draggedElement = null; + } + + public void HighlightDrops() + { + foreach (var item in _drops) + item.AddToClassList("inspector-list-drop-area-highlight"); + + _highlightDrops = true; + } + + public void DeHighlightDrops() + { + foreach (var item in _drops) + item.RemoveFromClassList("inspector-list-drop-area-highlight"); + + _highlightDrops = false; + } + + public override void HandleEvent(EventBase evt) + { + var type = evt.GetType(); //SerializedObjectBindEvent is internal, so need to use reflection here + if ((type.Name == "SerializedPropertyBindEvent") && !string.IsNullOrWhiteSpace(bindingPath)) + { + var obj = type.GetProperty("bindProperty")?.GetValue(evt) as SerializedProperty; + _array = obj; + if (obj != null) + { + if (_hasFoldingBeenForced) obj.isExpanded = _listContainer.value; + else _listContainer.value = obj.isExpanded; + } + UpdateList(); + } + base.HandleEvent(evt); + } + + public void UpdateList() + { + _listContainer.Clear(); + _drops.Clear(); + + if (_array == null) + return; + _listContainer.text = _array.displayName; + CreateDrop(); + + _loadedModules = new List(); + for (int i = 0; i < _array.arraySize; i++) + { + if (_array.GetArrayElementAtIndex(i).objectReferenceValue != null) + _loadedModules.Add(((ShaderModule)_array.GetArrayElementAtIndex(i).objectReferenceValue)?.Id); + } + + + + for (int i = 0; i < _array.arraySize; i++) + { + int index = i; + + var moduleItem = new VisualElement(); + var objectField = new ObjectField();//_array.GetArrayElementAtIndex(index)); + + SerializedProperty propertyValue = _array.GetArrayElementAtIndex(index); + + objectField.objectType = typeof(ShaderModule); + objectField.bindingPath = propertyValue.propertyPath; + objectField.Bind(propertyValue.serializedObject); + var infoLabel = new Label(); + moduleItem.Add(objectField); + moduleItem.Add(infoLabel); + + objectField.RegisterCallback>(x => + { + var newValue = (ShaderModule)x.newValue; + var oldValue = (ShaderModule)x.previousValue; + + if (oldValue != null) + _loadedModules.Remove(oldValue.Id); + if (newValue != null) + _loadedModules.Add(newValue.Id); + + for (int j = 0; j < _array.arraySize; j++) + { + var element = ((ObjectField)x.target).parent.parent.parent.ElementAt(j*2+1).ElementAt(1); + Label label = element.ElementAt(1) as Label; + if (index == j) + CheckModuleValidity(newValue, label, element); + else + CheckModuleValidity((ShaderModule)_array.GetArrayElementAtIndex(j).objectReferenceValue, label, element); + } + }); + + var item = new InspectorListItem(this, moduleItem, _array, index, _showElementsButtons); + item.removeButton.RegisterCallback((evt) => RemoveItem(index)); + item.upButton.RegisterCallback((evt) => MoveUpItem(index)); + item.downButton.RegisterCallback((evt) => MoveDownItem(index)); + _listContainer.Add(item); + CreateDrop(); + + CheckModuleValidity((ShaderModule)propertyValue.objectReferenceValue, infoLabel, moduleItem); + } + if (enabledSelf) + _listContainer.Add(_addButton); + } + + private void CreateDrop() + { + VisualElement dropArea = new VisualElement(); + dropArea.AddToClassList("inspector-list-drop-area"); + dropArea.RegisterCallback(e => + { + if (_highlightDrops) + { + dropArea.AddToClassList("inspector-list-drop-area-selected"); + _currentDrop = dropArea; + } + }); + dropArea.RegisterCallback(e => + { + if (_highlightDrops) + { + dropArea.RemoveFromClassList("inspector-list-drop-area-selected"); + if (_currentDrop == dropArea) _currentDrop = null; + } + }); + + _listContainer.Add(dropArea); + _drops.Add(dropArea); + } + + private void CheckModuleValidity(ShaderModule newValue, Label infoLabel, VisualElement moduleItem) + { + + List problems = new List(); + + if (newValue != null) + { + var moduleId = newValue.Id; + if (_loadedModules.Count(y => y.Equals(moduleId)) > 1) + problems.Add("The module is duplicate"); + + List missingDependencies = newValue.ModuleDependencies.Where(dependency => _loadedModules.Count(y => y.Equals(dependency)) == 0).ToList(); + List incompatibilities = newValue.IncompatibleWith.Where(dependency => _loadedModules.Count(y => y.Equals(dependency)) > 0).ToList(); + + if (missingDependencies.Count > 0) + problems.Add("Missing dependencies: " + string.Join(", ", missingDependencies)); + + if (incompatibilities.Count > 0) + problems.Add("These incompatible modules are installed: " + string.Join(", ", incompatibilities)); + } + + infoLabel.text = string.Join("\n", problems); + + if (!string.IsNullOrWhiteSpace(infoLabel.text)) + { + moduleItem.AddToClassList("error-background"); + infoLabel.visible = true; + } + else + { + moduleItem.RemoveFromClassList("error-background"); + infoLabel.visible = false; + } + } + + public void RemoveItem(int index) + { + if (_array != null) + { + if (index < _array.arraySize - 1) + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index + 1).isExpanded; + var elementProperty = _array.GetArrayElementAtIndex(index); + if (elementProperty.objectReferenceValue != null) + elementProperty.objectReferenceValue = null; + _array.DeleteArrayElementAtIndex(index); + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void MoveUpItem(int index) + { + if (_array != null && index > 0) + { + _array.MoveArrayElement(index, index - 1); + bool expanded = _array.GetArrayElementAtIndex(index).isExpanded; + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index - 1).isExpanded; + _array.GetArrayElementAtIndex(index - 1).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void MoveDownItem(int index) + { + if (_array != null && index < _array.arraySize - 1) + { + _array.MoveArrayElement(index, index + 1); + bool expanded = _array.GetArrayElementAtIndex(index).isExpanded; + _array.GetArrayElementAtIndex(index).isExpanded = _array.GetArrayElementAtIndex(index + 1).isExpanded; + _array.GetArrayElementAtIndex(index + 1).isExpanded = expanded; + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void AddItem() + { + if (_array != null) + { + _array.InsertArrayElementAtIndex(_array.arraySize); + _array.serializedObject.ApplyModifiedProperties(); + } + + UpdateList(); + } + + public void SetFoldingState(bool open) + { + _listContainer.value = open; + if (_array != null) _array.isExpanded = open; + else _hasFoldingBeenForced = true; + } + + public new class UxmlFactory : UxmlFactory { } + + public new class UxmlTraits : BindableElement.UxmlTraits + { + UxmlBoolAttributeDescription showElements = + new UxmlBoolAttributeDescription { name = "show-elements-text", defaultValue = true }; + + public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) + { + base.Init(ve, bag, cc); + + if (ve is ModuleInspectorList ate) ate._showElementsButtons = showElements.GetValueFromBag(bag, cc); + } + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs.meta new file mode 100644 index 00000000..aab66df8 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/ModuleInspectorList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f9210556d98393149bad9819fb127c5b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs new file mode 100644 index 00000000..73079bd3 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs @@ -0,0 +1,30 @@ +using UnityEngine.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + public class VariableField : VisualElement + { + public Variable Variable { get; set; } + + private string _type; + + public VariableField(Variable variable) + { + Variable = variable; + if(variable.Type == VariableType.Custom) + _type = variable.CustomType; + else + _type = variable.Type.ToString(); + var nameField = new Label(variable.Name); + var typeField = new Label(_type); + + nameField.style.flexGrow = 1; + typeField.AddToClassList("variable-type-text"); + Add(nameField); + Add(typeField); + + style.flexDirection = FlexDirection.Row; + + } + } +} \ No newline at end of file diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs.meta new file mode 100644 index 00000000..476b82a9 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Elements/VariableField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1d7f89d7e489068458d4c125179d6061 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors.meta b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors.meta new file mode 100644 index 00000000..6a6b0b87 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e5f27652ec52b1e4abcf40a28dfa2e9c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ModularShaderEditor.cs b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ModularShaderEditor.cs new file mode 100644 index 00000000..4da90e07 --- /dev/null +++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Scripts/Editor/ModularShaderSystem/Editors/Inspectors/ModularShaderEditor.cs @@ -0,0 +1,68 @@ +using System; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.UIElements; + +namespace Poiyomi.ModularShaderSystem.UI +{ + [CustomEditor(typeof(ModularShader))] + public class ModularShaderEditor : Editor + { + private VisualElement _root; + private ModularShader _shader; + + public override VisualElement CreateInspectorGUI() + { + _root = new VisualElement(); + _shader = (ModularShader)serializedObject.targetObject; + var visualTree = Resources.Load(MSSConstants.RESOURCES_FOLDER + "/MSSUIElements/ModularShaderEditor"); + VisualElement template = visualTree.CloneTree(); + + _root.Add(template); + + var baseModulesField = _root.Q("BaseModulesField"); + bool areModulesEditable = !_shader.LockBaseModules; + bool checkForProperties = _shader.UseTemplatesForProperties; + if(!areModulesEditable) + baseModulesField.SetFoldingState(true); + baseModulesField.SetEnabled(areModulesEditable); + + var templateField = _root.Q("ShaderTemplateField"); + templateField.objectType = typeof(TemplateAsset); + + var propertiesTemplateField = _root.Q("ShaderPropertiesTemplateField"); + propertiesTemplateField.objectType = typeof(TemplateAsset); + propertiesTemplateField.style.display = checkForProperties ? DisplayStyle.Flex : DisplayStyle.None; + + var useTemplatesField = _root.Q("UseTemplatesForPropertiesField"); + useTemplatesField.RegisterValueChangedCallback(x => + { + propertiesTemplateField.style.display = x.newValue ? DisplayStyle.Flex : DisplayStyle.None; + }); + + var generateButton = _root.Q