Example #1
0
        //button
        public bool Button(ICComRect position,
                           string label = "", string tooltip = "", GUIStyle style = null)
        {
            Com_Init(position, label, tooltip, style, ICEditorFunc.buttonStyle);

            return(GUI.Button(com_rect, com_content, com_style));
        }
Example #2
0
        //Element
        public void Element(string textureName, ICComRect position, RectOffset borders, RectOffset offset)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            position.Init(this);
            Rect rect = position.GetRect();

            GUIStyle elementStyle = new GUIStyle();

            elementStyle.normal.background = ICEditorFunc.GetIcon(textureName);
            elementStyle.hover.background  = ICEditorFunc.GetIcon(textureName);

            if (borders != null)
            {
                elementStyle.border = borders;
            }
            Rect paddedRect = ToDisplay(rect);

            if (offset != null)
            {
                paddedRect = new Rect(paddedRect.x - offset.left, paddedRect.y - offset.top, paddedRect.width + offset.left + offset.right, paddedRect.height + offset.top + offset.bottom);
            }

#if UNITY_EDITOR
            elementStyle.Draw(paddedRect, UnityEditor.EditorGUIUtility.isProSkin, false, false, false);
#endif
        }
Example #3
0
        //Toggle样式的button
        public void CheckButton(ref bool value, ICComRect position,
                                string label = "", string tooltip = "", GUIStyle style = null)
        {
            Com_Init(position, label, tooltip, style, ICEditorFunc.buttonStyle);

            value = GUI.Toggle(com_rect, value, com_content, com_style);
        }
Example #4
0
 //Label
 public void Label(ICComRect position,
                   string label, string tooltip = "", GUIStyle style = null,
                   TextAnchor textAnchor        = TextAnchor.UpperLeft)
 {
     Com_Init(position, label, tooltip, style, ICEditorFunc.labelStyle);
     com_style.alignment = textAnchor;
     GUI.Label(com_rect, com_content, com_style);
 }
Example #5
0
        public void OnEditorGUI(ICField field, ICLayout layout, ICComRect pos, SerializedObject serializedObject)
        {
            int    value = field.GetVariable <int>();
            string name  = (label != "") ? label : field.name;

            layout.IntField(ref value, pos, name, tooltip);
            serializedObject.FindProperty(field.name).intValue = value;
        }
Example #6
0
        public void Icon(ICComRect position, string texture,
                         IconAligment horizontalAlign = IconAligment.resize,
                         IconAligment verticalAlign   = IconAligment.resize,
                         bool tile = false)
        {
            var text = ICEditorFunc.GetIcon(texture);

            Icon(position, text, horizontalAlign, verticalAlign, tile);
        }
Example #7
0
        //box
        public void Box(ICComRect position,
                        string label   = "",
                        string tooltip = "", GUIStyle style = null
                        )
        {
            Com_Init(position, label, tooltip, style, ICEditorFunc.boxStyle);

            GUI.Box(com_rect, com_content, com_style);
        }
Example #8
0
        public void Icon(ICComRect position, Texture2D texture,
                         IconAligment horizontalAlign = IconAligment.resize,
                         IconAligment verticalAlign   = IconAligment.resize,
                         bool tile = false)
        {
#if UNITY_EDITOR
            if (texture == null)
            {
                return;
            }

            position.Init(this);
            var rect = position.GetRect(margin);

            //aligning texture if the rect width or height is more than icon size
            if (rect.width > texture.width)
            {
                switch (horizontalAlign)
                {
                case IconAligment.min: rect.width = texture.width; break;

                case IconAligment.center: rect.x += rect.width / 2; rect.x -= texture.width / 2; rect.width = texture.width; break;

                case IconAligment.max: rect.x += rect.width; rect.x -= texture.width; rect.width = texture.width; break;
                }
            }
            if (rect.height > texture.height)
            {
                switch (verticalAlign)
                {
                case IconAligment.min: rect.height = texture.height; break;

                case IconAligment.center: rect.y += rect.height / 2; rect.y -= texture.height / 2; rect.height = texture.height; break;

                case IconAligment.max: rect.y += rect.height; rect.y -= texture.height; rect.height = texture.height; break;
                }
            }
            if (!tile)
            {
                GUI.DrawTexture(ToDisplay(rect), texture, ScaleMode.ScaleAndCrop);
            }
            else
            {
                //Debug.Log(zoom);
                Rect localRect = ToDisplay(rect);
                for (float x = 0; x < rect.width; x += texture.width * zoom)
                {
                    for (float y = 0; y < rect.height + texture.height; y += texture.height * zoom)
                    {
                        GUI.DrawTexture(new Rect(x + localRect.x, y + localRect.y, texture.width * zoom + 1, texture.height * zoom + 1), texture, ScaleMode.StretchToFill);
                    }
                }
            }
#endif
        }
Example #9
0
        private void Com_Init(ICComRect position,
                              string label          = "", string tooltip = "", GUIStyle style = null,
                              GUIStyle defaultStyle = null)
        {
            position.Init(this);
            com_rect = ToDisplay(position.GetRect(margin));                //确定位置

            Style_Init(style, defaultStyle);

            com_content = new GUIContent(label, tooltip);
        }
Example #10
0
        //ColorBox
        public void ColorBox(ICComRect position, Color color)
        {
            Com_Init(position, "", "", null, ICEditorFunc.labelStyle);
            com_style.normal.background = Texture2D.whiteTexture;
            var back = GUI.backgroundColor;

            GUI.backgroundColor = color;
            GUI.Box(com_rect, com_content, com_style);

            GUI.backgroundColor = back;
        }
Example #11
0
        public void Vector2Field(ref Vector2 value, ICComRect position,
                                 string label = "", string tooltip = "Vector2 Value")
        {
            Com_Init(position, label, tooltip, null, ICEditorFunc.InputTextStyle);
            Rect LabelRect = com_rect.SplitRectHorizontal(0, 3);
            Rect XRect     = com_rect.SplitRectHorizontal(1, 3);
            Rect YRect     = com_rect.SplitRectHorizontal(2, 3);

#if UNITY_EDITOR
            Style_Init(ICEditorFunc.labelStyle);
            GUI.Label(LabelRect, com_content, com_style);
            Style_Init(ICEditorFunc.InputTextStyle);
            UnityEditor.EditorGUIUtility.labelWidth = 3;
            value.x = UnityEditor.EditorGUI.FloatField(XRect, " ", value.x, com_style);
            value.y = UnityEditor.EditorGUI.FloatField(YRect, " ", value.y, com_style);
            UnityEditor.EditorGUIUtility.labelWidth = 0;
#endif

            //value = UnityEditor.EditorGUI.Vector2Field(com_rect, "ss", value);
        }
Example #12
0
        public void Curve(ref AnimationCurve src, ICComRect position,
                          string label = "", string tooltip = "Float Value", GUIStyle style = null)
        {
            Com_Init(position, label, tooltip, null, ICEditorFunc.InputTextStyle);

#if UNITY_EDITOR
            //recording undo on change if the curve editor window is opened (and this current curve is selected)
            if (curveWindowType == null)
            {
                curveWindowType = typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.CurveEditorWindow");
            }
            if (UnityEditor.EditorWindow.focusedWindow != null && UnityEditor.EditorWindow.focusedWindow.GetType() == curveWindowType)
            {
                AnimationCurve windowCurve = curveWindowType.GetProperty("curve").GetValue(UnityEditor.EditorWindow.focusedWindow, null) as AnimationCurve;
                if (windowCurve == src)
                {
                    if (windowCurveRef == null)
                    {
                        windowCurveRef = windowCurve.Copy();
                    }
                    if (!windowCurve.IdenticalTo(windowCurveRef))
                    {
                        Keyframe[] tempKeys = windowCurve.keys;
                        windowCurve.keys = windowCurveRef.keys;
                        //SetChange(true);
                        //SetChange(true);

                        windowCurve.keys = tempKeys;

                        windowCurveRef = windowCurve.Copy();
                    }
                }
            }
            else
            {
                windowCurveRef = null;
            }

            UnityEditor.EditorGUI.CurveField(com_rect, src, Color.white, new Rect(0, 0, 1, 1));
#endif
        }
Example #13
0
        //Int Input
        public void IntField(ref int value, ICComRect position,
                             string label = "", string tooltip = "Float Value", GUIStyle style = null)
        {
            Com_Init(position, label, tooltip, style, ICEditorFunc.InputTextStyle);
#if UNITY_EDITOR
            var texture  = ICEditorFunc.GetIcon("ICMagic_Slider");
            var iconRect = com_rect.SplitRectHorizontal(1, 2).Move(-texture.width, 2);
            iconRect.height = texture.height; iconRect.width = texture.width;
            GUI.DrawTexture(ToDisplay(iconRect), texture, ScaleMode.ScaleAndCrop);


            UnityEditor.EditorGUIUtility.labelWidth = com_rect.width / 2;
            value = UnityEditor.EditorGUI.IntField(com_rect, " ", value, com_style);
            UnityEditor.EditorGUIUtility.labelWidth = 0;


            Style_Init(ICEditorFunc.labelStyle);
            com_style.alignment = TextAnchor.UpperLeft;
            GUI.Label(com_rect, com_content, com_style);
#endif
        }
Example #14
0
        //Float Input
        public void FloatField(ref float value, ICComRect position,
                               string label = "", string tooltip = "Float Value", GUIStyle style = null)
        {
            //Icon(new zSpeOneline(1, 4, false, position.height) { offset = new Rect(2,1,0,0)}
            //, "ICMagic_Slider",IconAligment.max,IconAligment.center);
            Com_Init(position, label, tooltip, style, ICEditorFunc.InputTextStyle);
#if UNITY_EDITOR
            var texture  = ICEditorFunc.GetIcon("ICMagic_Slider");
            var iconRect = com_rect.SplitRectHorizontal(1, 2).Move(-texture.width, 2);
            iconRect.height = texture.height; iconRect.width = texture.width;
            GUI.DrawTexture(ToDisplay(iconRect), texture, ScaleMode.ScaleAndCrop);


            UnityEditor.EditorGUIUtility.labelWidth = com_rect.width / 2;
            value = UnityEditor.EditorGUI.FloatField(com_rect, " ", value, com_style);
            UnityEditor.EditorGUIUtility.labelWidth = 0;


            Style_Init(ICEditorFunc.labelStyle);
            com_style.alignment = TextAnchor.UpperLeft;
            GUI.Label(com_rect, com_content, com_style);
#endif
        }
Example #15
0
 //空元素,用于新的定位
 public void Empty(ICComRect position)
 {
     Com_Init(position, "", "", null, null);
 }