示例#1
0
    public void Update()
    {
        var skin = UiSkinManager.GetDefinition(_skinCode);

        if (!(skin == null && _skin == null) && ((skin == null ^ _skin == null) || skin != _skin))
        {
            Unregister();
            _skin = skin;
            if (_skin != null)
            {
                _skin.Apply(Attached);
                _skin.OnChange.Register(OnChange);
            }
        }
    }
示例#2
0
    public override void OnInspectorGUI()
    {
        bool changed = false;

        serializedObject.Update();
        _target = (UiSkinManager)target;
        Event ev = Event.current;

        HashSet <string> _codes = new HashSet <string>();

        var defsProp = serializedObject.FindProperty("_colorDefinitions");

        //var defs = _target.SkinDefinitions;
        //if( defsProp.arraySize == 0 )
        //	return;

        if (_folds == null)
        {
            _folds = new List <bool>();
        }
        while (_folds.Count > defsProp.arraySize)
        {
            _folds.RemoveAt(_folds.Count - 1);
        }
        while (_folds.Count < defsProp.arraySize)
        {
            _folds.Add(false);
        }

        for (int i = 0; i < defsProp.arraySize; i++)
        {
            SeparationLine.Horizontal();
            var def = defsProp.GetArrayElementAtIndex(i);

            var codeName = def.FindPropertyRelative("_code");
            var valid    = !_codes.Contains(codeName.stringValue);
            var color    = valid ? Color.white : Color.red;
            GuiColorManager.New(color);

            EditorGUILayout.BeginHorizontal();
            _folds[i] = EditorGUILayout.Foldout(_folds[i], (valid ? "" : "!UNUSED! ") + codeName.stringValue, K10GuiStyles.bigFoldStyle);


            var fxOrderProp = def.FindPropertyRelative("_effectOrder");
            var instance    = _target.SkinDefinitions[i];
            for (int e = 0; e < instance.FxCount; e++)
            {
                var fx = instance.GetFxAt(e);
                DrawFxIcon(fx);
            }

            bool canUp = i > 0;
            GuiColorManager.New((canUp) ? color : Color.gray);
            if (GUILayout.Button("↑", GUILayout.MaxWidth(15)) && canUp)
            {
                SwapSkins(i, i - 1);
            }
            GuiColorManager.Revert();

            bool canDown = i < defsProp.arraySize - 1;
            GuiColorManager.New((canDown) ? color : Color.gray);
            if (GUILayout.Button("↓", GUILayout.MaxWidth(15)) && canDown)
            {
                SwapSkins(i, i + 1);
            }
            GuiColorManager.Revert();

            GuiColorManager.New(new Color(.6f, .1f, .1f, 1));
            if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
            {
                K10EditorGUIUtils.RemoveItemFromArray(defsProp, i);
                i--;
                GuiColorManager.Revert();
                GuiColorManager.Revert();
                EditorGUILayout.EndHorizontal();
                continue;
            }

            GuiColorManager.Revert();
            EditorGUILayout.EndHorizontal();

            if (_folds[i])
            {
                SeparationLine.Horizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Codename", K10GuiStyles.smallboldStyle, GUILayout.Width(75));
                codeName.stringValue = EditorGUILayout.TextField(codeName.stringValue, K10GuiStyles.smalltextFieldStyle, GUILayout.Height(18));
                _codes.Add(codeName.stringValue);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                //GUILayout.Label( "Color", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 40 ) );
                ColorPicker.Layout(def.FindPropertyRelative("_color"));
                //def.Color = EditorGUILayout.ColorField( def.Color );
                //GUILayout.Label( "Font", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 35 ) );
                var fontProp = def.FindPropertyRelative("_font");
                fontProp.objectReferenceValue = (Font)EditorGUILayout.ObjectField(fontProp.objectReferenceValue, typeof(Font), false);
                EditorGUILayout.EndHorizontal();


                SeparationLine.Horizontal();
                GUILayout.Label("Effects", K10GuiStyles.titleStyle);
                SeparationLine.Horizontal();

                var shadowProp   = def.FindPropertyRelative("_shadow");
                var outlineProp  = def.FindPropertyRelative("_outline");
                var gradientProp = def.FindPropertyRelative("_gradient");

                var sid = UiSkinDefinition.GetID <UiShadowEffect>();
                var oid = UiSkinDefinition.GetID <UiOutlineEffect>();
                var gid = UiSkinDefinition.GetID <UiGradientEffect>();

                EditorGUILayout.BeginHorizontal();
                //GUILayout.FlexibleSpace();
                //EditorGUILayout.BeginVertical();
                ButtonAddEffect(fxOrderProp, sid, "Shadow");
                ButtonAddEffect(fxOrderProp, oid, "Outline");
                ButtonAddEffect(fxOrderProp, gid, "Gradient");
                //EditorGUILayout.EndVertical();
                //GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                if (fxOrderProp.arraySize > 0)
                {
                    SeparationLine.Horizontal();
                    GUILayout.Label("Edit Effects", K10GuiStyles.titleStyle);
                    for (int e = 0; e < fxOrderProp.arraySize; e++)
                    {
                        SeparationLine.Horizontal();
                        if (sid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditShadow(shadowProp, fxOrderProp, e);
                        }
                        else if (oid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditOutline(outlineProp, fxOrderProp, e);
                        }
                        else if (gid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditGradient(gradientProp, fxOrderProp, e);
                        }
                    }
                }
            }

            SeparationLine.Horizontal();
            EditorGUILayout.Space();
            GuiColorManager.Revert();
        }

        if (GUILayout.Button("Add New Skin Definition", K10GuiStyles.buttonStyle, GUILayout.Height(30)))
        {
            defsProp.arraySize++;
        }

        serializedObject.ApplyModifiedProperties();

        changed = true;
        if (changed)
        {
            UpdateInstances();
        }
    }
示例#3
0
 void OnChange(UiSkinDefinition skin)
 {
     skin.Apply(Attached);
 }