コード例 #1
0
        private Vector3 GetFlippedBonePosition(BoneCache bone, Vector2 startPosition, Rect spriteRect
                                               , bool flipX, bool flipY)
        {
            Vector3 position = startPosition;

            if (flipX)
            {
                position.x += spriteRect.width - bone.position.x;
            }
            else
            {
                position.x += bone.position.x;
            }

            if (flipY)
            {
                position.y += spriteRect.height - bone.position.y;
            }
            else
            {
                position.y += bone.position.y;
            }

            position.z = bone.position.z;
            return(position);
        }
コード例 #2
0
 void BoneDataChanged(BoneCache bone)
 {
     if (m_SkeletonToolView.target == bone)
     {
         m_SkeletonToolView.Update(bone.name, Mathf.RoundToInt(bone.depth), bone.position, bone.rotation.eulerAngles.z, bone.bindPoseColor);
     }
 }
コード例 #3
0
 void OnBoneNameChanged(BoneCache bone)
 {
     if (m_Model.view.visible)
     {
         SetViewHeaderText();
     }
 }
コード例 #4
0
 void BoneDataChanged(BoneCache bone)
 {
     if (m_SkeletonToolView.target == bone)
     {
         m_SkeletonToolView.Update(bone.name, Mathf.RoundToInt(bone.depth));
     }
 }
コード例 #5
0
 private void HandleCancelMultiStepAction()
 {
     if (view.DoCancelMultistepAction(false))
     {
         m_PrevCreatedBone = null;
     }
 }
コード例 #6
0
        private void ValidateBone(BoneCache bone)
        {
            if (bone == null)
            {
                return;
            }

            var skinningCache = bone.skinningCache;

            if (skinningCache.hasCharacter)
            {
                if (bone.skeleton != skinningCache.character.skeleton)
                {
                    throw new Exception("Selection Exception: bone does not belong to character skeleton");
                }
            }
            else
            {
                var selectedSprite = skinningCache.selectedSprite;

                if (selectedSprite == null)
                {
                    throw new Exception("Selection Exception: skeleton not selected");
                }
                else
                {
                    var skeleton = selectedSprite.GetSkeleton();

                    if (bone.skeleton != skeleton)
                    {
                        throw new Exception("Selection Exception: bone's skeleton does not match selected skeleton");
                    }
                }
            }
        }
コード例 #7
0
        public static BoneCache CreateBone(this SkeletonCache skeleton, BoneCache parentBone, Vector3 position, Vector3 endPosition, bool isChained, string name)
        {
            Debug.Assert(skeleton != null);

            if (parentBone != null)
            {
                Debug.Assert(skeleton.Contains(parentBone));
            }

            var bone = skeleton.skinningCache.CreateCache <BoneCache>();

            bone.SetParent(parentBone);
            bone.name          = name;
            bone.bindPoseColor = ModuleUtility.CalculateNiceColor(skeleton.BoneCount, 6);
            bone.position      = position;
            bone.endPosition   = endPosition;

            if (isChained && parentBone != null)
            {
                parentBone.chainedChild = bone;
            }

            skeleton.AddBone(bone);


            return(bone);
        }
コード例 #8
0
        public string GetUniqueName(BoneCache bone)
        {
            Debug.Assert(Contains(bone));

            var boneName = bone.name;
            var names    = m_Bones.ConvertAll(b => b.name);
            var index    = IndexOf(bone);
            var count    = 0;

            Debug.Assert(index < names.Count);

            for (var i = 0; i < index; ++i)
            {
                if (names[i].Equals(boneName))
                {
                    ++count;
                }
            }

            if (count == 0)
            {
                return(boneName);
            }

            return(string.Format("{0} ({1})", boneName, count + 1));
        }
コード例 #9
0
 private void OnBoneNameChanged(BoneCache bone)
 {
     if (m_Model.view.visible)
     {
         m_Model.view.OnSkeletonChanged();
     }
 }
コード例 #10
0
 void OnBoneNameChanged(BoneCache bone)
 {
     if (m_Model.view.visible)
     {
         m_Model.view.UpdateList(m_Model.selectionInfluencedBones);
         m_Model.view.UpdateSelection(m_Model.selectedBones);
     }
 }
コード例 #11
0
 void OnBoneDepthChanged(BoneCache bone)
 {
     SetAnimationEvent(new AnimationEvent()
     {
         sub_type = AnimationEventType.BoneDepthChanged,
         data     = ""
     });
 }
コード例 #12
0
        public void SetTreeViewBoneName(IList <TreeViewItem> items, BoneCache bone)
        {
            var treeBone = items.FirstOrDefault(x => ((TreeViewItemBase <BoneCache>)x).customData == bone);

            if (treeBone != null)
            {
                treeBone.displayName = bone.name;
            }
        }
コード例 #13
0
 private void BuildBoneName(StringBuilder sb, BoneCache bone)
 {
     if (bone.parentBone != null)
     {
         BuildBoneName(sb, bone.parentBone);
         sb.Append(kNameSeparator);
     }
     sb.Append(bone.name);
 }
コード例 #14
0
 private void BoneColorChanged(BoneCache selectedBone, Color32 color)
 {
     if (selectedBone != null)
     {
         skinningCache.BeginUndoOperation(TextContent.colorBoneChanged);
         selectedBone.bindPoseColor = color;
         skinningCache.events.dataModified.Invoke();
     }
 }
コード例 #15
0
        private void DrawBone(BoneCache bone, Color color)
        {
            var isSelected           = selection.Contains(bone.ToCharacterIfNeeded());
            var isNotOnVisualElement = !skinningCache.IsOnVisualElement();
            var isJointHovered       = view.IsActionHot(SkeletonAction.None) && hoveredJoint == bone && isNotOnVisualElement;
            var isTailHovered        = view.IsActionHot(SkeletonAction.None) && hoveredTail == bone && isNotOnVisualElement;

            view.DrawBone(bone.position, bone.right, Vector3.forward, bone.length, color, bone.chainedChild != null, isSelected, isJointHovered, isTailHovered, bone == hotBone);
        }
コード例 #16
0
        public void SetName(BoneCache bone, string name)
        {
            var characterBone = bone.ToCharacterIfNeeded();

            characterBone.name = name;
            if (characterBone != bone || skinningCache.mode == SkinningMode.Character)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }
        }
コード例 #17
0
 private void BonePositionChanged(BoneCache selectedBone, Vector2 position)
 {
     if (selectedBone != null)
     {
         skinningCache.BeginUndoOperation(TextContent.moveBone);
         selectedBone.position = position;
         HandleUtility.Repaint();
         m_SkeletonController.InvokePoseChanged();
     }
 }
コード例 #18
0
ファイル: SkinningModule.cs プロジェクト: Habislife/unitygame
        private void OnBoneNameChanged(BoneCache bone)
        {
            var character = skinningCache.character;

            if (character != null && character.skeleton == bone.skeleton)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }
            DataModified();
        }
コード例 #19
0
        public static void SetEndPosition(this SkeletonCache skeleton, BoneCache bone, Vector3 endPosition)
        {
            Debug.Assert(skeleton != null);
            Debug.Assert(bone != null);
            Debug.Assert(skeleton.Contains(bone));

            var childrenStorage = bone.GetChildrenWoldPose();

            bone.endPosition = endPosition;
            bone.SetChildrenWorldPose(childrenStorage);
        }
コード例 #20
0
 private void BoneRotationChanged(BoneCache selectedBone, float rotation)
 {
     if (selectedBone != null)
     {
         var euler = selectedBone.rotation.eulerAngles;
         euler.z = rotation;
         skinningCache.BeginUndoOperation(TextContent.rotateBone);
         selectedBone.rotation = Quaternion.Euler(euler);
         HandleUtility.Repaint();
         m_SkeletonController.InvokePoseChanged();
     }
 }
コード例 #21
0
        public void AddBone(BoneCache bone, bool worldPositionStays)
        {
            Debug.Assert(bone != null);
            Debug.Assert(!Contains(bone));

            if (bone.parent == null)
            {
                bone.SetParent(this, worldPositionStays);
            }

            m_Bones.Add(bone);
        }
コード例 #22
0
        public void SetBoneColor(BoneCache bone, Color color)
        {
            var characterBone = bone.ToCharacterIfNeeded();

            characterBone.bindPoseColor = color;

            if (characterBone != bone || skinningCache.mode == SkinningMode.Character)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }

            skinningCache.events.boneColorChanged.Invoke(bone);
        }
コード例 #23
0
        public void SetDepth(BoneCache bone, int depth)
        {
            var characterBone = bone.ToCharacterIfNeeded();

            characterBone.depth = depth;

            if (characterBone != bone || skinningCache.mode == SkinningMode.Character)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }

            skinningCache.events.boneDepthChanged.Invoke(bone);
        }
コード例 #24
0
        public void Show(BoneCache target, bool isReadOnly)
        {
            m_BoneInspectorPanel.target = target;
            m_BoneInspectorPanel.SetHiddenFromLayout(false);
            var readOnlyProperty = BoneInspectorPanel.PropertyReadOnly.None;

            if (isReadOnly)
            {
                readOnlyProperty = BoneInspectorPanel.PropertyReadOnly.Name |
                                   BoneInspectorPanel.PropertyReadOnly.Depth |
                                   BoneInspectorPanel.PropertyReadOnly.Color;
            }
            m_BoneInspectorPanel.SetReadOnly(readOnlyProperty);
        }
コード例 #25
0
 private int GetBoneNameHash(StringBuilder sb, BoneCache bone, SpriteCache sprite = null)
 {
     sb.Clear();
     BuildBoneName(sb, bone);
     sb.Append(kNameSeparator);
     if (sprite != null)
     {
         sb.Append(sprite.id);
     }
     else
     {
         sb.Append(0);
     }
     return(Animator.StringToHash(sb.ToString()));
 }
コード例 #26
0
        private static void AddTreeViewItem(IList <TreeViewItem> rows, BoneCache bone, BoneCache[] bones, int depth)
        {
            var item = new TreeViewItemBase <BoneCache>(bone.GetInstanceID(), depth, bone.name, bone);

            rows.Add(item);

            var children = bones.Where(x => x.parentBone == bone).ToArray();

            System.Array.Sort(children, (a, b) => a.siblingIndex.CompareTo(b.siblingIndex));

            foreach (var childBone in children)
            {
                AddTreeViewItem(rows, childBone, bones, depth + 1);
            }
        }
コード例 #27
0
        public void DestroyBone(BoneCache bone)
        {
            Debug.Assert(bone != null);
            Debug.Assert(Contains(bone));

            m_Bones.Remove(bone);

            var children = bone.children;

            foreach (var child in children)
            {
                child.SetParent(bone.parent);
            }

            skinningCache.Destroy(bone);
        }
コード例 #28
0
        public Color GetOutlineColor(BoneCache bone, bool isSelected, bool isHovered)
        {
            var skinningCache = bone.skinningCache;

            if (isSelected)
            {
                return(SelectionOutlineSettings.outlineColor);
            }

            if (isHovered)
            {
                return(Handles.preselectionColor);
            }

            return(SetAlpha(CalculateOutlineColor(GetBoneColorRaw(bone), VisibilityToolSettings.boneOpacity), GetAlpha(bone), VisibilityToolSettings.boneOpacity));
        }
コード例 #29
0
        private void BoneDepthChanged(BoneCache selectedBone, int depth)
        {
            if (selectedBone != null)
            {
                if (Mathf.RoundToInt(selectedBone.depth) == depth)
                {
                    return;
                }

                using (skinningCache.UndoScope(TextContent.boneDepth))
                {
                    selectedBone.depth = depth;
                    skinningCache.events.boneDepthChanged.Invoke(selectedBone);
                }
            }
        }
コード例 #30
0
        public override void Initialize(LayoutOverlay layout)
        {
            base.Initialize(layout);

            m_WeightPainterPanel = WeightPainterPanel.GenerateFromUXML();
            m_WeightPainterPanel.SetHiddenFromLayout(true);
            layout.rightOverlay.Add(m_WeightPainterPanel);

            m_WeightPainterPanel.sliderStarted += () =>
            {
                EditStart(skinningCache.vertexSelection, false);
            };
            m_WeightPainterPanel.sliderChanged += (value) =>
            {
                EditWeights(value, true);
                meshTool.UpdateWeights();
            };
            m_WeightPainterPanel.sliderEnded += () =>
            {
                EditEnd();
            };
            m_WeightPainterPanel.bonePopupChanged += (i) =>
            {
                var skeleton = skinningCache.GetEffectiveSkeleton(skinningCache.selectedSprite);

                if (skeleton != null)
                {
                    BoneCache bone = null;

                    if (i != -1)
                    {
                        bone = skeleton.GetBone(i).ToCharacterIfNeeded();
                    }

                    if (bone != skinningCache.skeletonSelection.activeElement)
                    {
                        using (skinningCache.UndoScope(TextContent.boneSelection))
                        {
                            skinningCache.skeletonSelection.activeElement = bone;
                            InvokeBoneSelectionChanged();
                        }
                    }
                }
            };
            m_WeightPainterPanel.weightsChanged += () => meshTool.UpdateWeights();
        }