private void FieldSprites(List <EnergyBarUGUIBase.SpriteTex> sprites)
        {
            var arrayList = new MadGUI.ArrayList <EnergyBarUGUIBase.SpriteTex>(sprites, tex => {
                FieldSprite(tex, "");
                return(tex);
            });

            arrayList.onAdd += tex => tex.color = Color.white;

            if (arrayList.Draw())
            {
                EditorUtility.SetDirty((target as EnergyBarUGUIBase).gameObject);
            }
        }
Exemple #2
0
//    private void AtlasTextures(ref SerializedProperty textures, string label) {
//        if (MadGUI.Foldout(label, true)) {
//            var list = new MadGUI.ArrayList<EnergyBar3DBase.AtlasTex>(textures, (property) => {
//                var spriteName = property.FindPropertyRelative("spriteGUID");
//                var color = property.FindPropertyRelative("color");
//
//                AtlasTexture(spriteName, color);
//            });
//
//            list.Draw();
//        }
//    }

        private EnergyBar3DBase.AtlasTex[] AtlasTextures(EnergyBar3DBase.AtlasTex[] textures, string label)
        {
            if (MadGUI.Foldout(label, true))
            {
                var l = new List <EnergyBar3DBase.AtlasTex>();
                if (textures != null)
                {
                    l.AddRange(textures);
                }

                var list = new MadGUI.ArrayList <EnergyBar3DBase.AtlasTex>(l, (item) => {
                    var spriteGUID = item.spriteGUID;
                    var color      = item.color;

                    EditorGUI.BeginChangeCheck();
                    AtlasTexture(spriteGUID, ref color, (guid) => {
                        item.spriteGUID = guid;
                        EditorUtility.SetDirty(target);
                    });
                    if (EditorGUI.EndChangeCheck())
                    {
                        item.spriteGUID = spriteGUID;
                        item.color      = color;
                        EditorUtility.SetDirty(target);
                    }

                    return(item);
                });
                list.onAdd += (tex) => tex.color = Color.white;

                list.Draw();
                return(l.ToArray());
            }
            else
            {
                return(textures);
            }
        }
 protected void GUIAnimationRefList(SerializedProperty list, bool showFromTheBeginning) {
     var alist = new MadGUI.ArrayList<MadAnimator.AnimationRef>(list, (p) => {
         GUIAnimationRef(p, showFromTheBeginning);
     });
     alist.Draw();
 }
//    private void AtlasTextures(ref SerializedProperty textures, string label) {
//        if (MadGUI.Foldout(label, true)) {
//            var list = new MadGUI.ArrayList<EnergyBar3DBase.AtlasTex>(textures, (property) => {
//                var spriteName = property.FindPropertyRelative("spriteGUID");
//                var color = property.FindPropertyRelative("color");
//                
//                AtlasTexture(spriteName, color);
//            });
//            
//            list.Draw();
//        }
//    }
    
    private EnergyBar3DBase.AtlasTex[] AtlasTextures(EnergyBar3DBase.AtlasTex[] textures, string label) {
        if (MadGUI.Foldout(label, true)) {
            var l = new List<EnergyBar3DBase.AtlasTex>();
            if (textures != null) {
                l.AddRange(textures);
            }
            
            var list = new MadGUI.ArrayList<EnergyBar3DBase.AtlasTex>(l, (item) => {
                var spriteGUID = item.spriteGUID;
                var color = item.color;
                
                EditorGUI.BeginChangeCheck();
                AtlasTexture(spriteGUID, ref color, (guid) => {
                    item.spriteGUID = guid;
                    EditorUtility.SetDirty(target);
                });
                if (EditorGUI.EndChangeCheck()) {
                    item.spriteGUID = spriteGUID;
                    item.color = color;
                    EditorUtility.SetDirty(target);
                }

                return item;
            });
            list.onAdd += (tex) => tex.color = Color.white;
            
            list.Draw();
            return l.ToArray();
        } else {
            return textures;
        }
    }
 private void GUIModifiers(SerializedProperty listProperty) {
     var list = new MadGUI.ArrayList<MadLevelAnimator.Modifier>(listProperty, (p) => {
         GUIModifier(p);
     });
     list.Draw();
 }
    public override void OnInspectorGUI() {
        serializedObject.UpdateIfDirtyOrScript();
        
        MadGUI.PropertyField(draggable, "Draggable", MadGUI.ObjectIsSet);
        MadGUI.PropertyField(startDepth, "Start Depth", "Depth value of first layer added. "
            + "Every next layer will receive +1 to it's depth value.");
        MadGUI.PropertyField(ignoreXMovement, "Ignore X Movement");
        MadGUI.PropertyField(ignoreYMovement, "Ignore Y Movement");
        
        serializedObject.ApplyModifiedProperties();
        
        MadGUI.Info("Add new layers, then select them to edit properties for each layer.");
        
        var arrayList = new MadGUI.ArrayList<MadLevelBackgroundLayer>(script.layers, (layer) => {
                if (layer == null) {
                    return null;
                }
            
                var so = new SerializedObject(layer);
                so.UpdateIfDirtyOrScript();
                
                var texture = so.FindProperty("texture");
                
                EditorGUILayout.BeginHorizontal();
                
                MadGUI.PropertyField(texture, "");
                
                MadGUI.ConditionallyEnabled(CanMoveUp(layer), () => {
                    if (GUILayout.Button("Up")) {
                        MoveUp(layer);
                    }
                });
                
                MadGUI.ConditionallyEnabled(CanMoveDown(layer), () => {
                    if (GUILayout.Button("Down")) {
                        MoveDown(layer);
                    }
                });
                
                GUI.color = Color.yellow;
                if (GUILayout.Button("Select")) {
                    Selection.activeGameObject = layer.gameObject;
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
                
                if (so.ApplyModifiedProperties()) {
                    layer.SetDirty();
                }

                return layer;
        });
        
        arrayList.addLabel = "Add Layer";
        arrayList.emptyLabel = "There are currently no layers.";
        
        arrayList.createFunctionGeneric = () => {
            var layer = MadTransform.CreateChild<MadLevelBackgroundLayer>(script.transform, "layer (empty)");
            layer.GetComponent<MadSprite>().hideFlags = HideFlags.HideInInspector;
            return layer;
        };
        arrayList.onRemove = (layer) => layer.Cleanup();
        
        arrayList.beforeAdd = () => {
            MadUndo.RecordObject(script, "Add Background Layer");
            MadUndo.LegacyRegisterSceneUndo("Add Background Layer");
        };
        
        arrayList.beforeRemove = (arg) => {
            MadUndo.RecordObject(script, "Remove Background Layer");
            MadUndo.LegacyRegisterSceneUndo("Remove Background Layer");
        };
        
        if (arrayList.Draw()) {
            EditorUtility.SetDirty(script);
        }
        
    
        EditorGUI.BeginChangeCheck();
        
        if (EditorGUI.EndChangeCheck()) {
            // changed
        }
    }