Exemplo n.º 1
0
        private void CreateCharacter(ISpriteEditorDataProvider spriteEditor)
        {
            var characterProvider = spriteEditor.GetDataProvider <ICharacterDataProvider>();

            if (characterProvider != null)
            {
                var characterData  = characterProvider.GetCharacterData();
                var characterParts = new List <CharacterPartCache>();

                m_Character     = CreateCache <CharacterCache>();
                m_BonesReadOnly = spriteEditor.GetDataProvider <IMainSkeletonDataProvider>() != null;

                var skeleton = CreateCache <SkeletonCache>();

                var characterBones = characterData.bones;

                skeleton.SetBones(CreateBoneCacheFromSpriteBones(characterBones, 1.0f));
                skeleton.position = Vector3.zero;

                var bones = skeleton.bones;
                foreach (var p in characterData.parts)
                {
                    var spriteBones = p.bones != null?p.bones.ToList() : new List <int>();

                    var characterPartBones = spriteBones.ConvertAll(i => bones.ElementAtOrDefault(i)).ToArray();
                    var characterPart      = CreateCache <CharacterPartCache>();

                    var positionInt = p.spritePosition.position;
                    characterPart.position    = new Vector2(positionInt.x, positionInt.y);
                    characterPart.sprite      = GetSprite(p.spriteId);
                    characterPart.bones       = characterPartBones;
                    characterPart.parentGroup = p.parentGroup;
                    characterPart.order       = p.order;

                    var mesh = characterPart.sprite.GetMesh();
                    if (mesh != null)
                    {
                        mesh.SetCompatibleBoneSet(characterPartBones);
                    }

                    characterParts.Add(characterPart);

                    m_CharacterPartMap.Add(characterPart.sprite, characterPart);
                }
                if (characterData.characterGroups != null)
                {
                    m_Character.groups = characterData.characterGroups.Select(x =>
                    {
                        var group         = CreateCache <CharacterGroupCache>();
                        group.name        = x.name;
                        group.parentGroup = x.parentGroup;
                        group.order       = x.order;
                        return(group);
                    }).ToArray();
                }
                else
                {
                    m_Character.groups = new CharacterGroupCache[0];
                }

                m_Character.parts     = characterParts.ToArray();
                m_Character.skeleton  = skeleton;
                m_Character.dimension = characterData.dimension;
                CreateSpriteSheetSkeletons();
            }
        }
Exemplo n.º 2
0
 private int GetCharacterGroupHash(StringBuilder sb, CharacterGroupCache characterGroup, CharacterCache characterCache)
 {
     sb.Clear();
     BuildGroupName(sb, characterGroup, characterCache);
     return(Animator.StringToHash(sb.ToString()));
 }