Exemplo n.º 1
0
    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);
            }
        }

    }
Exemplo n.º 2
0
    public override void OnCustomInspector() {
        serializedObject.Update();

        Header();
        
        Section("Textures", () => {
            FieldTextureMode();

            EditorGUILayout.Space();

            if (script.textureMode != EnergyBar3DBase.TextureMode.TextureAtlas || script.atlas != null) {
                FieldBackgroundTextures();

                EditorGUILayout.Space();

                FieldSprite(textureBar, atlasTextureBarGUID, "Bar Texture");

                EditorGUILayout.Space();
                
                CheckTextureIsReadable(script.textureBar);
                CheckTextureFilterTypeNotPoint(script.textureBar);

                FieldForegroundTextures();

                FieldPremultipliedAlpha();
            }
        });

        if (showPositionAndSize) {
            SectionPositionAndSize();
        }

        Section("Appearance", () => {
            var dir = (EnergyBarRenderer.GrowDirection) growDirection.enumValueIndex;

            if (dir == EnergyBarRenderer.GrowDirection.ColorChange) {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(textureBarColorType, new GUIContent("Bar Color Type"));
            EditorGUI.indentLevel++;
            switch ((EnergyBarRenderer.ColorType) textureBarColorType.enumValueIndex) {
                case EnergyBarRenderer.ColorType.Solid:
                    EditorGUILayout.PropertyField(textureBarColor, new GUIContent("Bar Color"));
                    break;

                case EnergyBarRenderer.ColorType.Gradient:
                    EditorGUILayout.PropertyField(textureBarGradient, new GUIContent("Bar Gradient"));
                    break;
            }

            EditorGUI.indentLevel--;

            GUI.enabled = true;

            MadGUI.PropertyFieldEnumPopup(growDirection, "Grow Direction");

            if (dir == EnergyBarRenderer.GrowDirection.RadialCW || dir == EnergyBarRenderer.GrowDirection.RadialCCW) {
                MadGUI.Indent(() => {
                    EditorGUILayout.Slider(radialOffset, -1, 1, "Offset");
                    EditorGUILayout.Slider(radialLength, 0, 1, "Length");
                });
            } else if (dir == EnergyBarRenderer.GrowDirection.ColorChange) {
                EditorGUILayout.PropertyField(textureBarGradient, new GUIContent("Bar Gradient"));
            }

            FieldLabel();
        });

        Section("Effects", () => {
            FieldSmoothEffect();

            MadGUI.PropertyFieldToggleGroup2(effectBurn, "Burn Out", () => {
                MadGUI.Indent(() => {
                    FieldSprite(effectBurnTextureBar, atlasEffectBurnTextureBarGUID, "Burn Texture Bar");
                    MadGUI.PropertyField(effectBurnTextureBarColor, "Burn Color");
                });
            });

            MadGUI.PropertyFieldToggleGroup2(effectBlink, "Blink", () => {
                MadGUI.Indent(() => {
                    MadGUI.PropertyField(effectBlinkValue, "Value");
                    MadGUI.PropertyField(effectBlinkRatePerSecond, "Rate (per second)");
                    MadGUI.PropertyField(effectBlinkColor, "Color");
                });
            });

            MadGUI.PropertyFieldToggleGroup2(effectFollow, "Sprite Follow", () => {
                MadGUI.Indent(() => {
                    if (GUI.enabled && !GrowDirectionSupportedByFollowEffect()) {
                        MadGUI.Error("This effect cannot be used with selected grow direction. "
                            + "Please read manual for more information.");
                    }

                    MadGUI.PropertyField(effectFollowObject, "Texture or GameObject",
                        "This can be Texture, MadSprite or any other GameObject.");

                    if (!VerifyFollowObject()) {
                        MadGUI.Error("You can put here only Texture2D or GameObject.");
                    }

                    MadGUI.PropertyField(effectFollowColor, "Color");
                    MadGUI.PropertyField(effectFollowRotation, "Rotation");
                    if (MadGUI.Foldout("Scale", false)) {
                        MadGUI.Indent(() => {
                            MadGUI.PropertyField(effectFollowScaleX, "X");
                            MadGUI.PropertyField(effectFollowScaleY, "Y");
                            MadGUI.PropertyField(effectFollowScaleZ, "Z");
                        });
                    }


                });
            });
        });
        
        EditorGUILayout.Space();
        
        serializedObject.ApplyModifiedProperties();
    }
    private void SectionEffects() {
        GUILayout.Label("Effects", "HeaderLabel");
        using (MadGUI.Indent()) {
            FieldSmoothEffect();

            burnEffectAnimBool.target = effectBurn.boolValue;
            MadGUI.PropertyField(effectBurn, "Burn");
            if (EditorGUILayout.BeginFadeGroup(burnEffectAnimBool.faded)) {
                MadGUI.Indent(() => {
                    FieldSprite(effectBurnSprite, "Bar Texture");
                    MadGUI.PropertyField(effectBurnSprite.FindPropertyRelative("material"), "Material");

                    MadGUI.PropertyFieldEnumPopup(effectBurnDirection, "Direction");
                    if (effectBurnDirection.enumValueIndex != (int) EnergyBarBase.BurnDirection.OnlyWhenDecreasing &&
                        !effectSmoothChange.boolValue) {
                        if (
                            MadGUI.WarningFix(
                                "Burning when increasing will be visible only if the Smooth effect is enabled.",
                                "Enable Smooth Effect")) {
                            effectSmoothChange.boolValue = true;
                        }
                    }
                    MadGUI.PropertyField(effectSmoothChangeSpeed, "Speed");
                });
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndFadeGroup();

            blinkEffectAnimBool.target = effectBlink.boolValue;
            MadGUI.PropertyField(effectBlink, "Blink");
            if (EditorGUILayout.BeginFadeGroup(blinkEffectAnimBool.faded)) {
                MadGUI.Indent(() => {
                    MadGUI.PropertyFieldEnumPopup(effectBlinkOperator, "Operator");
                    MadGUI.PropertyField(effectBlinkValue, "Value");
                    MadGUI.PropertyField(effectBlinkRatePerSecond, "Rate (per second)");
                    MadGUI.PropertyField(effectBlinkColor, "Color");
                });
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndFadeGroup();

            tiledEffectAnimBool.target = effectTiled.boolValue;
            MadGUI.PropertyField(effectTiled, "Tiled");
            if (EditorGUILayout.BeginFadeGroup(tiledEffectAnimBool.faded)) {
                MadGUI.Indent(() => {
                    EditorGUILayout.BeginHorizontal();
                    MadGUI.PropertyField(effectTiledSprite, "Sprite", MadGUI.ObjectIsSet);
                    EditorGUILayout.PropertyField(effectTiledTint, new GUIContent(""), GUILayout.Width(90));
                    EditorGUILayout.EndHorizontal();

                    EnsureSpriteRepeated(effectTiledSprite);

                    MadGUI.PropertyFieldVector2(effectTiledTiling, "Tiling");
                    MadGUI.PropertyFieldVector2(effectTiledStartOffset, "Start Offset");
                    MadGUI.PropertyFieldVector2(effectTiledOffsetChangeSpeed, "Speed");
                });
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndFadeGroup();

            followEffectAnimBool.target = effectFollow.boolValue;
            MadGUI.PropertyField(effectFollow, "Follow");
            if (EditorGUILayout.BeginFadeGroup(followEffectAnimBool.faded)) {
                using (MadGUI.Indent()) {
                    if (!GrowDirectionSupportedByFollowEffect()) {
                        MadGUI.Error("This effect cannot be used with selected grow direction. "
                                     + "Please read manual for more information.");
                    }

                    MadGUI.PropertyField(effectFollowObject, "GameObject");
                    MadGUI.PropertyField(effectFollowOffset, "Position Offset");

                    EditorGUILayout.Space();

                    MadGUI.PropertyField(effectFollowColor, "Color");
                    MadGUI.PropertyField(effectFollowRotation, "Rotation");
                    if (MadGUI.Foldout("Scale", false)) {
                        MadGUI.Indent(() => {
                            MadGUI.PropertyField(effectFollowScaleX, "X");
                            MadGUI.PropertyField(effectFollowScaleY, "Y");
                            MadGUI.PropertyField(effectFollowScaleZ, "Z");
                        });
                    }
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndFadeGroup();
        }
    }
    public override void OnInspectorGUI() {
        serializedObject.Update();
        
        script = target as FilledRenderer3D;
        
        if (MadGUI.Foldout("Textures", true)) {
            MadGUI.BeginBox();
            FieldBackgroundTextures();
            
            EditorGUILayout.PropertyField(textureBar, new GUIContent("Bar Texture"));         
            CheckTextureIsReadable(script.textureBar);
            CheckTextureFilterTypeNotPoint(script.textureBar);
            
            FieldForegroundTextures();
            
            FieldPremultipliedAlpha();
            MadGUI.EndBox();
        }
        
        if (showPositionAndSize && MadGUI.Foldout("Position & Size", true)) {
            MadGUI.BeginBox();
            
            if (MadGUI.Button("Make Pixel-Perfect")) {
                script.transform.localPosition = MadMath.Round(script.transform.localPosition);
                script.transform.localScale = new Vector3(1, 1, 1);
                EditorUtility.SetDirty(script);
            }
            
            if (!IsAnchored()) {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Anchor");
                if (GUILayout.Button("Create")) {
                    CreateAnchor();
                }
                EditorGUILayout.EndHorizontal();
            } else {
                var anchor = GetAnchor();
                var serAnchor = new SerializedObject(anchor);
                MadAnchorInspector.DrawInspector(serAnchor);
            }

            EditorGUI.BeginChangeCheck();
            script.pivot = (EnergyBar3DBase.Pivot) EditorGUILayout.EnumPopup("Pivot Point", script.pivot);
            if (EditorGUI.EndChangeCheck()) {
                EditorUtility.SetDirty(script);
            }
            MadGUI.PropertyField(guiDepth, "GUI Depth");
            MadGUI.EndBox();
        }
        
        if (MadGUI.Foldout("Appearance", false)) {
            MadGUI.BeginBox();
            
            var dir = (EnergyBarRenderer.GrowDirection) growDirection.enumValueIndex;
        
            if (dir == EnergyBarRenderer.GrowDirection.ColorChange) {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(textureBarColorType, new GUIContent("Bar Color Type"));
            EditorGUI.indentLevel++;
                switch ((EnergyBarRenderer.ColorType)textureBarColorType.enumValueIndex) {
                    case EnergyBarRenderer.ColorType.Solid:
                        EditorGUILayout.PropertyField(textureBarColor, new GUIContent("Bar Color"));
                        break;
                        
                    case EnergyBarRenderer.ColorType.Gradient:
                        EditorGUILayout.PropertyField(textureBarGradient, new GUIContent("Bar Gradient"));
                        break;
                }
                
            EditorGUI.indentLevel--;
            
            GUI.enabled = true;
            
            EditorGUILayout.PropertyField(growDirection, new GUIContent("Grow Direction"));
            
            if (dir == EnergyBarRenderer.GrowDirection.RadialCW || dir == EnergyBarRenderer.GrowDirection.RadialCCW) {
                MadGUI.Indent(() => {
                    EditorGUILayout.Slider(radialOffset, -1, 1, "Offset");
                    EditorGUILayout.Slider(radialLength, 0, 1, "Length");
                });
            } else if (dir == EnergyBarRenderer.GrowDirection.ColorChange) {
                EditorGUILayout.PropertyField(textureBarGradient, new GUIContent("Bar Gradient"));
            }
            
            FieldLabel();
            
            MadGUI.EndBox();
        }
        
        if (MadGUI.Foldout("Effects", false)) {
            MadGUI.BeginBox();
            
            FieldSmoothEffect();
            
            MadGUI.PropertyFieldToggleGroup2(effectBurn, "Burn Out", () => {
                MadGUI.Indent(() => {
                    MadGUI.PropertyField(effectBurnTextureBar, "Burn Texture Bar");
                    MadGUI.PropertyField(effectBurnTextureBarColor, "Burn Color");
                });
            });
            
            MadGUI.PropertyFieldToggleGroup2(effectBlink, "Blink", () => {
                MadGUI.Indent(() => {
                    MadGUI.PropertyField(effectBlinkValue, "Value");
                    MadGUI.PropertyField(effectBlinkRatePerSecond, "Rate (per second)");
                    MadGUI.PropertyField(effectBlinkColor, "Color");
                });
            });
            
            MadGUI.PropertyFieldToggleGroup2(effectFollow, "Sprite Follow", () => {
                MadGUI.Indent(() => {
                    if (GUI.enabled && !GrowDirectionSupportedByFollowEffect()) {
                        MadGUI.Error("This effect cannot be used with selected grow direction. "
                            + "Please read manual for more information.");
                    }
                
                    MadGUI.PropertyField(effectFollowObject, "Texture or GameObject",
                        "This can be Texture, MadSprite or any other GameObject.");
                        
                    if (!VerifyFollowObject()) {
                        MadGUI.Error("You can put here only Texture2D or GameObject.");
                    }
                        
                    MadGUI.PropertyField(effectFollowColor, "Color");
                    MadGUI.PropertyField(effectFollowRotation, "Rotation");
                    if (MadGUI.Foldout("Scale", false)) {
                        MadGUI.Indent(() => {
                            MadGUI.PropertyField(effectFollowScaleX, "X");
                            MadGUI.PropertyField(effectFollowScaleY, "Y");
                            MadGUI.PropertyField(effectFollowScaleZ, "Z");
                        });
                    }
                    
                    
                });
            });
            
            MadGUI.EndBox();
        }
        
        EditorGUILayout.Space();
        
        serializedObject.ApplyModifiedProperties();
    }