Skip to content

Commit

Permalink
fix: the background color of the inspector does not change while prev…
Browse files Browse the repository at this point in the history
…iewing or recording in the animation view

close #2
  • Loading branch information
mob-sakai committed Jul 1, 2024
1 parent 5bd37cd commit 6ea719f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Packages/src/Editor/InjectionPropertyDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using Coffee.UIMaterialPropertyInjectorInternal;
using UnityEditor;
Expand All @@ -10,6 +11,10 @@ namespace Coffee.UIExtensions
[CustomPropertyDrawer(typeof(InjectionProperty))]
internal class InjectionPropertyDrawer : PropertyDrawer
{
private static readonly Func<bool> s_InAnimationRecording = typeof(AnimationMode)
.GetMethod("InAnimationRecording", BindingFlags.Static | BindingFlags.NonPublic)
.CreateDelegate(typeof(Func<bool>)) as Func<bool>;

private static SerializedProperty GetProperty(SerializedProperty property, PropertyType type)
{
switch (type)
Expand Down Expand Up @@ -114,6 +119,14 @@ public void OnGUI(Rect r, GUIContent label, string name, PropertyType type, Seri
r.xMin += 18;
}

var bg = GUI.backgroundColor;
if (prop.isAnimated)
{
GUI.backgroundColor = s_InAnimationRecording()
? AnimationMode.recordedPropertyColor
: AnimationMode.animatedPropertyColor;
}

ReadFrom(name, type, prop, material);
var mp = MaterialEditor.GetMaterialProperty(_editor.targets, name);
if (type == PropertyType.Texture || mp.name != name)
Expand Down Expand Up @@ -142,6 +155,8 @@ public void OnGUI(Rect r, GUIContent label, string name, PropertyType type, Seri
prop.serializedObject.ApplyModifiedProperties();
}
}

GUI.backgroundColor = bg;
}

private static bool IsValid(Material material, string propertyName, PropertyType type)
Expand Down

0 comments on commit 6ea719f

Please sign in to comment.