Search Unity

how to create 2d bone sprite in runtime mode

Discussion in '2D' started by luoweihong, Apr 27, 2021.

  1. luoweihong

    luoweihong

    Joined:
    May 27, 2019
    Posts:
    56
    In 2d Animation package I saw the SpriteSkinEdiotr can use the CreateBoneHierarchy method


    private void DoGenerateBonesButton()
    {
    if (GUILayout.Button("Create Bones", GUILayout.MaxWidth(125f)))
    {
    foreach (var t in targets)
    {
    var spriteSkin = t as SpriteSkin;
    var sprite = spriteSkin.spriteRenderer.sprite;
    if (sprite == null || spriteSkin.rootBone != null)
    continue;
    Undo.RegisterCompleteObjectUndo(spriteSkin, "Create Bones");
    Debug.Log("#######"+ spriteSkin);
    spriteSkin.CreateBoneHierarchy();
    foreach (var transform in spriteSkin.boneTransforms)
    Undo.RegisterCreatedObjectUndo(transform.gameObject, "Create Bones");
    ResetBoundsIfNeeded(spriteSkin);
    EditorUtility.SetDirty(spriteSkin);
    }
    BoneGizmo.instance.boneGizmoController.OnSelectionChanged();
    }
    }


    but i Can't use this method in my script? why
     
  2. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    207
    Hi @luoweihong you can't access that method yourself because it's an internal. Why are you trying to call that method? Are you making some custom tools to work with Sprite Skin component?