// Render color property.
        public bool RenderColorGroupProperty(ProfileGroupDefinition def)
        {
            EditorGUILayout.BeginHorizontal();

            ColorKeyframeGroup group = m_Profile.GetGroup <ColorKeyframeGroup>(def.propertyKey);

            EditorGUILayout.PrefixLabel(new GUIContent(group.name, def.tooltip));
            bool valueChanged = false;

            if (m_Profile.IsManagedByTimeline(def.propertyKey))
            {
                RenderManagedOnTimlineMessage();
            }
            else
            {
                ColorKeyframe frame = group.GetKeyframe(0);

                EditorGUI.BeginChangeCheck();
                Color selectedColor = EditorGUILayout.ColorField(frame.color);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_Profile, "Changed color keyframe value");
                    frame.color  = selectedColor;
                    valueChanged = true;
                }
            }

            EditorGUILayout.EndHorizontal();
            return(valueChanged);
        }
示例#2
0
        private void AddColorGroup(string propKey, string groupName, Color color)
        {
            ColorKeyframeGroup group = new ColorKeyframeGroup(
                groupName, new ColorKeyframe(color, 0));

            keyframeGroups[propKey] = group;
        }
示例#3
0
        public static void RenderColorGroupRow(Rect rect, ColorKeyframeGroup group)
        {
            if ((int)rect.width == 0)
            {
                return;
            }

            List <Vector4> shaderColors = FormatColorGradientForShader(group);

            if (m_RectangleMesh == null)
            {
                m_RectangleMesh = new Mesh()
                {
                    hideFlags = HideFlags.HideInHierarchy
                };
                m_RectangleMesh.MarkDynamic();
            }

            // Create a mesh that fits the aspect ratio
            PopulateRectangleMesh(Mathf.Floor(rect.width), Mathf.Floor(rect.height), m_RectangleMesh);

            int           textureSize   = Mathf.NextPowerOfTwo((int)rect.width);
            RenderTexture targetTexture = RenderTexture.GetTemporary(
                textureSize,
                textureSize,
                0,
                RenderTextureFormat.ARGB32,
                RenderTextureReadWrite.sRGB);

            RenderTexture oldRenderTexture = RenderTexture.active;

            GL.PushMatrix();
            GL.LoadPixelMatrix(0, Mathf.Floor(rect.width), 0, Mathf.Floor(rect.height));

            RenderTexture.active = targetTexture;

            GL.Clear(true, true, Color.white);

            // Configure the shader.
            Material gradientMaterial = new Material(Shader.Find("Hidden/Funly/SkyStudio/MultiColorGradient"))
            {
                hideFlags = HideFlags.HideInHierarchy
            };

            gradientMaterial.SetVectorArray("_ColorPoints", shaderColors);
            gradientMaterial.SetInt("_NumColorPoints", shaderColors.Count);
            gradientMaterial.SetPass(0);

            Graphics.DrawMeshNow(m_RectangleMesh, Vector3.zero, Quaternion.identity);

            GL.PopMatrix();
            RenderTexture.active = oldRenderTexture;

            GUI.DrawTexture(rect, targetTexture);
            RenderTexture.ReleaseTemporary(targetTexture);
        }
示例#4
0
        public Color GetColorPropertyValue(string propertyKey, float timeOfDay)
        {
            ColorKeyframeGroup group = GetGroup <ColorKeyframeGroup>(propertyKey);

            if (group == null)
            {
                Debug.LogError("Can't find color group with property key: " + propertyKey);
                return(Color.white);
            }

            return(group.ColorForTime(timeOfDay));
        }
示例#5
0
        private void InsertKeyframeInColorGroup(float time, ColorKeyframeGroup group)
        {
            ColorKeyframe previousKeyFrame = group.GetPreviousKeyFrame(time);
            //Color keyColor = previousKeyFrame != null ? previousKeyFrame.color : Color.white;
            ColorKeyframe newKeyFrame = new ColorKeyframe(previousKeyFrame);

            newKeyFrame.time = time;
            group.AddKeyFrame(newKeyFrame);

            KeyframeInspectorWindow.SetKeyframeData(
                newKeyFrame, group, KeyframeInspectorWindow.KeyType.Color, m_ActiveSkyProfile);
        }
示例#6
0
        // Render a timeline of gradient keyframes.
        private void RenderGradientRowAndAdvance(ref Rect rect, SkyProfile profile, ColorKeyframeGroup group, ProfileGroupDefinition groupDefinition)
        {
            rect.height = COLOR_ROW_HEIGHT;
            UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey);

            Rect valueRowRect;
            Rect nameRowRect;
            bool isActive;

            LoadRowInformation(ref rect, group.id, COLOR_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive);

            RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition);
            ColorTimelineRow.RenderColorGroupRow(valueRowRect, profile, group);
        }
示例#7
0
        private static List <Vector4> FormatColorGradientForShader(ColorKeyframeGroup group)
        {
            List <Vector4> colors = new List <Vector4>(group.keyframes.Count);

            if (group.keyframes.Count == 0)
            {
                return(colors);
            }

            // Start at zero if no keyframe.
            List <float> majorTimePoints = new List <float>();

            if (group.keyframes[0].time > .00001f)
            {
                majorTimePoints.Add(0);
            }

            foreach (ColorKeyframe keyframe in group.keyframes)
            {
                majorTimePoints.Add(keyframe.time);
            }

            // End at 1 if no keyframe
            if (group.keyframes[group.keyframes.Count - 1].time < .99999f)
            {
                majorTimePoints.Add(1.0f);
            }

            for (int i = 0; i < (majorTimePoints.Count - 1); i++)
            {
                float currentTime = majorTimePoints[i];
                float nextTime    = majorTimePoints[i + 1];

                float timeStep = (nextTime - currentTime) / k_LineSmoothing;
                for (int j = 0; j <= k_LineSmoothing; j++)
                {
                    float time      = currentTime + (j * timeStep);
                    Color timeColor = group.ColorForTime(time);

                    colors.Add(new Vector4(time, timeColor.r, timeColor.g, timeColor.b));
                }
            }

            return(colors);
        }
示例#8
0
        public static void RenderColorGroupRow(Rect rect, SkyProfile profile, ColorKeyframeGroup colors)
        {
            bool sortGroup = false;

            RenderColorGroupRow(rect, colors);

            for (int i = 0; i < colors.keyframes.Count; i++)
            {
                ColorKeyframe currentKey = colors.GetKeyframe(i);

                // Track key marker mouse events and render.
                bool didSingleClick  = false;
                bool isDragging      = false;
                bool keyframeUpdated = false;
                SkyEditorUtility.DrawHorizontalKeyMarker(rect, currentKey, profile,
                                                         out didSingleClick, out isDragging, out keyframeUpdated);

                if (keyframeUpdated)
                {
                    sortGroup = true;
                }

                // Show the color keyframe property window.
                if (didSingleClick || isDragging)
                {
                    // Load info about this keyframe and show the editor window.
                    KeyframeInspectorWindow.SetKeyframeData(
                        currentKey, colors, KeyframeInspectorWindow.KeyType.Color, profile);

                    if (didSingleClick)
                    {
                        KeyframeInspectorWindow.ShowWindow();
                    }
                }
            }

            if (sortGroup)
            {
                colors.SortKeyframes();
            }
        }