Skip to content

Commit 86e5b07

Browse files
Merge pull request #33 from Live2D/develop
R12
2 parents acec6a8 + 03c9665 commit 86e5b07

File tree

9 files changed

+191
-25
lines changed

9 files changed

+191
-25
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 http://live2d.com/eula/live2d-open-software-license-agreement_en.html.
6+
*/
7+
8+
9+
using Live2D.Cubism.Core.Unmanaged;
10+
using Live2D.Cubism.Framework;
11+
using UnityEngine;
12+
13+
14+
namespace Live2D.Cubism.Core
15+
{
16+
/// <summary>
17+
/// Single <see cref="CubismModel"/> canvas information.
18+
/// </summary>
19+
[CubismDontMoveOnReimport]
20+
public sealed class CubismCanvasInformation
21+
{
22+
/// <summary>
23+
/// Initializes instance.
24+
/// </summary>
25+
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
26+
public CubismCanvasInformation(CubismUnmanagedModel unmanagedModel)
27+
{
28+
Reset(unmanagedModel);
29+
}
30+
31+
32+
/// <summary>
33+
/// Unmanaged canvas information from unmanaged model.
34+
/// </summary>
35+
private CubismUnmanagedCanvasInformation UnmanagedCanvasInformation { get; set; }
36+
37+
38+
/// <summary>
39+
/// Width of native model canvas.
40+
/// </summary>
41+
public float CanvasWidth
42+
{
43+
get
44+
{
45+
// Pull data.
46+
return UnmanagedCanvasInformation.CanvasWidth;
47+
}
48+
}
49+
50+
51+
/// <summary>
52+
/// Height of native model canvas.
53+
/// </summary>
54+
public float CanvasHeight
55+
{
56+
get
57+
{
58+
// Pull data.
59+
return UnmanagedCanvasInformation.CanvasHeight;
60+
}
61+
}
62+
63+
64+
/// <summary>
65+
/// Coordinate origin of X axis.
66+
/// </summary>
67+
public float CanvasOriginX
68+
{
69+
get
70+
{
71+
// Pull data.
72+
return UnmanagedCanvasInformation.CanvasOriginX;
73+
}
74+
}
75+
76+
77+
/// <summary>
78+
/// Coordinate origin of Y axis.
79+
/// </summary>
80+
public float CanvasOriginY
81+
{
82+
get
83+
{
84+
// Pull data.
85+
return UnmanagedCanvasInformation.CanvasOriginY;
86+
}
87+
}
88+
89+
90+
/// <summary>
91+
/// Pixels per unit of native model.
92+
/// </summary>
93+
public float PixelsPerUnit
94+
{
95+
get
96+
{
97+
// Pull data.
98+
return UnmanagedCanvasInformation.PixelsPerUnit;
99+
}
100+
}
101+
102+
103+
/// <summary>
104+
/// Revives the instance.
105+
/// </summary>
106+
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
107+
internal void Revive(CubismUnmanagedModel unmanagedModel)
108+
{
109+
UnmanagedCanvasInformation = unmanagedModel.CanvasInformation;
110+
}
111+
112+
/// <summary>
113+
/// Restores instance to initial state.
114+
/// </summary>
115+
/// <param name="unmanagedModel">Handle to unmanaged model.</param>
116+
private void Reset(CubismUnmanagedModel unmanagedModel)
117+
{
118+
Revive(unmanagedModel);
119+
}
120+
}
121+
}

Assets/Live2D/Cubism/Core/CubismModel.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ public CubismDrawable[] Drawables
173173
private set { _drawables = value; }
174174
}
175175

176+
/// <summary>
177+
/// <see cref="CanvasInformation"/> backing field.
178+
/// </summary>
179+
[NonSerialized]
180+
private CubismCanvasInformation _canvasInformation;
181+
182+
/// <summary>
183+
/// Canvas information of model.
184+
/// </summary>
185+
public CubismCanvasInformation CanvasInformation
186+
{
187+
get
188+
{
189+
if (_canvasInformation == null)
190+
{
191+
Revive();
192+
}
193+
194+
195+
return _canvasInformation;
196+
}
197+
private set { _canvasInformation = value; }
198+
}
199+
176200
/// <summary>
177201
/// Parameter store cache.
178202
/// </summary>
@@ -222,11 +246,12 @@ private void Revive()
222246
Parts = GetComponentsInChildren<CubismPart>();
223247
Drawables = GetComponentsInChildren<CubismDrawable>();
224248

225-
226249
Parameters.Revive(TaskableModel.UnmanagedModel);
227250
Parts.Revive(TaskableModel.UnmanagedModel);
228251
Drawables.Revive(TaskableModel.UnmanagedModel);
229252

253+
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
254+
230255
_parameterStore = GetComponent<CubismParameterStore>();
231256
}
232257

@@ -255,6 +280,8 @@ private void Reset(CubismMoc moc)
255280
Parameters = parameters.GetComponentsInChildren<CubismParameter>();
256281
Parts = parts.GetComponentsInChildren<CubismPart>();
257282
Drawables = drawables.GetComponentsInChildren<CubismDrawable>();
283+
284+
CanvasInformation = new CubismCanvasInformation(TaskableModel.UnmanagedModel);
258285
}
259286

260287
/// <summary>

Assets/Live2D/Cubism/Framework/Json/CubismModel3Json.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,21 @@ public CubismModel ToModel(MaterialPicker pickMaterial, TexturePicker pickTextur
353353

354354

355355
// Initialize drawables.
356-
for (var i = 0; i < HitAreas.Length; i++)
356+
if(HitAreas != null)
357357
{
358-
for (var j = 0; j < drawables.Length; j++)
358+
for (var i = 0; i < HitAreas.Length; i++)
359359
{
360-
if (drawables[j].Id == HitAreas[i].Id)
360+
for (var j = 0; j < drawables.Length; j++)
361361
{
362-
// Add components for hit judgement to HitArea target Drawables.
363-
var hitDrawable = drawables[j].gameObject.AddComponent<CubismHitDrawable>();
364-
hitDrawable.Name = HitAreas[i].Name;
362+
if (drawables[j].Id == HitAreas[i].Id)
363+
{
364+
// Add components for hit judgement to HitArea target Drawables.
365+
var hitDrawable = drawables[j].gameObject.AddComponent<CubismHitDrawable>();
366+
hitDrawable.Name = HitAreas[i].Name;
365367

366-
drawables[j].gameObject.AddComponent<CubismRaycastable>();
367-
break;
368+
drawables[j].gameObject.AddComponent<CubismRaycastable>();
369+
break;
370+
}
368371
}
369372
}
370373
}

Assets/Live2D/Cubism/Framework/Motion/CubismMotionController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ private void OnEnable()
255255
}
256256

257257
// Create Playable Graph.
258+
#if UNITY_2018_1_OR_NEWER
258259
_playableGrap = PlayableGraph.Create("Playable Graph : " + this.FindCubismModel().name);
260+
#else
261+
_playableGrap = PlayableGraph.Create();
262+
#endif
259263
_playableGrap.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
260264

261265
// Create Playable Output.

Assets/Live2D/Cubism/Framework/Motion/CubismMotionLayer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,32 @@ public void StopAnimation(int index)
129129
if(index == 0 && _motionStates.Count == 1)
130130
{
131131
_isFinished = true;
132+
#if UNITY_2017_3_OR_NEWER
132133
_motionStates[0].ClipMixer.GetInput(0).Pause();
134+
#else
135+
_motionStates[0].ClipMixer.GetInput(0).SetPlayState(PlayState.Paused);
136+
#endif
133137
return;
134138
}
135139

136140
// Disconnect from previou state.
137141
var preMixer = (index == 0) ? PlayableOutput : _motionStates[index - 1].ClipMixer;
138142
var lastInput = (index == 0) ? 0 : _motionStates[index - 1].ClipMixer.GetInputCount() - 1;
143+
144+
#if UNITY_2018_2_OR_NEWER
139145
preMixer.DisconnectInput(lastInput);
146+
#else
147+
preMixer.GetGraph().Disconnect(preMixer, lastInput);
148+
#endif
140149

141150
// Connect next state.
142151
if(index + 1 < _motionStates.Count)
143152
{
153+
#if UNITY_2018_2_OR_NEWER
144154
_motionStates[index].ClipMixer.DisconnectInput(_motionStates[index].ClipMixer.GetInputCount() - 1);
155+
#else
156+
_motionStates[index].ClipMixer.GetGraph().Disconnect(_motionStates[index].ClipMixer, _motionStates[index].ClipMixer.GetInputCount() - 1);
157+
#endif
145158

146159
preMixer.ConnectInput(lastInput, _motionStates[index + 1].ClipMixer, 0);
147160
preMixer.SetInputWeight(lastInput, 1.0f);
@@ -246,7 +259,11 @@ public void PlayAnimation(AnimationClip clip, bool isLoop = true, float speed =
246259
}
247260
else
248261
{
262+
#if UNITY_2018_2_OR_NEWER
249263
PlayableOutput.DisconnectInput(0);
264+
#else
265+
PlayableOutput.GetGraph().Disconnect(PlayableOutput, 0);
266+
#endif
250267
PlayableOutput.ConnectInput(0, state.ClipMixer, 0);
251268
PlayableOutput.SetInputWeight(0, 1.0f);
252269
}

Assets/Live2D/Cubism/Framework/Motion/CubismMotionState.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ public static CubismMotionState CreateCubismMotionState(PlayableGraph playableGr
7373
public void ConnectClipMixer(AnimationMixerPlayable clipMixer)
7474
{
7575
var lastInput = ClipMixer.GetInputCount() - 1;
76+
#if UNITY_2018_2_OR_NEWER
7677
ClipMixer.DisconnectInput(lastInput);
78+
#else
79+
ClipMixer.GetGraph().Disconnect(ClipMixer, lastInput);
80+
#endif
7781
ClipMixer.ConnectInput(lastInput, clipMixer, 0);
7882
ClipMixer.SetInputWeight(lastInput, 1.0f);
7983
}

Assets/Live2D/Cubism/Framework/MotionFade/CubismFadeController.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ private void UpdateFade(ICubismFadeState fadeState)
137137

138138
var time = Time.time;
139139

140-
var isDoneAllFadeIn = true;
141-
142140
// Calculate MotionFade.
143141
for (var i = 0; i < playingMotions.Count; i++)
144142
{
@@ -222,18 +220,10 @@ private void UpdateFade(ICubismFadeState fadeState)
222220
fadeMotion.ParameterFadeInTimes[index], fadeMotion.ParameterFadeOutTimes[index],
223221
motionWeight, DestinationParts[j].Opacity);
224222
}
225-
226-
227-
if (erapsedTime > fadeInTime)
228-
{
229-
continue;
230-
}
231-
isDoneAllFadeIn = false;
232223
}
233224

234-
if (!isDoneAllFadeIn || !fadeState.GetStateTransitionFinished())
225+
if (!fadeState.GetStateTransitionFinished())
235226
{
236-
// Do not process any motion that has never finished fade-in.
237227
return;
238228
}
239229

@@ -250,7 +240,7 @@ private void UpdateFade(ICubismFadeState fadeState)
250240
continue;
251241
}
252242

253-
// If fade-in of all motion has been completed, delete the motion that has been played back.
243+
// If fade-in has been completed, delete the motion that has been played back.
254244
fadeState.StopAnimation(i);
255245
}
256246
}

Assets/Live2D/Cubism/Framework/Physics/CubismPhysicsMath.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ public static float Normalize(CubismParameter parameter,
164164

165165
if (maxValue < parameter.Value)
166166
{
167-
return result;
167+
parameter.Value = maxValue;
168168
}
169169

170170
var minValue = Mathf.Min(parameter.MaximumValue, parameter.MinimumValue);
171171
if (minValue > parameter.Value)
172172
{
173-
return result;
173+
parameter.Value = minValue;
174174
}
175175

176176
var minNormValue = Mathf.Min(normalizedMinimum, normalizedMaximum);

Assets/Live2D/Cubism/Framework/Pose/Editor/CubismPoseMotionImporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ private static void RegisterModelImporter()
4747
private static void OnModelImport(CubismModel3JsonImporter sender, CubismModel model)
4848
{
4949
var shouldImportAsOriginalWorkflow = CubismUnityEditorMenu.ShouldImportAsOriginalWorkflow;
50+
var pose3Json = sender.Model3Json.Pose3Json;
5051

5152
// Fail silently...
52-
if(!shouldImportAsOriginalWorkflow)
53+
if(!shouldImportAsOriginalWorkflow || pose3Json == null)
5354
{
5455
return;
5556
}
5657

5758
var assetsDirectoryPath = Application.dataPath.Replace("Assets", "");
5859
var assetPath = sender.AssetPath.Replace(assetsDirectoryPath, "");
5960
var fileReferences = sender.Model3Json.FileReferences;
60-
var pose3Json = sender.Model3Json.Pose3Json;
6161

6262
// Create pose animation clip
6363
var motions = new List<CubismModel3Json.SerializableMotion>();

0 commit comments

Comments
 (0)