Ejemplo n.º 1
0
        protected override void DrawElements(Rect position, SerializedProperty property, GUIContent label)
        {
            ColorLink instance      = GetInstance <ColorLink>();
            Object    instanceOwner = InstanceOwner;

            EditorGUI.LabelField(GetLineDrawingRect(), label);
            ColorPalette palette = (ColorPalette)EditorGUI.ObjectField(
                GetLineDrawingRect(), instance.Palette,
                typeof(ColorPalette), false
                );

            if (palette != instance.Palette)
            {
                Undo.RecordObject(instanceOwner, "Changing palette instance");
                instance.Palette = palette;
                OnInstanceChanged();
            }

            if (palette == null)
            {
                return;
            }

            HandlePaletteDrawing();
        }
Ejemplo n.º 2
0
 private void OnValidate()
 {
     Initialization();
     if (m_ColorLink == null)
     {
         m_ColorLink = new ColorLink(GetAction());
     }
 }
Ejemplo n.º 3
0
        private void HandlePaletteDrawing()
        {
            ColorLink    instance   = GetInstance <ColorLink>();
            ColorPalette palette    = instance.Palette;
            Vector2      squareSize = SquareSize;
            int          colorCount = palette.Count;

            if (Width < MinHeight)
            {
                return;
            }

            var squareCounts = GetSquareCounts(colorCount, Width);

            Vector2 drawingPositionBeforeRects = CurrentDrawingStart;

            DrawRects(squareCounts, palette);
            if (instance.Index >= 0)
            {
                int     index             = instance.Index;
                Vector2 indexGridPosition = GetGridPositionFromIndex(index, squareCounts);

                Vector2 start = drawingPositionBeforeRects + indexGridPosition * squareSize;
                Drawing.DrawRectBorder(start, squareSize, Color.cyan, 2);
            }

            Event current = Event.current;

            if (current.type == EventType.MouseDown)
            {
                Vector2 currentMousePosition = current.mousePosition;
                Rect    squaresRect          = new Rect(drawingPositionBeforeRects, new Vector2(Width, CurrentDrawingStart.y - drawingPositionBeforeRects.y));
                if (squaresRect.Contains(currentMousePosition))
                {
                    currentMousePosition -= squaresRect.min;
                    currentMousePosition /= squareSize;
                    int newIndex = (int)currentMousePosition.x +
                                   (int)currentMousePosition.y * squareCounts.x;
                    if (newIndex >= 0 && newIndex < colorCount)
                    {
                        Undo.RecordObject(InstanceOwner, "Changing palette link index");
                        instance.Index = newIndex;
                        OnInstanceChanged();
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void Awake()
 {
     Debug.Log("Awake Called");
     if (m_ColorLink != null)
     {
         int id      = m_ColorLink.Index;
         var palette = m_ColorLink.Palette;
         m_ColorLink = new ColorLink(m_ColorLink, GetAction())
         {
             Palette = palette, Index = id
         };
     }
     else
     {
         m_ColorLink = new ColorLink(GetAction());
     }
 }
Ejemplo n.º 5
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            ColorLink instance           = GetInstance <ColorLink>(property);
            float     lineHeight         = MinHeight;
            float     lineHeightMargined = MinHeight + Margin;

            if (instance.Palette == null)
            {
                return(lineHeightMargined * 2);
            }

            int     colorCount   = instance.Palette.Count;
            Vector2 squareCounts = GetSquareCounts(colorCount, EditorGUIUtility.currentViewWidth);

            return(lineHeightMargined +          // Label
                   lineHeightMargined +          // ColorPalette field
                   squareCounts.y * lineHeight + // Squares
                   Margin);                      // Final margin
        }
Ejemplo n.º 6
0
 public void AddLink(ColorLink Link)
 {
     Links.Add(Link);
 }
Ejemplo n.º 7
0
 public ColorGroup(ColorLink link)
 {
     this._Col = link.Color;
     this.Links.Add(link);
 }
Ejemplo n.º 8
0
 public void AddColorLink(ColorLink Link)
 {
     Tuples.AddRange(Link.Tuples);
 }