diff --git a/Assets/UdonSharp/Editor/Resources.meta b/Assets/UdonSharp/Editor/Resources.meta new file mode 100644 index 00000000..56c3e066 --- /dev/null +++ b/Assets/UdonSharp/Editor/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5dc51e470f4db1e4e80398498820e372 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png b/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png new file mode 100644 index 00000000..c6d27360 Binary files /dev/null and b/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png differ diff --git a/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png.meta b/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png.meta new file mode 100644 index 00000000..a8626677 --- /dev/null +++ b/Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: d166756ffd718494082c946aee6d4ab9 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png b/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png new file mode 100644 index 00000000..2d807795 Binary files /dev/null and b/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png differ diff --git a/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png.meta b/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png.meta new file mode 100644 index 00000000..51f9d0ef --- /dev/null +++ b/Assets/UdonSharp/Editor/Resources/UndoArrowLight.png.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: 62ddcf63cbc3b6944b9e1ca0960c150a +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs b/Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs index 441317de..4ddbbf06 100644 --- a/Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs +++ b/Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs @@ -46,6 +46,10 @@ public class UdonSharpProgramAsset : UdonAssemblyProgramAsset private UdonBehaviour currentBehaviour = null; private static GUIStyle errorTextStyle; + private static GUIStyle undoLabelStyle; + private static GUIContent undoArrowLight; + private static GUIContent undoArrowDark; + private static GUIContent undoArrowContent; private void DrawCompileErrorTextArea() { @@ -66,6 +70,24 @@ private void DrawCompileErrorTextArea() protected override void DrawProgramSourceGUI(UdonBehaviour udonBehaviour, ref bool dirty) { + if (undoLabelStyle == null || + undoArrowDark == null || + undoArrowLight == null) + { + undoLabelStyle = new GUIStyle(EditorStyles.label); + undoLabelStyle.alignment = TextAnchor.MiddleCenter; + undoLabelStyle.padding = new RectOffset(0, 0, 1, 0); + undoLabelStyle.margin = new RectOffset(0, 0, 0, 0); + undoLabelStyle.border = new RectOffset(0, 0, 0, 0); + undoLabelStyle.stretchWidth = false; + undoLabelStyle.stretchHeight = false; + + undoArrowLight = new GUIContent((Texture)EditorGUIUtility.Load("Assets/UdonSharp/Editor/Resources/UndoArrowLight.png"), "Reset to default value"); + undoArrowDark = new GUIContent((Texture)EditorGUIUtility.Load("Assets/UdonSharp/Editor/Resources/UndoArrowBlack.png"), "Reset to default value"); + } + + undoArrowContent = EditorGUIUtility.isProSkin ? undoArrowLight : undoArrowDark; + currentBehaviour = udonBehaviour; EditorGUI.BeginChangeCheck(); @@ -427,8 +449,7 @@ private object DrawFieldForType(string fieldName, string symbol, (object value, fieldLabel = new GUIContent(fieldName, tooltip.tooltip); else fieldLabel = new GUIContent(fieldName); - - + if (declaredType.IsArray) { bool foldoutEnabled; @@ -713,7 +734,9 @@ protected override object DrawPublicVariableField(string symbol, object variable EditorGUI.BeginChangeCheck(); object newValue = DrawFieldForType(null, symbol, (variableValue, variableType, fieldDefinition), fieldDefinition != null ? fieldDefinition.fieldSymbol.userCsType : null, ref dirty, enabled); - if (EditorGUI.EndChangeCheck()) + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) { if (shouldUseRuntimeValue) { @@ -735,7 +758,31 @@ protected override object DrawPublicVariableField(string symbol, object variable } if (!isArray) + { + object originalValue = program.Heap.GetHeapVariable(program.SymbolTable.GetAddressFromSymbol(symbol)); + + if (originalValue != null && !originalValue.Equals(variableValue)) + { + int originalIndent = EditorGUI.indentLevel; + EditorGUI.indentLevel = 0; + // Check if changed because otherwise the UI throw an error since we changed that we want to draw the undo arrow in the middle of drawing when we're modifying stuff like colors + if (!changed && GUI.Button(EditorGUILayout.GetControlRect(GUILayout.Width(14f), GUILayout.Height(11f)), undoArrowContent, undoLabelStyle)) + { + if (shouldUseRuntimeValue) + { + currentBehaviour.SetProgramVariable(symbol, originalValue); + } + else + { + dirty = true; + variableValue = originalValue; + } + } + EditorGUI.indentLevel = originalIndent; + } + EditorGUILayout.EndHorizontal(); + } } EditorGUI.EndDisabledGroup();