Skip to content

Commit 5260831

Browse files
Merge pull request #84 from Live2D/develop
Update to Cubism 5 SDK for Unity R3
2 parents 97cf812 + 11071d3 commit 5260831

37 files changed

+1080
-434
lines changed

Assets/Live2D/Cubism/CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
8+
## [5-r.3] - 2024-11-28
9+
10+
### Added
11+
12+
* Add processing to parse `CombinedParameters` from `.cdi3.json` file.
13+
* Also add `CubismDisplayInfoCombinedParameterInfo` component to store this information.
14+
* Add `AnimationBeganHandler`, which calls a function when the motion playback starts, to both `CubismMotionController` and `CubismMotionLayer`.
15+
* Add the definition of the function `GetLogFunction` to `CubismCoreDll`.
16+
17+
### Changed
18+
19+
* Change `OnGeneratedCSProjectFiles` function to be disabled in Unity 2017.3 and later by [@moz-moz](https://github.com/moz-moz)
20+
* Change to a single function The initialization process in CubismModel class. by [@KT](https://creatorsforum.live2d.com/t/topic/2356/)
21+
* Change to optimize update process for Multiply Color and Screen Color.
22+
* Change argument type of `CubismMotionLayer.AnimationEndHandler` and `CubismMotionController.AnimationEndHandler` to match the current usage.
23+
* Move the definition of `csmSetLogFunction` from `CubismLogging` to `CubismCoreDll` and rename to `SetLogFunction`.
24+
* Raycast processing now supports 3D intersection determination.
25+
* In the `AsyncBenchmark` scene and `AutomaticAsyncBenchmark`, changed it so that asynchronous processing is not performed in WebGL.
26+
27+
### Fixed
28+
29+
* The fade in and fade out functionality has been improved to better maintain compatibility with other CubismSDK implementations.
30+
* Fix an issue in which when the number of textures for masks was increased, masks were not generated for the increased number of textures from the time of execution.
31+
* Fix an issue that caused an error when parsing Json if the name of the model had certain characters.
32+
* Fix the condition for setting the fade-out end time for Expression.
33+
734
## [5-r.2] - 2024-04-04
835

936
### Added
@@ -406,6 +433,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
406433
* Fix issue where Priority value was not reset after playing motion with CubismMotionController.
407434

408435

436+
[5-r.3]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.2...5-r.3
409437
[5-r.2]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1...5-r.2
410438
[5-r.1]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.4...5-r.1
411439
[5-r.1-beta.4]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.3...5-r.1-beta.4

Assets/Live2D/Cubism/Core/CubismDrawable.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public int TextureIndex
108108
}
109109
}
110110

111+
/// <summary>
112+
/// <see cref="MultiplyColor"/> backing field.
113+
/// </summary>
114+
private Color _multiplyColor;
115+
111116
/// <summary>
112117
/// Copy of MultiplyColor.
113118
/// </summary>
@@ -116,14 +121,22 @@ public Color MultiplyColor
116121
get
117122
{
118123
var index = UnmanagedIndex * 4;
124+
119125
// Pull data.
120-
return new Color(UnmanagedDrawables.MultiplyColors[index],
121-
UnmanagedDrawables.MultiplyColors[index + 1],
122-
UnmanagedDrawables.MultiplyColors[index + 2],
123-
UnmanagedDrawables.MultiplyColors[index + 3]);
126+
_multiplyColor.r = UnmanagedDrawables.MultiplyColors[index];
127+
_multiplyColor.g = UnmanagedDrawables.MultiplyColors[index + 1];
128+
_multiplyColor.b = UnmanagedDrawables.MultiplyColors[index + 2];
129+
_multiplyColor.a = UnmanagedDrawables.MultiplyColors[index + 3];
130+
131+
return _multiplyColor;
124132
}
125133
}
126134

135+
/// <summary>
136+
/// <see cref="ScreenColor"/> backing field.
137+
/// </summary>
138+
public Color _screenColor;
139+
127140
/// <summary>
128141
/// Copy of ScreenColor.
129142
/// </summary>
@@ -132,11 +145,14 @@ public Color ScreenColor
132145
get
133146
{
134147
var index = UnmanagedIndex * 4;
148+
135149
// Pull data.
136-
return new Color(UnmanagedDrawables.ScreenColors[index],
137-
UnmanagedDrawables.ScreenColors[index + 1],
138-
UnmanagedDrawables.ScreenColors[index + 2],
139-
UnmanagedDrawables.ScreenColors[index + 3]);
150+
_screenColor.r = UnmanagedDrawables.ScreenColors[index];
151+
_screenColor.g = UnmanagedDrawables.ScreenColors[index + 1];
152+
_screenColor.b = UnmanagedDrawables.ScreenColors[index + 2];
153+
_screenColor.a = UnmanagedDrawables.ScreenColors[index + 3];
154+
155+
return _screenColor; ;
140156
}
141157
}
142158

@@ -360,7 +376,6 @@ public bool MultiplyBlend
360376
}
361377
}
362378

363-
364379
/// <summary>
365380
/// Revives instance.
366381
/// </summary>

Assets/Live2D/Cubism/Core/CubismLogging.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,36 @@ namespace Live2D.Cubism.Core
1818
/// <summary>
1919
/// Wrapper for core logs.
2020
/// </summary>
21-
internal static class CubismLogging
21+
public class CubismLogging
2222
{
2323
#region Delegates
2424

2525
/// <summary>
2626
/// Delegate compatible with unmanaged log function.
2727
/// </summary>
2828
/// <param name="message">Message to log.</param>
29-
private unsafe delegate void UnmanagedLogDelegate(char* message);
29+
public unsafe delegate void UnmanagedLogDelegate(char* message);
3030

3131
#endregion
3232

3333
/// <summary>
3434
/// Delegate to pass to native Api.
3535
/// </summary>
3636
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
37-
private static UnmanagedLogDelegate LogDelegate { get; set; }
37+
public static UnmanagedLogDelegate LogDelegate { get; set; }
3838

3939
#region Initialization
4040

4141
/// <summary>
4242
/// Registers delegates.
4343
/// </summary>
44-
[RuntimeInitializeOnLoadMethod]
45-
// ReSharper disable once UnusedMember.Local
46-
private static unsafe void Initialize()
44+
public static unsafe void Initialize(UnmanagedLogDelegate logFunctionDelegate)
4745
{
48-
LogDelegate = LogUnmanaged;
49-
46+
LogDelegate = logFunctionDelegate;
5047

5148
var logFunction = Marshal.GetFunctionPointerForDelegate(LogDelegate);
5249

53-
54-
csmSetLogFunction(logFunction);
50+
CubismCoreDll.SetLogFunction(logFunction);
5551
}
5652

5753
#endregion
@@ -61,7 +57,7 @@ private static unsafe void Initialize()
6157
/// </summary>
6258
/// <param name="message">Message to log.</param>
6359
[MonoPInvokeCallback(typeof(UnmanagedLogDelegate))]
64-
private static unsafe void LogUnmanaged(char* message)
60+
public static unsafe void LogUnmanaged(char* message)
6561
{
6662
// Marshal message and log it.
6763
var managedMessage = Marshal.PtrToStringAnsi(new IntPtr(message));
@@ -70,11 +66,16 @@ private static unsafe void LogUnmanaged(char* message)
7066
Debug.LogFormat("[Cubism] Core: {0}.", managedMessage);
7167
}
7268

73-
#region Extern C
74-
75-
[DllImport(CubismCoreDll.DllName)]
76-
private static extern void csmSetLogFunction(IntPtr logFunction);
69+
/// <summary>
70+
/// Example log function.
71+
/// </summary>
72+
/// <param name="message">Log message.</param>
73+
public static unsafe void InvokeLog(string message)
74+
{
75+
var logFunction = Marshal.GetDelegateForFunctionPointer<UnmanagedLogDelegate>(CubismCoreDll.GetLogFunction());
7776

78-
#endregion
77+
var str = Marshal.StringToHGlobalAnsi(message);
78+
logFunction.Invoke((char*)str.ToPointer());
79+
}
7980
}
8081
}

Assets/Live2D/Cubism/Core/CubismModel.cs

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,7 @@ private void Revive()
266266
}
267267

268268

269-
// Revive unmanaged model.
270-
TaskableModel = new CubismTaskableModel(Moc);
271-
272-
if (TaskableModel == null || TaskableModel.UnmanagedModel == null)
273-
{
274-
return;
275-
}
276-
277-
// Revive proxies.
278-
Parameters = GetComponentsInChildren<CubismParameter>();
279-
Parts = GetComponentsInChildren<CubismPart>();
280-
Drawables = GetComponentsInChildren<CubismDrawable>();
281-
282-
Parameters.Revive(TaskableModel.UnmanagedModel);
283-
Parts.Revive(TaskableModel.UnmanagedModel);
284-
Drawables.Revive(TaskableModel.UnmanagedModel);
285-
286-
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
287-
288-
_parameterStore = GetComponent<CubismParameterStore>();
269+
Reset(Moc);
289270
}
290271

291272
/// <summary>
@@ -303,22 +284,52 @@ private void Reset(CubismMoc moc)
303284
return;
304285
}
305286

306-
// Create and initialize proxies.
307-
var parameters = CubismParameter.CreateParameters(TaskableModel.UnmanagedModel);
308-
var parts = CubismPart.CreateParts(TaskableModel.UnmanagedModel);
309-
var drawables = CubismDrawable.CreateDrawables(TaskableModel.UnmanagedModel);
310287

288+
Parameters = GetComponentsInChildren<CubismParameter>();
289+
if (Parameters.Length < 1 && (transform.Find("Parameters") == null))
290+
{
291+
// Create and initialize proxies.
292+
var parameters = CubismParameter.CreateParameters(TaskableModel.UnmanagedModel);
293+
parameters.transform.SetParent(transform);
294+
Parameters = parameters.GetComponentsInChildren<CubismParameter>();
295+
}
296+
else
297+
{
298+
Parameters.Revive(TaskableModel.UnmanagedModel);
299+
}
311300

312-
parameters.transform.SetParent(transform);
313-
parts.transform.SetParent(transform);
314-
drawables.transform.SetParent(transform);
315301

302+
Parts = GetComponentsInChildren<CubismPart>();
303+
if (Parts.Length < 1 && (transform.Find("Parts") == null))
304+
{
305+
// Create and initialize proxies.
306+
var parts = CubismPart.CreateParts(TaskableModel.UnmanagedModel);
307+
parts.transform.SetParent(transform);
308+
Parts = parts.GetComponentsInChildren<CubismPart>();
309+
}
310+
else
311+
{
312+
Parts.Revive(TaskableModel.UnmanagedModel);
313+
}
314+
315+
316+
Drawables = GetComponentsInChildren<CubismDrawable>();
317+
if (Drawables.Length < 1 && (transform.Find("Drawables") == null))
318+
{
319+
// Create and initialize proxies.
320+
var drawables = CubismDrawable.CreateDrawables(TaskableModel.UnmanagedModel);
321+
drawables.transform.SetParent(transform);
322+
Drawables = drawables.GetComponentsInChildren<CubismDrawable>();
323+
}
324+
else
325+
{
326+
Drawables.Revive(TaskableModel.UnmanagedModel);
327+
}
316328

317-
Parameters = parameters.GetComponentsInChildren<CubismParameter>();
318-
Parts = parts.GetComponentsInChildren<CubismPart>();
319-
Drawables = drawables.GetComponentsInChildren<CubismDrawable>();
320329

321330
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
331+
332+
RefreshParameterStore();
322333
}
323334

324335
/// <summary>
@@ -339,6 +350,26 @@ public void ForceUpdateNow()
339350
#endif
340351
}
341352

353+
/// <summary>
354+
/// パラメータストアを最新の情報に更新する。
355+
/// </summary>
356+
public void RefreshParameterStore()
357+
{
358+
// CubismParameterStore を取得する。
359+
_parameterStore = GetComponent<CubismParameterStore>();
360+
361+
362+
// Return early if empty.
363+
if (_parameterStore == null)
364+
{
365+
return;
366+
}
367+
368+
369+
// 最新の情報に更新する。
370+
_parameterStore.Refresh();
371+
}
372+
342373

343374
#if UNITY_2018_1_OR_NEWER
344375
/// <summary>

Assets/Live2D/Cubism/Core/Unmanaged/CubismCoreDll.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ public static class CubismCoreDll
142142
/// Sets log handler.
143143
/// </summary>
144144
[DllImport(DllName, EntryPoint = "csmSetLogFunction")]
145-
public static extern void SetLogFunction(uint handler);
145+
public static extern void SetLogFunction(IntPtr handler);
146+
/// <summary>
147+
/// Gets log handler.
148+
/// </summary>
149+
[DllImport(DllName, EntryPoint = "csmGetLogFunction")]
150+
public static extern IntPtr GetLogFunction();
146151
/// <summary>
147152
/// Gets Size of model instance (in bytes).
148153
/// </summary>

Assets/Live2D/Cubism/Editor/CubismAssetProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CubismAssetProcessor : AssetPostprocessor
2828
{
2929
#region Unity Event Handling
3030

31+
#if !UNITY_2017_3_OR_NEWER
3132
/// <summary>
3233
/// Called by Unity. Makes sure <see langword="unsafe"/> code is allowed.
3334
/// </summary>
@@ -36,6 +37,7 @@ public static void OnGeneratedCSProjectFiles()
3637
{
3738
AllowUnsafeCode();
3839
}
40+
#endif
3941

4042

4143
/// <summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright(c) Live2D Inc. All rights reserved.
3+
*
4+
* Use of this source code is governed by the Live2D Open Software license
5+
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
6+
*/
7+
8+
9+
using Live2D.Cubism.Framework.Json;
10+
using UnityEngine;
11+
12+
public class CubismDisplayInfoCombinedParameterInfo : MonoBehaviour
13+
{
14+
/// <summary>
15+
/// Combined parameters from .cdi3.json.
16+
/// </summary>
17+
public CubismDisplayInfo3Json.CombinedParameter[] CombinedParameters
18+
{
19+
get
20+
{
21+
return combinedParameters;
22+
}
23+
set
24+
{
25+
combinedParameters = value;
26+
}
27+
}
28+
29+
/// <summary>
30+
/// backing field for <see cref="CombinedParameters"/>.
31+
/// </summary>
32+
private CubismDisplayInfo3Json.CombinedParameter[] combinedParameters;
33+
}

Assets/Live2D/Cubism/Framework/CubismDisplayInfoCombinedParameterInfo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Live2D/Cubism/Framework/Expression/CubismExpressionController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ private void StartExpression()
9595
if(_playingExpressions.Count > 0)
9696
{
9797
var playingExpression = _playingExpressions[_playingExpressions.Count - 1];
98-
playingExpression.ExpressionEndTime = playingExpression.ExpressionUserTime + playingExpression.FadeOutTime;
98+
var newExpressionEndTime = playingExpression.ExpressionUserTime + playingExpression.FadeOutTime;
99+
100+
if (playingExpression.ExpressionEndTime == 0.0f || newExpressionEndTime < playingExpression.ExpressionEndTime)
101+
{
102+
playingExpression.ExpressionEndTime = newExpressionEndTime;
103+
}
99104
_playingExpressions[_playingExpressions.Count - 1] = playingExpression;
100105
}
101106

0 commit comments

Comments
 (0)