示例#1
0
        void OnEnable()
        {
            m_colorIndexProperty         = serializedObject.FindProperty("colorIndex");
            m_reactProperty              = serializedObject.FindProperty("react");
            m_customPaletteIndexProperty = serializedObject.FindProperty("customPaletteIndex");
            m_overrideAlphaProperty      = serializedObject.FindProperty("overrideAlpha");
            m_alphaProperty              = serializedObject.FindProperty("alpha");

            m_target = (ColorPaletteObject)target;
        }
示例#2
0
        private bool doSelectedGameObjectHaveSameColor()
        {
            Object[] targetObjectArray = serializedObject.targetObjects;
            Color    referenceColor    = ((ColorPaletteObject)targetObjectArray[0]).getColor();

            for (int i = 0; i < targetObjectArray.Length; i++)
            {
                ColorPaletteObject colorPaletteObject = (ColorPaletteObject)targetObjectArray[i];
                if (!referenceColor.Equals(colorPaletteObject.getColor()))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            // Draw the enum
            EditorGUILayout.PropertyField(m_reactProperty);


            // If NONE, draw nothing
            if (m_reactProperty.enumValueIndex == (int)ColorPaletteObject.React.NONE)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }


            // Draw the palette selection
            if (!m_reactProperty.hasMultipleDifferentValues)
            {
                if (m_reactProperty.enumValueIndex == (int)ColorPaletteObject.React.CUSTOM_PALETTE)
                {
                    m_customPaletteIndexProperty.intValue = EditorGUILayout.Popup("Palette", m_customPaletteIndexProperty.intValue, ColorPaletteData.Singleton.getColorPaletteNameArray());
                }
                else if (m_reactProperty.enumValueIndex == (int)ColorPaletteObject.React.CURRENT_PALETTE)
                {
                    EditorGUILayout.LabelField("Palette", ColorPaletteData.Singleton.getCurrentPalette().name);
                }
            }


            // Fix issue if a selected color palette has been deleted
            if (m_reactProperty.enumValueIndex == (int)ColorPaletteObject.React.CUSTOM_PALETTE)
            {
                if (m_customPaletteIndexProperty.intValue >= ColorPaletteData.Singleton.colorPaletteList.Count)
                {
                    m_customPaletteIndexProperty.intValue = ColorPaletteData.Singleton.colorPaletteList.Count - 1;
                    GUI.changed = true;
                }
            }


            // Draw the percentage slider
            EditorGUILayout.PropertyField(m_colorIndexProperty);

            // Draw the alpha properties
            EditorGUILayout.PropertyField(m_overrideAlphaProperty);
            if (m_overrideAlphaProperty.boolValue)
            {
                EditorGUILayout.PropertyField(m_alphaProperty);
            }

            GUILayout.Space(3f);

            // Draw the button colors
            int maxIndex = m_target.getColorPalette().colorInfoList.Count;

            EditorGUILayout.BeginHorizontal();
            {
                bool allObjectsSameColor = doSelectedGameObjectHaveSameColor();
                for (int i = 0; i < maxIndex; i++)
                {
                    int swatchSize = isCurrentColor(i, allObjectsSameColor) ? 24 : 20;

                    Rect rect = DrawCustomSwatch(m_target.getColorPalette().colorInfoList[i], swatchSize);

                    if (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown)
                    {
                        if (rect.Contains(Event.current.mousePosition))
                        {
                            m_colorIndexProperty.intValue = i;
                            GUI.changed = true;
                        }
                    }
                }

                GUI.color = Color.white;
            }
            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();


            // Display warnings if necessary
            if (m_colorIndexProperty.intValue < 0)
            {
                EditorGUILayout.HelpBox("You specified a negative color index value, we automatically apply index 0 in that case.", MessageType.Warning);
            }
            else if (m_colorIndexProperty.intValue >= maxIndex)
            {
                EditorGUILayout.HelpBox("You are using an index outside the length of the color list for the selected palette. The last color of the palette is applied instead", MessageType.Warning);
            }


            // Update data
            Object[] targetObjectArray = serializedObject.targetObjects;
            for (int i = 0; i < targetObjectArray.Length; i++)
            {
                // If a changed occured, we apply the modifications
                if (GUI.changed)
                {
                    ColorPaletteObject colorPaletteObject = (ColorPaletteObject)targetObjectArray[i];
                    colorPaletteObject.updateColor();
                }
            }
        }