2025-01-23 10:16:47 +08:00
using System.Collections.Generic ;
using JetBrains.Annotations ;
using PrimeTween ;
using UnityEditor ;
using UnityEngine ;
[CustomEditor(typeof(PrimeTweenManager))]
internal class PrimeTweenManagerInspector : Editor {
SerializedProperty tweensProp ;
2025-05-15 10:40:15 +08:00
SerializedProperty lateUpdateTweensProp ;
2025-01-23 10:16:47 +08:00
SerializedProperty fixedUpdateTweensProp ;
GUIContent aliveTweenGuiContent ;
2025-05-15 10:40:15 +08:00
GUIContent lateUpdateTweenGuiContent ;
2025-01-23 10:16:47 +08:00
GUIContent fixedUpdateTweenGuiContent ;
StringCache tweensCountCache ;
StringCache maxSimultaneousTweensCountCache ;
StringCache currentPoolCapacityCache ;
void OnEnable ( ) {
tweensProp = serializedObject . FindProperty ( nameof ( PrimeTweenManager . tweens ) ) ;
2025-05-15 10:40:15 +08:00
lateUpdateTweensProp = serializedObject . FindProperty ( nameof ( PrimeTweenManager . lateUpdateTweens ) ) ;
2025-01-23 10:16:47 +08:00
fixedUpdateTweensProp = serializedObject . FindProperty ( nameof ( PrimeTweenManager . fixedUpdateTweens ) ) ;
Assert . IsNotNull ( tweensProp ) ;
2025-05-15 10:40:15 +08:00
Assert . IsNotNull ( lateUpdateTweensProp ) ;
2025-01-23 10:16:47 +08:00
Assert . IsNotNull ( fixedUpdateTweensProp ) ;
aliveTweenGuiContent = new GUIContent ( "Tweens" ) ;
2025-05-15 10:40:15 +08:00
lateUpdateTweenGuiContent = new GUIContent ( "Late update tweens" ) ;
2025-01-23 10:16:47 +08:00
fixedUpdateTweenGuiContent = new GUIContent ( "Fixed update tweens" ) ;
}
public override void OnInspectorGUI ( ) {
using ( new EditorGUI . DisabledScope ( true ) ) {
EditorGUILayout . ObjectField ( "Script" , MonoScript . FromMonoBehaviour ( ( MonoBehaviour ) target ) , typeof ( MonoBehaviour ) , false ) ;
}
var manager = target as PrimeTweenManager ;
Assert . IsNotNull ( manager ) ;
GUILayout . BeginHorizontal ( ) ;
GUILayout . Label ( "Alive tweens" , EditorStyles . label ) ;
GUILayout . Label ( tweensCountCache . GetCachedString ( manager . tweensCount ) , EditorStyles . boldLabel ) ;
GUILayout . FlexibleSpace ( ) ;
GUILayout . EndHorizontal ( ) ;
GUILayout . BeginHorizontal ( ) ;
GUILayout . Label ( Constants . maxAliveTweens , EditorStyles . label ) ;
GUILayout . Label ( maxSimultaneousTweensCountCache . GetCachedString ( manager . maxSimultaneousTweensCount ) , EditorStyles . boldLabel ) ;
GUILayout . FlexibleSpace ( ) ;
GUILayout . EndHorizontal ( ) ;
GUILayout . BeginHorizontal ( ) ;
GUILayout . Label ( "Tweens capacity" , EditorStyles . label ) ;
GUILayout . Label ( currentPoolCapacityCache . GetCachedString ( manager . currentPoolCapacity ) , EditorStyles . boldLabel ) ;
GUILayout . FlexibleSpace ( ) ;
GUILayout . EndHorizontal ( ) ;
EditorGUILayout . HelpBox ( "Use " + Constants . setTweensCapacityMethod + " to set tweens capacity.\n" +
"To prevent memory allocations during runtime, choose the value that is greater than the maximum number of simultaneous tweens in your game." , MessageType . None ) ;
drawList ( tweensProp , manager . tweens , aliveTweenGuiContent ) ;
2025-05-15 10:40:15 +08:00
drawList ( lateUpdateTweensProp , manager . lateUpdateTweens , lateUpdateTweenGuiContent ) ;
2025-01-23 10:16:47 +08:00
drawList ( fixedUpdateTweensProp , manager . fixedUpdateTweens , fixedUpdateTweenGuiContent ) ;
void drawList ( SerializedProperty tweensProp , List < ReusableTween > list , GUIContent guiContent ) {
if ( tweensProp . isExpanded ) {
foreach ( var tween in list ) {
if ( tween ! = null & & string . IsNullOrEmpty ( tween . debugDescription ) ) {
tween . debugDescription = tween . GetDescription ( ) ;
}
}
}
using ( new EditorGUI . DisabledScope ( true ) ) {
EditorGUILayout . PropertyField ( tweensProp , guiContent ) ;
}
}
}
struct StringCache {
int currentValue ;
string str ;
[NotNull]
internal string GetCachedString ( int value ) {
if ( currentValue ! = value | | str = = null ) {
currentValue = value ;
str = value . ToString ( ) ;
}
return str ;
}
}
}