public override void OnInspectorGUI() { Mask maskTarget = (Mask)target; Texture alphaTexture = maskTarget.GetComponent <Renderer>().sharedMaterial.mainTexture; if (maskTarget.GetComponents <Mask>().Length > 1) { GUILayout.Label("More than one instance of Mask attached.\nPlease only use one."); return; } if ((maskTarget.GetComponent <MeshRenderer>() != null) && (maskTarget.GetComponent <MeshFilter>() != null) && (maskTarget.GetComponent <Renderer>().sharedMaterial != null) && (maskTarget.GetComponent <Renderer>().sharedMaterial.mainTexture != null)) { //maskTarget.maskMappingWorldAxis = (Mask.MappingAxis)EditorGUILayout.EnumPopup("Mask Mapping World Axis", maskTarget.maskMappingWorldAxis); bool isMaskingEnabled = EditorGUILayout.Toggle("Masking Enabled", maskTarget.isMaskingEnabled); if (isMaskingEnabled != maskTarget.isMaskingEnabled) { maskTarget.isMaskingEnabled = isMaskingEnabled; } Mask.MappingAxis maskMappingWorldAxis = (Mask.MappingAxis)EditorGUILayout.EnumPopup("Mask Mapping World Axis", maskTarget.maskMappingWorldAxis); if (maskMappingWorldAxis != maskTarget.maskMappingWorldAxis) { maskTarget.maskMappingWorldAxis = maskMappingWorldAxis; } bool invertAxis = EditorGUILayout.Toggle("Invert Axis", maskTarget.invertAxis); if (invertAxis != maskTarget.invertAxis) { maskTarget.invertAxis = invertAxis; } bool clampAlphaHorizontally = EditorGUILayout.Toggle("Clamp Alpha Horizontally", maskTarget.clampAlphaHorizontally); if (clampAlphaHorizontally != maskTarget.clampAlphaHorizontally) { maskTarget.clampAlphaHorizontally = clampAlphaHorizontally; } bool clampAlphaVertically = EditorGUILayout.Toggle("Clamp Alpha Vertically", maskTarget.clampAlphaVertically); if (clampAlphaVertically != maskTarget.clampAlphaVertically) { maskTarget.clampAlphaVertically = clampAlphaVertically; } float clampingBorder = EditorGUILayout.FloatField("Clamping Border", maskTarget.clampingBorder); if (clampingBorder != maskTarget.clampingBorder) { maskTarget.clampingBorder = clampingBorder; } bool useMaskAlphaChannel = EditorGUILayout.Toggle("Use Mask Alpha Channel (not RGB)", maskTarget.useMaskAlphaChannel); if (useMaskAlphaChannel != maskTarget.useMaskAlphaChannel) { maskTarget.useMaskAlphaChannel = useMaskAlphaChannel; } if (!Application.isPlaying) { bool displayMask = EditorGUILayout.Toggle("Display Mask", maskTarget.GetComponent <Renderer>().enabled); if (displayMask != maskTarget.GetComponent <Renderer>().enabled) { maskTarget.GetComponent <Renderer>().enabled = displayMask; } } if (!Application.isPlaying) { if (GUILayout.Button("Apply Mask to Siblings in Hierarchy")) { ApplyMaskToChildren(); // this is needed, so that it would apply the value to the materials (this is done within the setter of this property) maskTarget.isMaskingEnabled = maskTarget.isMaskingEnabled; } } if ((alphaTexturePrevious != null) && (alphaTexturePrevious != alphaTexture)) { maskTarget.SetMaskTextureInMaterials(alphaTexture); } alphaTexturePrevious = alphaTexture; } else { GUILayout.Label("Please attach MeshFilter and MeshRenderer.\nAlso assign a texture to MeshRenderer."); } if (GUI.changed) { EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { Mask maskTarget = (Mask)target; bool changesMade = false; if (maskTarget.GetComponents <Mask>().Length > 1) { GUILayout.Label("More than one instance of Mask attached.\nPlease only use one."); return; } if ((maskTarget.GetComponent <MeshRenderer>().sharedMaterial != null)) { Texture maskTexture = (Texture)EditorGUILayout.ObjectField("Main Tex:", maskTarget.MainTex, typeof(Texture), true); if (maskTexture != maskTarget.MainTex) { maskTarget.MainTex = maskTexture; changesMade = true; } Vector2 tiling = EditorGUILayout.Vector2Field("Tiling:", maskTarget.MainTexTiling); if (tiling != maskTarget.MainTexTiling) { maskTarget.MainTexTiling = tiling; changesMade = true; } Vector2 offset = EditorGUILayout.Vector2Field("Offset:", maskTarget.MainTexOffset); if (offset != maskTarget.MainTexOffset) { maskTarget.MainTexOffset = offset; changesMade = true; } bool isMaskingEnabled = EditorGUILayout.Toggle("Masking Enabled", maskTarget.IsMaskingEnabled); if (isMaskingEnabled != maskTarget.IsMaskingEnabled) { maskTarget.IsMaskingEnabled = isMaskingEnabled; changesMade = true; } bool clampAlphaHorizontally = EditorGUILayout.Toggle("Clamp Alpha Horizontally", maskTarget.ClampAlphaHorizontally); if (clampAlphaHorizontally != maskTarget.ClampAlphaHorizontally) { maskTarget.ClampAlphaHorizontally = clampAlphaHorizontally; changesMade = true; } bool clampAlphaVertically = EditorGUILayout.Toggle("Clamp Alpha Vertically", maskTarget.ClampAlphaVertically); if (clampAlphaVertically != maskTarget.ClampAlphaVertically) { maskTarget.ClampAlphaVertically = clampAlphaVertically; changesMade = true; } float clampingBorder = EditorGUILayout.FloatField("Clamping Border", maskTarget.ClampingBorder); if (clampingBorder != maskTarget.ClampingBorder) { maskTarget.ClampingBorder = clampingBorder; changesMade = true; } bool useMaskAlphaChannel = EditorGUILayout.Toggle("Use Mask Alpha Channel (not RGB)", maskTarget.UseMaskAlphaChannel); if (useMaskAlphaChannel != maskTarget.UseMaskAlphaChannel) { maskTarget.UseMaskAlphaChannel = useMaskAlphaChannel; changesMade = true; } if (!Application.isPlaying) { bool doDisplayMask = EditorGUILayout.Toggle("Display Mask", maskTarget.displayMaskReference); if (maskTarget.displayMaskReference != doDisplayMask) { maskTarget.displayMaskReference = doDisplayMask; changesMade = true; } } if (!Application.isPlaying) { if (GUILayout.Button("Apply Mask to Siblings in Hierarchy")) { ApplyMask(); changesMade = true; } } } else { GUILayout.Label("Please assign Mask-Material to mesh renderer."); } if (changesMade) { EditorUtility.SetDirty(target); } }