1
- using EnhancedStreamChat . Textures ;
1
+ using ChatCore . Interfaces ;
2
+ using EnhancedStreamChat . Chat ;
3
+ using EnhancedStreamChat . Graphics ;
2
4
using System ;
3
5
using System . Collections . Generic ;
4
6
using System . Reflection ;
@@ -20,7 +22,7 @@ public static class RequestCoordinator
20
22
21
23
private static Mode mode ;
22
24
23
- internal static Action < string , byte > EmoteQueue ;
25
+ internal static Action < IChatEmote , byte > EmoteQueue ;
24
26
25
27
private static Dictionary < Mode , PS_Prefab_Pair > particleSystems = new Dictionary < Mode , PS_Prefab_Pair > ( ) ;
26
28
@@ -30,10 +32,8 @@ internal static Scene myScene
30
32
{
31
33
if ( ! _myScene . HasValue )
32
34
{
33
- Log ( "Creating Scene.." ) ;
34
35
_myScene = SceneManager . CreateScene ( "EmoteRainScene" ) ;
35
36
}
36
- Log ( "Returning Scene.." ) ;
37
37
return _myScene . Value ;
38
38
}
39
39
}
@@ -63,50 +63,87 @@ internal static void OnLoad()
63
63
Log ( "Prefab at: " + ( particleSystems [ Mode . Play ] . Item2 ? particleSystems [ Mode . Play ] . Item2 . GetFullPath ( ) : "null" ) ) ;
64
64
}
65
65
66
- private static void MessageCallback ( string id , byte count )
66
+ private static void MessageCallback ( IChatEmote emote , byte count )
67
67
{
68
68
if ( ( mode == Mode . Menu && Settings . menuRain ) || ( mode == Mode . Play && Settings . songRain ) )
69
69
{
70
- SharedCoroutineStarter . instance . StartCoroutine ( WaitForCollection ( id , count ) ) ;
70
+ SharedCoroutineStarter . instance . StartCoroutine ( WaitForCollection ( emote , count ) ) ;
71
71
}
72
72
}
73
73
74
- private static IEnumerator < WaitUntil > WaitForCollection ( string id , byte count )
74
+ private static IEnumerator < WaitUntil > WaitForCollection ( IChatEmote emote , byte count )
75
75
{
76
76
float time = Time . time ;
77
- Log ( "Id: " + id ) ;
77
+ bool isAnimation = false ; //doesn't do anything yet. look below.
78
78
79
- CachedSpriteData cachedSpriteData = default ;
80
- yield return new WaitUntil ( ( ) => ImageDownloader . CachedTextures . TryGetValue ( id , out cachedSpriteData ) && mode != Mode . None ) ;
79
+ EnhancedImageInfo enhancedImageInfo = default ;
80
+ yield return new WaitUntil ( ( ) => ChatImageProvider . instance . CachedImageInfo . TryGetValue ( emote . Id , out enhancedImageInfo ) && mode != Mode . None ) ;
81
81
82
- Log ( $ "Continuing after { Time . time - time } seconds...") ;
82
+ // Log($"Continuing after {Time.time - time} seconds...");
83
83
84
84
TimeoutScript cloneTimer ;
85
85
PS_Prefab_Pair ps_Prefab_Pair = particleSystems [ mode ] ;
86
86
87
- if ( ! ps_Prefab_Pair . Item1 . ContainsKey ( id ) )
87
+ if ( ! ps_Prefab_Pair . Item1 . ContainsKey ( emote . Id ) )
88
88
{
89
- Log ( ps_Prefab_Pair . Item2 ? ps_Prefab_Pair . Item2 . GetFullPath ( ) : "null" ) ;
90
89
cloneTimer = UnityEngine . Object . Instantiate ( ps_Prefab_Pair . Item2 ) . GetComponent < TimeoutScript > ( ) ;
91
90
var main = cloneTimer . PS . main ;
92
91
if ( mode == Mode . Menu ) main . startSize = Settings . menuSize ;
93
92
if ( mode == Mode . Play ) main . startSize = Settings . songSize ;
94
- cloneTimer . key = id ;
93
+ cloneTimer . key = emote . Id ;
95
94
cloneTimer . mode = mode ;
96
95
SceneManager . MoveGameObjectToScene ( cloneTimer . gameObject , myScene ) ;
97
- ps_Prefab_Pair . Item1 . Add ( id , cloneTimer ) ;
96
+ ps_Prefab_Pair . Item1 . Add ( emote . Id , cloneTimer ) ;
98
97
}
99
98
else
100
99
{
101
- cloneTimer = ps_Prefab_Pair . Item1 [ id ] ;
100
+ cloneTimer = ps_Prefab_Pair . Item1 [ emote . Id ] ;
102
101
}
103
- Log ( "Assigning..." ) ;
104
- cloneTimer . PSR . material . mainTexture = cachedSpriteData . sprite . texture ;
105
- Log ( "Finished assigning!" ) ;
102
+
103
+ //not sure about this. Might not work at all, but is not yet in use. So it technically does work?
104
+ if ( isAnimation )
105
+ {
106
+ int numTilesX = ( int ) ( enhancedImageInfo . Width / enhancedImageInfo . AnimControllerData . uvs [ 0 ] . width ) ;
107
+ int numTilesY = ( int ) ( enhancedImageInfo . Height / enhancedImageInfo . AnimControllerData . uvs [ 0 ] . height ) ;
108
+
109
+ var tex = cloneTimer . PS . textureSheetAnimation ;
110
+ tex . enabled = true ;
111
+ tex . animation = ParticleSystemAnimationType . WholeSheet ;
112
+ tex . numTilesX = numTilesX ;
113
+ tex . numTilesY = numTilesY ;
114
+ tex . timeMode = ParticleSystemAnimationTimeMode . Lifetime ;
115
+
116
+ float lifeTime = cloneTimer . PS . main . startLifetime . constant ;
117
+ AnimationCurve curve = new AnimationCurve ( ) ;
118
+ float singleFramePercentage = 1 / enhancedImageInfo . AnimControllerData . uvs . Length ;
119
+ float maxFramePercentage = enhancedImageInfo . AnimControllerData . uvs . Length / ( numTilesX * numTilesY ) ;
120
+
121
+ List < float > timePercentages = new List < float > ( ) ;
122
+ float currentTimePercentage = 0 ;
123
+ float currentFramePercentage = 0 ;
124
+ for ( int i = 0 ; currentTimePercentage < 1.0f ; i ++ )
125
+ {
126
+ currentTimePercentage += ( enhancedImageInfo . AnimControllerData . delays [ i ] / 1000 ) / lifeTime ;
127
+ if ( currentFramePercentage < maxFramePercentage )
128
+ {
129
+ currentFramePercentage += singleFramePercentage ;
130
+ }
131
+ else
132
+ {
133
+ currentFramePercentage = 0 ;
134
+ }
135
+ curve . AddKey ( currentTimePercentage , currentFramePercentage ) ;
136
+ }
137
+ tex . frameOverTime = new ParticleSystem . MinMaxCurve ( 1.0f , curve ) ;
138
+ }
139
+ //end of "not-sure-about-this"
140
+
141
+ //Log("Assigning texture...");
142
+ cloneTimer . PSR . material . mainTexture = enhancedImageInfo . Sprite . texture ;
106
143
107
144
cloneTimer . Emit ( count ) ;
108
145
109
- Log ( "ParticleSystems notified! " + cachedSpriteData . sprite . name ) ;
146
+ // Log("ParticleSystems notified! ");
110
147
111
148
}
112
149
//Needs rework...
@@ -138,7 +175,7 @@ internal static void EnvironmentSwitched(string scene, SceneLoadMode sceneLoadMo
138
175
internal static void UnregisterPS ( string key , Mode mode )
139
176
{
140
177
UnityEngine . Object . Destroy ( particleSystems [ mode ] . Item1 [ key ] ) ;
141
- Log ( "Inactive ParticleSystem. Removing..." ) ;
178
+ // Log("Inactive ParticleSystem. Removing...");
142
179
particleSystems [ mode ] . Item1 . Remove ( key ) ;
143
180
}
144
181
}
0 commit comments