Skip to content

Commit ff57fcd

Browse files
Update to Cubism 5 SDK for Unity R1 beta4
1 parent 08815c8 commit ff57fcd

22 files changed

+491
-162
lines changed

Assets/Live2D/Cubism/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77

8+
## [5-r.1-beta.4] - 2024-01-18
9+
10+
### Added
11+
12+
* Add `CubismDrawableInspector` and parent Part display.
13+
* Add `CubismPartInspector` to show parent and descendant trees.
14+
* Add expression to check for index out of range with `CubismRenderer.OnMaskPropertiesDidChange()`.
15+
16+
### Changed
17+
18+
* Change `CubismPartsInspectorInspector` to be hierarchical.
19+
20+
### Fixed
21+
22+
* Fix an issue where models with a specific number of masks could not be drawn correctly.
23+
824
## [5-r.1-beta.3] - 2023-11-14
925

1026
### Added
@@ -21,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2137

2238
* Fix an error when displaying CubismRendererInspector for uninitialized models.
2339
* Fix condition for clearing AnimationCurve when Reimporting .motion3.json.
40+
* Fix fade calculation bug in MotionFade.
2441

2542

2643
## [5-r.1-beta.2] - 2023-09-28
@@ -350,6 +367,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
350367
* Fix issue where Priority value was not reset after playing motion with CubismMotionController.
351368

352369

370+
[5-r.1-beta.4]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.3...5-r.1-beta.4
353371
[5-r.1-beta.3]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.2...5-r.1-beta.3
354372
[5-r.1-beta.2]: https://github.com/Live2D/CubismUnityComponents/compare/5-r.1-beta.1...5-r.1-beta.2
355373
[5-r.1-beta.1]: https://github.com/Live2D/CubismUnityComponents/compare/4-r.7...5-r.1-beta.1

Assets/Live2D/Cubism/Core/CubismDrawable.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ internal int UnmanagedIndex
7676
private set { _unmanagedIndex = value; }
7777
}
7878

79+
/// <summary>
80+
/// Parent Part Position in unmanaged arrays.
81+
/// </summary>
82+
public int UnmanagedParentIndex
83+
{
84+
get { return UnmanagedDrawables.ParentPartIndices[UnmanagedIndex]; }
85+
}
7986

8087
/// <summary>
8188
/// Copy of Id.

Assets/Live2D/Cubism/Core/CubismPart.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal static GameObject CreateParts(CubismUnmanagedModel unmanagedModel)
7070
/// <summary>
7171
/// Position in unmanaged arrays.
7272
/// </summary>
73-
internal int UnmanagedIndex
73+
public int UnmanagedIndex
7474
{
7575
get { return _unmanagedIndex; }
7676
private set { _unmanagedIndex = value; }
@@ -98,7 +98,7 @@ public string Id
9898
/// <summary>
9999
/// Parent part position in unmanaged arrays.
100100
/// </summary>
101-
internal int UnmanagedParentIndex
101+
public int UnmanagedParentIndex
102102
{
103103
get
104104
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Live2D.Cubism.Core;
2+
using UnityEditor;
3+
4+
namespace Live2D.Cubism.Editor.Inspectors
5+
{
6+
/// <summary>
7+
/// Inspector for <see cref="CubismRenderer"/>s.
8+
/// </summary>
9+
[CustomEditor(typeof(CubismDrawable)), CanEditMultipleObjects]
10+
internal sealed class CubismDrawableInspector : UnityEditor.Editor
11+
{
12+
/// <summary>
13+
/// <see cref="CubismPart"/>s cache.
14+
/// </summary>
15+
private CubismPart[] Parts { get; set; }
16+
17+
#region Editor
18+
19+
/// <summary>
20+
/// Draws inspector.
21+
/// </summary>
22+
public override void OnInspectorGUI()
23+
{
24+
var drawable = target as CubismDrawable;
25+
26+
if (Parts == null)
27+
{
28+
Parts = drawable.FindCubismModel(true).Parts;
29+
}
30+
31+
EditorGUILayout.ObjectField("Parent Part", Parts[drawable.ParentPartIndex], typeof(CubismPart), false);
32+
}
33+
34+
#endregion
35+
}
36+
}

Assets/Live2D/Cubism/Editor/Inspectors/CubismDrawableInspector.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.
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
using Live2D.Cubism.Core;
2+
using UnityEditor;
3+
using UnityEditorInternal;
4+
using UnityEngine;
5+
6+
namespace Live2D.Cubism.Editor.Inspectors
7+
{
8+
/// <summary>
9+
/// Inspector for <see cref="CubismRenderer"/>s.
10+
/// </summary>
11+
[CustomEditor(typeof(CubismPart)), CanEditMultipleObjects]
12+
internal sealed class CubismPartInspector : UnityEditor.Editor
13+
{
14+
/// <summary>
15+
/// Parent <see cref="CubismPart"/> cache.
16+
/// </summary>
17+
private CubismPart _parent;
18+
19+
/// <summary>
20+
/// Child <see cref="CubismPart"/>s foldout state.
21+
/// </summary>
22+
private static bool ChildPartsFoldout { get; set; } = true;
23+
24+
/// <summary>
25+
/// Child <see cref="CubismPart"/>s ReorderableList.
26+
/// </summary>
27+
private ReorderableList ChildParts { get; set; }
28+
29+
/// <summary>
30+
/// Child <see cref="CubismPart"/>'s child <see cref="CubismDrawable"/>s.
31+
/// </summary>
32+
private InternalTreeInfo ChildPartDrawables { get; set; }
33+
34+
private int DrawablesTotalCount { get; set; }
35+
36+
#region Editor
37+
38+
/// <summary>
39+
/// Draws inspector.
40+
/// </summary>
41+
public override void OnInspectorGUI()
42+
{
43+
if (!IsInitialized)
44+
{
45+
Initialize();
46+
}
47+
48+
EditorGUILayout.ObjectField("Parent Part", _parent, typeof(CubismPart), false);
49+
50+
{
51+
var rect = EditorGUILayout.GetControlRect();
52+
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
53+
var fieldRect = new Rect(rect.x + rect.width - 50f, rect.y, 50f, rect.height);
54+
55+
ChildPartsFoldout = EditorGUI.Foldout(foldoutRect, ChildPartsFoldout, "Child Parts");
56+
EditorGUI.IntField(fieldRect, ChildParts.count);
57+
}
58+
if (ChildPartsFoldout)
59+
{
60+
ChildParts.DoLayoutList();
61+
}
62+
63+
{
64+
var rect = EditorGUILayout.GetControlRect();
65+
var foldoutRect = new Rect(rect.x, rect.y, rect.width, rect.height);
66+
var fieldRect = new Rect(rect.x + rect.width - 50f, rect.y, 50f, rect.height);
67+
68+
ChildPartDrawables.Foldout = EditorGUI.Foldout(foldoutRect, ChildPartDrawables.Foldout, "Child Drawables");
69+
EditorGUI.IntField(fieldRect, DrawablesTotalCount);
70+
}
71+
if (ChildPartDrawables.Foldout)
72+
{
73+
for (var i = 0; i < ChildPartDrawables.Drawables.Length; i++)
74+
{
75+
EditorGUILayout.ObjectField(ChildPartDrawables.Drawables[i], typeof(CubismDrawable), true);
76+
}
77+
EditorGUI.indentLevel++;
78+
for (var i = 0; i < ChildPartDrawables.Childs.Length; i++)
79+
{
80+
DrawTree(ChildPartDrawables.Childs[i]);
81+
}
82+
EditorGUI.indentLevel--;
83+
}
84+
}
85+
86+
private void DrawTree(InternalTreeInfo item)
87+
{
88+
item.Foldout = EditorGUILayout.Foldout(item.Foldout, item.Part.Id);
89+
if (item.Foldout)
90+
{
91+
for (var i = 0; i < item.Drawables.Length; i++)
92+
{
93+
EditorGUILayout.ObjectField(item.Drawables[i], typeof(CubismDrawable), true);
94+
}
95+
for (var i = 0; i < item.Childs.Length; i++)
96+
{
97+
DrawTree(item.Childs[i]);
98+
}
99+
}
100+
}
101+
102+
#endregion
103+
104+
/// <summary>
105+
/// Gets whether <see langword="this"/> is initialized.
106+
/// </summary>
107+
private bool IsInitialized
108+
{
109+
get
110+
{
111+
return ChildParts != null && ChildPartDrawables != null;
112+
}
113+
}
114+
115+
/// <summary>
116+
/// Initializes <see langword="this"/>.
117+
/// </summary>
118+
private void Initialize()
119+
{
120+
var part = target as CubismPart;
121+
122+
var model = part.FindCubismModel(true);
123+
var parts = model.Parts;
124+
var drawables = model.Drawables;
125+
126+
_parent = part.UnmanagedParentIndex < 0 ? null : parts[part.UnmanagedParentIndex];
127+
128+
var childParts = new CubismPart[0];
129+
for (var i = 0; i < parts.Length; i++)
130+
{
131+
if (parts[i].UnmanagedParentIndex == part.UnmanagedIndex)
132+
{
133+
System.Array.Resize(ref childParts, childParts.Length + 1);
134+
childParts[childParts.Length - 1] = parts[i];
135+
}
136+
}
137+
138+
ChildParts = new ReorderableList(childParts, typeof(CubismPart), false, false, false, false)
139+
{
140+
drawElementCallback = (rect, index, isActive, isFocused) =>
141+
{
142+
var element = childParts[index];
143+
rect.height = EditorGUIUtility.singleLineHeight;
144+
var labelRect = new Rect(rect.x, rect.y, rect.width * 0.2f, rect.height);
145+
var objRect = new Rect(rect.x + labelRect.width, rect.y, rect.width * 0.8f, rect.height);
146+
EditorGUI.LabelField(labelRect, $"{index}");
147+
EditorGUI.ObjectField(objRect, childParts[index], typeof(CubismPart), true);
148+
}
149+
};
150+
151+
int count = 0;
152+
ChildPartDrawables = new InternalTreeInfo(part, drawables, parts, ref count);
153+
DrawablesTotalCount = count;
154+
}
155+
156+
private class InternalTreeInfo
157+
{
158+
public bool Foldout = true;
159+
public readonly CubismPart Part;
160+
public readonly CubismDrawable[] Drawables;
161+
162+
public readonly InternalTreeInfo[] Childs;
163+
164+
165+
public InternalTreeInfo(CubismPart part, CubismDrawable[] srcDrawables, CubismPart[] srcParts, ref int drawableCount)
166+
{
167+
this.Part = part;
168+
Drawables = new CubismDrawable[0];
169+
for (var i = 0; i < srcDrawables.Length; i++)
170+
{
171+
if (srcDrawables[i].UnmanagedParentIndex == part.UnmanagedIndex)
172+
{
173+
System.Array.Resize(ref Drawables, Drawables.Length + 1);
174+
Drawables[Drawables.Length - 1] = srcDrawables[i];
175+
drawableCount++;
176+
}
177+
}
178+
179+
Childs = new InternalTreeInfo[0];
180+
for (var i = 0; i < srcParts.Length; i++)
181+
{
182+
if (srcParts[i].UnmanagedParentIndex == part.UnmanagedIndex)
183+
{
184+
System.Array.Resize(ref Childs, Childs.Length + 1);
185+
Childs[Childs.Length - 1] = new InternalTreeInfo(srcParts[i], srcDrawables, srcParts, ref drawableCount);
186+
}
187+
}
188+
}
189+
}
190+
}
191+
}

Assets/Live2D/Cubism/Editor/Inspectors/CubismPartInspector.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.

0 commit comments

Comments
 (0)