-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VRM10SpringBoneColliderGroup 改善 #2485
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
|
@@ -14,5 +15,80 @@ public class VRM10SpringBoneColliderGroup : MonoBehaviour | |
|
||
[SerializeField] | ||
public List<VRM10SpringBoneCollider> Colliders = new List<VRM10SpringBoneCollider>(); | ||
|
||
string GetName() | ||
{ | ||
if (!string.IsNullOrEmpty(Name)) | ||
{ | ||
return Name; | ||
} | ||
return Colliders[0].name; | ||
} | ||
|
||
#if UNITY_EDITOR | ||
[ContextMenu("Create child and move to that")] | ||
public void Separate() | ||
{ | ||
var vrm = GetComponentInParent<Vrm10Instance>(); | ||
if (vrm == null) | ||
{ | ||
return; | ||
} | ||
if (Colliders == null || Colliders.Count == 0) | ||
{ | ||
return; | ||
} | ||
|
||
UnityEditor.Undo.IncrementCurrentGroup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この辺ビルドするとエラーになりません? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 忘れてたー |
||
UnityEditor.Undo.SetCurrentGroupName("VRM10SpringBoneColliderGroup.Separate"); | ||
var undo = UnityEditor.Undo.GetCurrentGroup(); | ||
|
||
var child = new GameObject($"group: {GetName()}"); | ||
UnityEditor.Undo.RegisterCreatedObjectUndo(child, "child"); | ||
UnityEditor.Undo.SetTransformParent(child.transform, transform, "setParent"); | ||
|
||
var group = UnityEditor.Undo.AddComponent<VRM10SpringBoneColliderGroup>(child); | ||
group.Name = Name; | ||
group.Colliders = Colliders.ToList(); | ||
for (int i = 0; i < vrm.SpringBone.ColliderGroups.Count; ++i) | ||
{ | ||
if (vrm.SpringBone.ColliderGroups[i] == this) | ||
{ | ||
vrm.SpringBone.ColliderGroups[i] = group; | ||
} | ||
} | ||
foreach (var spring in vrm.SpringBone.Springs) | ||
{ | ||
for (int i = 0; i < spring.ColliderGroups.Count; ++i) | ||
{ | ||
if (spring.ColliderGroups[i] == this) | ||
{ | ||
spring.ColliderGroups[i] = group; | ||
} | ||
} | ||
} | ||
|
||
if (Application.isPlaying) | ||
{ | ||
Destroy(this); | ||
} | ||
else | ||
{ | ||
UnityEditor.Undo.DestroyObjectImmediate(this); | ||
} | ||
|
||
UnityEditor.Undo.RegisterFullObjectHierarchyUndo(vrm.gameObject, "VRM10SpringBoneColliderGroup.Separate"); | ||
|
||
UnityEditor.Undo.CollapseUndoOperations(undo); | ||
} | ||
#endif | ||
|
||
public void OnDrawGizmosSelected() | ||
{ | ||
foreach (var collider in Colliders) | ||
{ | ||
collider.DrawGizmos(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本当は ifdef やめて Editor asmdef の方に Editor コードは書きたいところだけど
Gizmo や Menu の周りは結構どうしようもないときはあるんだよなあ。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
editor 側に移動しようかと思ったのだけど、
一個の GameObject に複数の同一 component がささっているときに対象を選択するには、
ContextMenu が楽なのでやむを得ない・・・。