Ejemplo n.º 1
0
        public void FillTempBone(int generalBoneID, int lastActiveID)
        {
            int           id            = tempPreviewBones.Count;
            CharacterBone characterBone = characterBones[generalBoneID];

            if (characterBone.selected)
            {
                PreviewBone parentBone = null;
                if (lastActiveID != -1)
                {
                    parentBone = tempPreviewBones[lastActiveID];
                    if (parentBone.childIDs == null)
                    {
                        parentBone.childIDs = new List <int>();
                    }
                    parentBone.childIDs.Add(id);
                }
                tempPreviewBones.Add(new PreviewBone(characterBone.tr, generalBoneID, lastActiveID));
                lastActiveID = id;
            }

            if (characterBone.childIDs != null)
            {
                for (int i = 0; i < characterBone.childIDs.Count; i++)
                {
                    int childId = characterBone.childIDs[i];
                    FillTempBone(childId, lastActiveID);
                }
            }
        }
Ejemplo n.º 2
0
 public void FindConnectionsWithAvatar()
 {
     if (avatar == null)
     {
         return;
     }
     if (avatar.previewBones == null)
     {
         return;
     }
     //connect avatar and preview bones if they has equal name
     for (int i = 0; i < characterBones.Count; i++)
     {
         CharacterBone boneG = characterBones[i];
         foreach (PreviewBone boneA in avatar.previewBones)
         {
             if (boneA.name.Equals(boneG.name) || boneA.name.Equals(characterBones[i].avatarConnection))
             {
                 boneG.selected = true;
                 characterBones[i].avatarConnection = boneA.name;
                 break;
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void DrawBonesHierarchy(CharacterBone bone, bool singleBranch, bool isPreview, bool isCharacterBones)
        {
            if (!singleBranch && bone.childIDs != null)
            {
                GUILayout.BeginVertical();
            }

            if (isCharacterBones)
            {
                DrawScrollBoneBox(bone.name, out bone.rect, Color.green, bone.selected);
            }
            else
            {
                DrawBoneBox(bone.name, out bone.rect, Color.green, bone.selected);
            }

            if (bone.childIDs != null)
            {
                if (bone.childIDs.Count > 1)
                {
                    GUILayout.BeginHorizontal();
                }

                for (int i = 0; i < bone.childIDs.Count; i++)
                {
                    int           id    = bone.childIDs[i];
                    CharacterBone child = isPreview ? tgt.previewBones[id] : tgt.characterBones[id];
                    DrawBonesHierarchy(child, bone.childIDs.Count == 1, isPreview, isCharacterBones);
                }

                if (bone.childIDs.Count > 1)
                {
                    GUILayout.EndHorizontal();
                }
            }

            if (!singleBranch && bone.childIDs != null)
            {
                GUILayout.EndVertical();
            }

            //bottom line to childs
            if (bone.IsRoot)
            {
                return;
            }
            DrawBottomLineToChilds(bone.rect);
        }
Ejemplo n.º 4
0
        private bool UpdateLineDrag()
        {
            if (lineDrag)
            {
                CharacterBone lineEndBone = null;
                for (int i = 0; i < tgt.characterBones.Count; i++)
                {
                    if (scrollRect.Contains(Event.current.mousePosition) && tgt.characterBones[i].rect.Contains(Event.current.mousePosition))
                    {
                        lineEndBone = tgt.characterBones[i];
                        break;
                    }
                }

                if (lineEndBone != null)
                {
                    DrawConnector(lineStartBone.rect, lineEndBone.rect, Color.black, true);
                }
                else
                {
                    DrawConnector(lineStartBone.rect, new Rect(Event.current.mousePosition - new Vector2(10, 0), Vector2.zero), Color.black, false);
                }

                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    lineDrag = false;

                    int generalBoneID = -1;
                    for (int i = 0; i < tgt.characterBones.Count; i++)
                    {
                        if (lineStartBone.name.Equals(tgt.characterBones[i].avatarConnection))
                        {
                            generalBoneID = i;
                            break;
                        }
                    }

                    if (lineEndBone != null)
                    {
                        if (lineStartBone.name.Equals(lineEndBone.avatarConnection))
                        {
                            return(false);
                        }
                        if (generalBoneID >= 0 && !lineEndBone.Equals(tgt.characterBones[generalBoneID]))
                        {
                            tgt.characterBones[generalBoneID].avatarConnection = null;
                            tgt.characterBones[generalBoneID].selected         = false;
                        }
                        lineEndBone.avatarConnection = lineStartBone.name;
                        lineEndBone.selected         = true;
                        return(true);
                    }
                    else if (generalBoneID >= 0)
                    {
                        tgt.characterBones[generalBoneID].avatarConnection = null;
                        tgt.characterBones[generalBoneID].selected         = false;
                        return(true);
                    }
                }
                Repaint();
            }
            return(false);
        }