protected void CheckTextureIsReadable(Texture2D texture) { if (texture == null) { return; } var path = AssetDatabase.GetAssetPath(texture); var importer = TextureImporter.GetAtPath(path) as TextureImporter; if ((importer.textureType != #if UNITY_5_5_OR_NEWER TextureImporterType.Default #else TextureImporterType.Advanced #endif && importer.textureType != TextureImporterType.GUI) || !importer.isReadable || importer.npotScale != TextureImporterNPOTScale.None) { if (MadGUI.ErrorFix("This texture must be set to Advanced/Readable without power of 2.")) { #if UNITY_5_5_OR_NEWER importer.textureType = TextureImporterType.Default; #else importer.textureType = TextureImporterType.Advanced; #endif importer.isReadable = true; importer.npotScale = TextureImporterNPOTScale.None; AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate); } } }
public override void OnInspectorGUI() { serializedObject.Update(); valueCurrent.intValue = (int)EditorGUILayout.Slider("Current Value", valueCurrent.intValue, valueMin.intValue, valueMax.intValue); MadGUI.PropertyField(valueMin, "Min Value"); MadGUI.PropertyField(valueMax, "Max Value"); MadGUI.PropertyField(spriteNameTemplate, "Sprite Name Template"); MadGUI.Info("Format: Use \"X\" to mark digit placeholder. For instance: sprite_XX will resolve to sprite_01, sprite_02 etc."); MadGUI.PropertyField(spriteNameNumberStart, "Sprite Number Start"); MadGUI.PropertyField(spriteNameNumberEnd, "Sprite Number End"); MadGUI.Info(string.Format("Will search for sprites {0} to {1}", UISequenceProgressBar.GetSpriteName(spriteNameNumberStart.intValue, spriteNameTemplate.stringValue), UISequenceProgressBar.GetSpriteName(spriteNameNumberEnd.intValue, spriteNameTemplate.stringValue))); if (GUILayout.Button("Make Pixel-Perfect")) { (target as UISequenceProgressBar).sprite.MakePixelPerfect(); } serializedObject.ApplyModifiedProperties(); }
protected void FieldSprite(SerializedProperty texture, SerializedProperty atlasTexture, string label) { if (UseAtlas()) { FieldAtlasSprite(atlasTexture, label); } else { MadGUI.PropertyField(texture, label, MadGUI.ObjectIsSet); } }
private void SectionAppearance() { GUILayout.Label("Appearance", "HeaderLabel"); using (MadGUI.Indent()) { FieldSetNativeSize(); EditorGUILayout.Space(); MadGUI.PropertyField(repeatCount, "Repeat Count"); MadGUI.PropertyFieldVector2(repeatPositionDelta, "Icons Distance"); MadGUI.PropertyField(repeatRotation, "Rotation"); using (MadGUI.Indent()) { MadGUI.PropertyField(repeatKeepOrientation, "Keep Orientation"); MadGUI.PropertyField(repeatKeepPosition, "Keep Position"); } EditorGUILayout.Space(); MadGUI.PropertyFieldEnumPopup(growType, "Grow Type"); using (MadGUI.EnabledIf(growType.enumValueIndex == (int)RepeatedRendererUGUI.GrowType.Fill)) { var index = growDirection.enumValueIndex; EditorGUI.BeginChangeCheck(); index = MadGUI.DynamicPopup(index, "Fill Direction", Enum.GetNames(typeof(EnergyBarBase.GrowDirection)).Length - 1, i => { return(SplitByCamelCase(Enum.GetNames(typeof(EnergyBarBase.GrowDirection))[i])); }); if (EditorGUI.EndChangeCheck()) { growDirection.enumValueIndex = index; } } FieldLabel2(); } }
private void EnsureSpriteRepeated(SerializedProperty spriteSP) { var sprite = (Sprite) spriteSP.objectReferenceValue; if (sprite == null) { return; } if (sprite.packed) { MadGUI.Error("This sprite shouldn't be packed! Please select it and remove the Packing Tag."); return; } if (sprite.rect.width != sprite.texture.width || sprite.rect.height != sprite.texture.height) { MadGUI.Error("This sprite shouldn't be packed! Please use the single texture instead."); return; } var texture = sprite.texture; var assetPath = AssetDatabase.GetAssetPath(texture); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (importer.wrapMode != TextureWrapMode.Repeat) { if (MadGUI.ErrorFix("Sprite wrap mode must be set to Repeat", "Fix Now")) { #if UNITY_5_5_OR_NEWER importer.textureType = TextureImporterType.Default; #else importer.textureType = TextureImporterType.Advanced; #endif importer.wrapMode = TextureWrapMode.Repeat; AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } } }
private void SectionObjectTransform() { GUILayout.Label("Object Transform", "HeaderLabel"); using (MadGUI.Indent()) { MadGUI.PropertyFieldToggleGroup2(transformTranslate, "Translate", () => { MadGUI.Indent(() => { MadGUI.PropertyFieldVector2(translateFunctionStart, "Start Point"); MadGUI.PropertyFieldVector2(translateFunctionEnd, "End Point"); MadGUI.PropertyField(translateAnimation, "Curve"); }); }); MadGUI.PropertyFieldToggleGroup2(transformRotate, "Rotate", () => { MadGUI.Indent(() => { MadGUI.PropertyField(rotateFunctionStart, "Start Angle"); MadGUI.PropertyField(rotateFunctionEnd, "End Angle"); MadGUI.PropertyField(rotateAnimation, "Curve"); }); }); MadGUI.PropertyFieldToggleGroup2(transformScale, "Scale", () => { MadGUI.Indent(() => { MadGUI.PropertyFieldVector2(scaleFunctionStart, "Start Scale"); MadGUI.PropertyFieldVector2(scaleFunctionEnd, "End Scale"); MadGUI.PropertyField(scaleAnimation, "Curve"); }); }); } }
protected void EnsureFullRect(SerializedProperty spriteObject) { var sprite = (Sprite)spriteObject.objectReferenceValue; if (sprite == null) { return; } var texture = sprite.texture; var assetPath = AssetDatabase.GetAssetPath(texture); var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter; var textureImporterSettings = new TextureImporterSettings(); importer.ReadTextureSettings(textureImporterSettings); if (textureImporterSettings.spriteMeshType != SpriteMeshType.FullRect) { if (MadGUI.ErrorFix("Texture Mesh Type must be set to Full Rect", "Fix Now")) { textureImporterSettings.spriteMeshType = SpriteMeshType.FullRect; importer.SetTextureSettings(textureImporterSettings); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } } }
protected void SectionDebugMode() { GUILayout.Label("Debug", "HeaderLabel"); using (MadGUI.Indent()) { MadGUI.PropertyField(debugMode, "Debug Mode"); } }
protected void FieldTextureMode() { MadGUI.PropertyFieldEnumPopup(textureMode, "Texture Mode"); if (energyBar3DBase.textureMode == EnergyBar3DBase.TextureMode.TextureAtlas) { MadGUI.PropertyField(atlas, "Texture Atlas", MadGUI.ObjectIsSet); } }
protected void FieldSmoothEffect() { MadGUI.PropertyFieldToggleGroup2(effectSmoothChange, "Smooth Effect", () => { MadGUI.Indent(() => { MadGUI.PropertyField(effectSmoothChangeSpeed, "Smooth Speed"); }); }); }
private void SectionAppearance() { GUILayout.Label("Appearance", "HeaderLabel"); using (MadGUI.Indent()) { FieldSetNativeSize(); EditorGUILayout.Space(); FieldLabel2(); } }
protected void FieldSetNativeSize() { if (MadGUI.Button("Set Native Size")) { var b = (EnergyBarUGUIBase)target; MadUndo.RecordObject2(b.gameObject, "Set Native Size"); b.SetNativeSize(); } }
private void SectionAppearance() { GUILayout.Label("Appearance", "HeaderLabel"); using (MadGUI.Indent()) { FieldSetNativeSize(); EditorGUILayout.Space(); var dir = (EnergyBarBase.GrowDirection)growDirection.enumValueIndex; if (dir == EnergyBarBase.GrowDirection.ColorChange) { GUI.enabled = false; } MadGUI.PropertyField(spriteBarColorType, "Bar Color Type"); EditorGUI.indentLevel++; switch ((EnergyBarBase.ColorType)spriteBarColorType.enumValueIndex) { case EnergyBarBase.ColorType.Solid: MadGUI.PropertyField(spriteBarColor, "Bar Color"); break; case EnergyBarBase.ColorType.Gradient: MadGUI.PropertyField(spriteBarGradient, "Bar Gradient"); break; } EditorGUI.indentLevel--; GUI.enabled = true; FieldGrowDirection(); MadGUI.PropertyField(spriteBarMinSize, "Min Size"); using (MadGUI.Indent()) { if (dir == EnergyBarBase.GrowDirection.RadialCW || dir == EnergyBarBase.GrowDirection.RadialCCW) { MadGUI.Indent(() => { EditorGUILayout.Slider(radialOffset, -1, 1, "Offset"); EditorGUILayout.Slider(radialLength, 0, 1, "Length"); }); } else if (dir == EnergyBarBase.GrowDirection.ColorChange) { EditorGUILayout.PropertyField(spriteBarGradient, new GUIContent("Bar Gradient")); } } EditorGUILayout.Space(); MadGUI.PropertyField(barImageScale, "Bar Scale"); MadGUI.PropertyField(barImageOffset, "Bar Offset"); EditorGUILayout.Space(); FieldLabel2(); GUI.enabled = true; } }
protected void FieldRelativeToTransform() { MadGUI.PropertyField(positionSizeFromTransform, "Relative To Transform", "Affects position and size by this game object transform."); if (positionSizeFromTransform.boolValue) { MadGUI.Indent(() => { MadGUI.PropertyField(positionSizeFromTransformNormalized, "Normalized"); }); } }
protected void Section(string name, SectionBody body) { GUILayout.Label(name, "HeaderLabel"); EditorGUILayout.Space(); MadGUI.Indent(() => { body(); }); EditorGUILayout.Space(); }
public void FieldSprite(SerializedProperty p, string label, MadGUI.Validator validator) { var sprite = p.FindPropertyRelative("sprite"); var color = p.FindPropertyRelative("color"); EditorGUILayout.BeginHorizontal(); MadGUI.PropertyField(sprite, label, validator); EditorGUILayout.PropertyField(color, new GUIContent(""), GUILayout.Width(90)); //MadGUI.PropertyField(color, ""); EditorGUILayout.EndHorizontal(); }
void FieldSequenceTextures() { if (UseAtlas()) { int size = script.sequenceAtlasTexturesGUID.Length; int nSize = FieldTextureCount(); EditorGUILayout.Space(); FieldBatchTextureSet(); EditorGUILayout.Space(); MadGUI.Indent(() => { if (size != nSize) { MadUndo.RecordObject2(script, "Texture Count Resize"); System.Array.Resize(ref script.sequenceAtlasTexturesGUID, nSize); EditorUtility.SetDirty(script); } if (sequenceAtlasTexturesGUID.arraySize == 0) { ZeroTexturesWarning(); } for (int i = 0; i < sequenceAtlasTexturesGUID.arraySize; ++i) { var element = sequenceAtlasTexturesGUID.GetArrayElementAtIndex(i); FieldAtlasSprite(element, "Texture " + i); } }); } else { int size = script.sequenceTextures.Length; int nSize = FieldTextureCount(); EditorGUILayout.Space(); MadGUI.Indent(() => { if (size != nSize) { MadUndo.RecordObject2(script, "Texture Count Resize"); System.Array.Resize(ref script.sequenceTextures, nSize); EditorUtility.SetDirty(script); } if (sequenceTextures.arraySize == 0) { ZeroTexturesWarning(); } for (int i = 0; i < sequenceTextures.arraySize; ++i) { var element = sequenceTextures.GetArrayElementAtIndex(i); MadGUI.PropertyField(element, "Texture " + i); } }); } }
public override void OnInspectorGUI() { serializedObject.Update(); var t = target as RepeatedRenderer3D; Header(); Section("Textures", () => { FieldTextureMode(); EditorGUILayout.BeginHorizontal(); FieldSprite(textureIcon, atlasTextureIconGUID, "Icon"); //MadGUI.PropertyField(textureIcon, "Icon"); EditorGUILayout.PropertyField(tintIcon, new GUIContent(""), new GUILayoutOption[] { GUILayout.Width(50) }); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); FieldSprite(textureSlot, atlasTextureSlotGUID, "Slot"); //MadGUI.PropertyField(textureSlot, "Slot"); EditorGUILayout.PropertyField(tintSlot, new GUIContent(""), new GUILayoutOption[] { GUILayout.Width(50) }); EditorGUILayout.EndHorizontal(); FieldPremultipliedAlpha(); CheckTextureIsReadable(t.textureIcon); CheckTextureIsReadable(t.textureSlot); }); SectionPositionAndSize(); Section("Appearance", () => { MadGUI.PropertyField(repeatCount, "Repeat Count"); MadGUI.PropertyFieldVector2(repeatPositionDelta, "Icon Distance"); MadGUI.PropertyField(repeatRotationDelta, "Icon Rotation"); MadGUI.PropertyField(growType, "Grow Type"); MadGUI.ConditionallyEnabled(growType.enumValueIndex == (int) RepeatedRenderer3D.GrowType.Fill, () => { MadGUI.PropertyField(fillDirection, "Fill Direction"); }); FieldLabel(); }); Section("Effects", () => { FieldSmoothEffect(); }); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
protected void FieldNotify(SerializedProperty serializedProperty, string label) { var receiver = serializedProperty.FindPropertyRelative("receiver"); var methodName = serializedProperty.FindPropertyRelative("methodName"); MadGUI.PropertyField(receiver, label); if (receiver.objectReferenceValue != null) { using (MadGUI.Indent()) { MadGUI.PropertyField(methodName, "Message"); } } }
private void SectionTextures() { GUILayout.Label("Textures", "HeaderLabel"); using (MadGUI.Indent()) { FieldBackgroundSprites(); EditorGUILayout.Space(); MadGUI.PropertyFieldEnumPopup(renderMethod, "Render Method"); switch (renderer.renderMethod) { case SequenceRendererUGUI.RenderMethod.Grid: FieldSprite(gridSprite, "Sprite", MadGUI.ObjectIsSet); using (MadGUI.Indent()) { MadGUI.PropertyField(gridSprite.FindPropertyRelative("material"), "Material"); } using (MadGUI.Indent()) { MadGUI.PropertyField(gridWidth, "Grid Width"); MadGUI.PropertyField(gridHeight, "Grid Height"); MadGUI.PropertyField(frameCountAuto, "Frame Count Auto"); showFrameCount.target = !frameCountAuto.boolValue; if (EditorGUILayout.BeginFadeGroup(showFrameCount.faded)) { if (renderer.frameCountAuto) { frameCount.intValue = gridWidth.intValue * gridHeight.intValue; } MadGUI.PropertyField(frameCount, "Frame Count"); } EditorGUILayout.EndFadeGroup(); } break; case SequenceRendererUGUI.RenderMethod.Sequence: sequenceSpritesList.DoLayoutList(); MadGUI.PropertyField(sequenceTint, "Tint"); break; default: throw new ArgumentOutOfRangeException(); } EditorGUILayout.Space(); //serializedObject.UpdateIfDirtyOrScript(); // MadGUI.PropertyField(spriteBar, "Bar"); //serializedObject.ApplyModifiedProperties(); EditorGUILayout.Space(); FieldForegroundSprites(); } }
private void SectionTextures() { Section("Textures", () => { FieldTextureMode(); if (script.textureMode != EnergyBar3DBase.TextureMode.TextureAtlas || script.atlas != null) { FieldBackgroundTextures(); FieldSprite(objectTexture, objectAtlasTextureGUID, "Object Texture"); MadGUI.PropertyFieldVector2(objectAnchor, "Object Anchor"); FieldForegroundTextures(); } FieldPremultipliedAlpha(); }); }
protected void FieldLabel() { bool classic = labelFont == null; // true if classic GUI version MadGUI.PropertyFieldToggleGroup2(labelEnabled, "Draw Label", () => { MadGUI.Indent(() => { if (classic) { EditorGUILayout.PropertyField(labelSkin, new GUIContent("Label Skin")); } else { MadGUI.PropertyField(labelFont, "Label Font", MadGUI.ObjectIsSet); MadGUI.PropertyField(labelScale, "Label Scale"); } labelPosition.vector2Value = EditorGUILayout.Vector2Field("Label Position", labelPosition.vector2Value); var t = target as EnergyBarBase; if (MadGameObject.IsActive(t.gameObject)) { var rect = t.DrawAreaRect; PropertySpecialNormalized(labelPosition, labelPositionNormalized, new Vector2(rect.width, rect.height)); } if (labelPivot != null) { MadGUI.PropertyField(labelPivot, "Pivot Point"); } EditorGUILayout.PropertyField(labelFormat, new GUIContent("Label Format")); if (MadGUI.Foldout("Label Format Help", false)) { EditorGUILayout.HelpBox(FormatHelp, MessageType.None); } EditorGUILayout.PropertyField(labelColor, new GUIContent("Label Color")); if (classic) { MadGUI.PropertyFieldToggleGroup2(labelOutlineEnabled, "Label Outline", () => { MadGUI.Indent(() => { EditorGUILayout.PropertyField(labelOutlineColor, new GUIContent("Outline Color")); }); }); } }); }); }
void OnGUI() { MadGUI.Info("There's more than one Panel on the scene. Please set the one that you want to create the bar on."); panel = EditorGUILayout.ObjectField("Panel", panel, typeof(MadPanel), true) as MadPanel; barType = (EnergyBar3DBase.BarType)EditorGUILayout.EnumPopup("Bar Type", barType); GUI.enabled = panel != null; if (MadGUI.Button("Create", Color.green)) { EnergyBarUtils.Create3DBar(barType, panel); Close(); } GUI.enabled = true; }
protected void FieldSmoothEffect() { smoothEffectAnimBool.target = effectSmoothChange.boolValue; MadGUI.PropertyField(effectSmoothChange, "Smooth Effect"); if (EditorGUILayout.BeginFadeGroup(smoothEffectAnimBool.faded)) { MadGUI.Indent(() => { MadGUI.PropertyField(effectSmoothChangeSpeed, "Speed"); MadGUI.PropertyFieldEnumPopup(effectSmoothChangeDirection, "Direction"); FieldNotify(effectSmoothChangeFinishedNotify, "On Finished"); }); EditorGUILayout.Space(); } EditorGUILayout.EndFadeGroup(); }
// =========================================================== // Methods // =========================================================== private void OnGUIGrid() { EditorGUILayout.PropertyField(gridTexture, new GUIContent("Grid Texture")); CheckTextureIsGUI(gridTexture.objectReferenceValue as Texture2D); EditorGUILayout.PropertyField(gridWidth, new GUIContent("Grid Width")); EditorGUILayout.PropertyField(gridHeight, new GUIContent("Grid Height")); MadGUI.PropertyFieldToggleGroup2(frameCountManual, "Manual Frame Count", () => { MadGUI.PropertyField(frameCount, "Frame Count"); }); // frameCountManual.boolValue = EditorGUILayout.BeginToggleGroup("Manual Frame Count", frameCountManual.boolValue); { // EditorGUILayout.EndToggleGroup(); }
protected void FieldLabel2() { MadGUI.PropertyField(label, "Label"); using (MadGUI.EnabledIf((target as EnergyBarUGUIBase).label != null)) { using (MadGUI.Indent()) { MadGUI.PropertyField(labelFormat, "Format"); formatHelpAnimBool.target = MadGUI.Foldout("Label Format Help", false); if (EditorGUILayout.BeginFadeGroup(formatHelpAnimBool.faded)) { EditorGUILayout.HelpBox(FormatHelp, MessageType.None); } EditorGUILayout.EndFadeGroup(); } } }
void GUIAction(SerializedProperty prop, bool withInterval) { var changeBar = prop.FindPropertyRelative("changeBar"); var changeBarType = prop.FindPropertyRelative("changeBarType"); var changeBarValue = prop.FindPropertyRelative("changeBarValue"); var sendMessage = prop.FindPropertyRelative("sendMessage"); var intervaled = prop.FindPropertyRelative("intervaled"); var timeInterval = prop.FindPropertyRelative("timeInterval"); var signals = prop.FindPropertyRelative("signals"); MadGUI.PropertyFieldToggleGroup(changeBar, "Change Bar", () => { MadGUI.Indent(() => { MadGUI.PropertyField(changeBarType, "Change Method"); MadGUI.Indent(() => { string example; switch ((SimpleEvent.Action.Type)changeBarType.enumValueIndex) { case SimpleEvent.Action.Type.DecreaseByPercent: case SimpleEvent.Action.Type.IncreaseByPercent: case SimpleEvent.Action.Type.SetToPercent: example = " (0.0 - 1.0)"; break; default: example = ""; break; } MadGUI.PropertyField(changeBarValue, "Value" + example); intervaled.boolValue = withInterval; if (withInterval) { MadGUI.PropertyField(timeInterval, "Time Interval"); } }); }); }); MadGUI.PropertyFieldToggleGroup(sendMessage, "Send Message", () => { MadGUI.Indent(() => { ArrayList(signals, "Signals", (signalProp) => { GUISignal(signalProp); }); }); }); }
private void SectionTextures() { GUILayout.Label("Textures", "HeaderLabel"); using (MadGUI.Indent()) { FieldBackgroundSprites(); EditorGUILayout.Space(); FieldSprite(spriteObject, "Object Sprite", MadGUI.ObjectIsSet); using (MadGUI.Indent()) { MadGUI.PropertyField(spriteObject.FindPropertyRelative("material"), "Material"); } MadGUI.PropertyFieldVector2(spriteObjectPivot, "Object Pivot"); EditorGUILayout.Space(); FieldForegroundSprites(); } }
private void SectionTextures() { GUILayout.Label("Textures", "HeaderLabel"); using (MadGUI.Indent()) { FieldBackgroundSprites(); EditorGUILayout.Space(); MadGUI.PropertyField(spriteBar, "Bar", MadGUI.ObjectIsSet); #if !UNITY_5 EnsureReadable(spriteBar); #endif EditorGUILayout.Space(); FieldForegroundSprites(); } }
private void SectionTextures() { Section("Textures", () => { MadGUI.PropertyField(renderingMethod, "Render Method"); FieldTextureMode(); EditorGUILayout.Space(); if (script.textureMode != EnergyBar3DBase.TextureMode.TextureAtlas || script.atlas != null) { switch (script.renderingMethod) { case SequenceRenderer3D.Method.Grid: FieldSprite(gridTexture, gridAtlasTextureGUID, "Bar Texture"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Grid Size"); GUILayout.FlexibleSpace(); MadGUI.LookLikeControls(30, 50); EditorGUILayout.PropertyField(gridWidth, new GUIContent("W")); MadGUI.PropertyField(gridHeight, "H"); MadGUI.LookLikeControls(0, 0); EditorGUILayout.EndHorizontal(); MadGUI.PropertyField(gridFrameCountManual, "Manual Frame Count"); MadGUI.ConditionallyEnabled(gridFrameCountManual.boolValue, () => { MadGUI.PropertyField(gridFrameCount, "Frame Count"); }); break; case SequenceRenderer3D.Method.Sequence: FieldSequenceTextures(); break; } EditorGUILayout.Space(); MadGUI.PropertyField(gridTint, "Tint"); EditorGUILayout.Space(); FieldBackgroundTextures(); FieldForegroundTextures(); FieldPremultipliedAlpha(); } }); }