Esempio n. 1
0
    //
    void RandomReplaceSkin()
    {
        // This suit has been replaced, Next suit
        if (this._replaceSuitParts.Count == 0)
        {
            this._replaceSuitIndex++;
            var suitNames = this._suitConfigs.Keys.ToArray();
            if (this._replaceSuitIndex >= suitNames.Length)
            {
                this._replaceSuitIndex = 0;
            }
            // Refill the unset parits
            this._replaceSuitParts.AddRange(this._suitConfigs[suitNames[this._replaceSuitIndex]]);
        }
        // Random one part in this suit
        var randomPartIndex = Random.Range(0, this._replaceSuitParts.Count);
        //
        var partArmatureName = this._replaceSuitParts[randomPartIndex];
        //
        ArmatureData partArmatureData = UnityFactory.factory.GetArmatureData(partArmatureName);

        // Replace skin
        UnityFactory.factory.ReplaceSkin(this._bodyArmatureComp.armature, partArmatureData.defaultSkin);
        // Remove has been replaced
        this._replaceSuitParts.RemoveAt(randomPartIndex);
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        // Change armatureposition.
        //uac.transform.localPosition = transform.position;//;new Vector3(0.0f, 0.0f, 0.0f);
        if (Input.GetButtonDown("Jump"))
        {
            animComponent.animation.FadeIn("Jump", 0.2f);
        }

        //test skin change
        if (Input.GetKeyDown(KeyCode.T))
        {
            //animComponent.armature.
            //UnityFactory.factory.
            //animComponent.
            Debug.Log("Anim event skin change attempt");
            string       newSkin         = isRed ? "GreenGuy" : "RedGuy";
            ArmatureData newArmatureData = UnityFactory.factory.GetArmatureData(newSkin);
            UnityFactory.factory.ReplaceSkin(animComponent.armature, newArmatureData.defaultSkin);
            isRed = !isRed;
        }

        //test data ubnload
        if (Input.GetKeyDown(KeyCode.I))
        {
            DragonBonesDataDebugPrint();

            UnityFactory.factory.RemoveDragonBonesData("GreenGuy");
            UnityFactory.factory.RemoveTextureAtlasData("GreenGuy");

            DragonBonesDataDebugPrint();
        }
    }
Esempio n. 3
0
        public static void transformArmatureDataAnimations(ArmatureData armatureData)
        {
            List <AnimationData> animationDataList = armatureData.AnimationDataList;
            int i = animationDataList.Count;

            while (i-- > 0)
            {
                TransformAnimationData(animationDataList[i], armatureData);
            }
        }
Esempio n. 4
0
        internal void Initialize(ArmatureData data)
        {
            FrameRate = data.FrameRate;

            if (data.Bones.Any())
            {
                Bones.Add(new DbBone(this, data.Bones[0]));
                for (var i = 1; i < data.Bones.Length; i++)
                {
                    var bone       = data.Bones[i];
                    var parentBone = Bones[bone.Parent];
                    parentBone.AddBone(new DbBone(this, bone));
                }
            }

            foreach (var slot in data.Slots)
            {
                var parentBone = Bones[slot.Parent];
                parentBone.AddSlot(new DbSlot(this, slot));
            }

            foreach (var fill in data.Skins[0].SlotFills)
            {
                var slot = Slots[fill.SlotName];
                foreach (var display in fill.Displays)
                {
                    slot.AddDisplay(display);
                }
            }

            foreach (var animation in data.Animations)
            {
                Animations.Add(new DbAnimation(this, animation));
            }

            foreach (var ik in data.InverseKinematics)
            {
                IkConstraints.Add(new DbIkConstraint(ik)); // TODO
            }
            SortSlots();
            ResetBones();
            // load DefaultActions into Dictionary
            DefaultActions = data.DefaultActions[0];
            if (DefaultActions.ContainsKey("gotoAndPlay") && Animations.Contains(DefaultActions["gotoAndPlay"]))
            {
                GotoAndPlay(DefaultActions["gotoAndPlay"]);
            }
        }
Esempio n. 5
0
        public static void AddHideTimeline(AnimationData animationData, ArmatureData armatureData)
        {
            List <BoneData> boneDataList = armatureData.BoneDataList;
            int             i            = boneDataList.Count;

            BoneData boneData;
            string   boneName;

            while (i-- > 0)
            {
                boneData = boneDataList[i];
                boneName = boneData.Name;
                if (animationData.GetTimeline(boneName) == null)
                {
                    animationData.AddTimeline(TransformTimeline.HIDE_TIMELINE, boneName);
                }
            }
        }
    /// <summary>
    /// 更换龙骨动画一个插槽里显示对象的显示,如果看不懂,去了解一下龙骨的一些基本概念
    ///http://developer.egret.com/cn/github/egret-docs/DB/dbPro/interface/mainInterface/index.html
    /// </summary>
    /// <param name="slotName">插槽名字</param>
    /// <param name="displayName">显示对象名字</param>
    /// <returns></returns>
    public bool ReplaceSlotDisplay(string slotName, string displayName)
    {
        ArmatureData armatureData = dragonBonesCom.armature.armatureData;

        if (armatureData == null || armatureData.defaultSkin == null)
        {
            return(false);
        }
        Slot slot = dragonBonesCom.armature.GetSlot(slotName);

        if (slot == null)
        {
            return(false);
        }
        var displayData = armatureData.defaultSkin.GetDisplay(slotName, displayName);

        if (displayData == null)
        {
            return(false);
        }
        UnityFactory.factory.ReplaceDisplay(slot, displayData);
        return(true);
    }
Esempio n. 7
0
        public static void TransformArmatureData(ArmatureData armatureData)
        {
            List <BoneData> boneDataList = armatureData.BoneDataList;
            int             i            = boneDataList.Count;
            BoneData        boneData;
            BoneData        parentBoneData;

            while (i-- > 0)
            {
                boneData = boneDataList[i];
                if (boneData.Parent != null)
                {
                    parentBoneData = armatureData.GetBoneData(boneData.Parent);
                    if (parentBoneData != null)
                    {
                        boneData.Transform.Copy(boneData.Global);

                        //Logger.Log(boneData.Name + "  " + boneData.Transform.X + "  " + boneData.Transform.Y);
                        TransformUtil.TransformPointWithParent(boneData.Transform, parentBoneData.Global);
                        //Logger.Log(boneData.Name + "  " + boneData.Transform.X + "  " + boneData.Transform.Y);
                    }
                }
            }
        }
Esempio n. 8
0
        public static void TransformAnimationData(AnimationData animationData, ArmatureData armatureData)
        {
            SkinData        skinData     = armatureData.GetSkinData(null);
            List <BoneData> boneDataList = armatureData.BoneDataList;
            List <SlotData> slotDataList = skinData.SlotDataList;
            int             i            = boneDataList.Count;

            BoneData          boneData;
            TransformTimeline timeline;
            SlotData          slotData;
            DisplayData       displayData;
            TransformTimeline parentTimeline;
            List <Frame>      frameList;
            DBTransform       originTransform;
            Point             originPivot;
            TransformFrame    prevFrame;
            uint           frameListLength;
            TransformFrame frame;

            while (i-- > 0)
            {
                boneData = boneDataList[i];
                timeline = animationData.GetTimeline(boneData.Name);
                if (timeline == null)
                {
                    continue;
                }

                slotData = null;
                foreach (SlotData slotDataObj in slotDataList)
                {
                    if (slotDataObj.Parent == boneData.Name)
                    {
                        slotData = slotDataObj;
                        break;
                    }
                }

                parentTimeline = boneData.Parent != null?animationData.GetTimeline(boneData.Parent) : null;

                frameList = timeline.FrameList;

                originTransform = null;
                originPivot     = null;
                prevFrame       = null;
                frameListLength = (uint)frameList.Count;
                for (int j = 0; j < frameListLength; j++)
                {
                    frame = frameList[j] as TransformFrame;
                    if (parentTimeline != null)
                    {
                        //tweenValues to transform.
                        _helpTransform1.Copy(frame.Global);

                        //get transform from parent timeline.
                        GetTimelineTransform(parentTimeline, frame.Position, _helpTransform2);
                        TransformUtil.TransformPointWithParent(_helpTransform1, _helpTransform2);

                        //transform to tweenValues.
                        frame.Transform.Copy(_helpTransform1);
                    }
                    else
                    {
                        frame.Transform.Copy(frame.Global);
                    }

                    frame.Transform.X      -= boneData.Transform.X;
                    frame.Transform.Y      -= boneData.Transform.Y;
                    frame.Transform.SkewX  -= boneData.Transform.SkewX;
                    frame.Transform.SkewY  -= boneData.Transform.SkewY;
                    frame.Transform.ScaleX -= boneData.Transform.ScaleX;
                    frame.Transform.ScaleY -= boneData.Transform.ScaleY;

                    if (!timeline.Transformed)
                    {
                        if (slotData != null)
                        {
                            frame.ZOrder -= slotData.ZOrder;
                        }
                    }

                    if (originTransform == null)
                    {
                        originTransform = timeline.OriginTransform;
                        originTransform.Copy(frame.Transform);
                        originTransform.SkewX = TransformUtil.FormatRadian(originTransform.SkewX);
                        originTransform.SkewY = TransformUtil.FormatRadian(originTransform.SkewY);
                        originPivot           = timeline.OriginPivot;
                        originPivot.X         = frame.Pivot.X;
                        originPivot.Y         = frame.Pivot.Y;
                    }

                    frame.Transform.X      -= originTransform.X;
                    frame.Transform.Y      -= originTransform.Y;
                    frame.Transform.SkewX   = TransformUtil.FormatRadian(frame.Transform.SkewX - originTransform.SkewX);
                    frame.Transform.SkewY   = TransformUtil.FormatRadian(frame.Transform.SkewY - originTransform.SkewY);
                    frame.Transform.ScaleX -= originTransform.ScaleX;
                    frame.Transform.ScaleY -= originTransform.ScaleY;

                    if (!timeline.Transformed)
                    {
                        frame.Pivot.Y -= originPivot.X;
                        frame.Pivot.Y -= originPivot.Y;
                    }

                    if (prevFrame != null)
                    {
                        float dLX = frame.Transform.SkewX - prevFrame.Transform.SkewX;

                        if (prevFrame.TweenRotate != 0)
                        {
                            if (prevFrame.TweenRotate > 0)
                            {
                                if (dLX < 0)
                                {
                                    frame.Transform.SkewX += (float)Math.PI * 2f;
                                    frame.Transform.SkewY += (float)Math.PI * 2f;
                                }

                                if (prevFrame.TweenRotate > 1)
                                {
                                    frame.Transform.SkewX += (float)Math.PI * 2f * ((float)prevFrame.TweenRotate - 1f);
                                    frame.Transform.SkewY += (float)Math.PI * 2f * ((float)prevFrame.TweenRotate - 1f);
                                }
                            }
                            else
                            {
                                if (dLX > 0)
                                {
                                    frame.Transform.SkewX -= (float)Math.PI * 2f;
                                    frame.Transform.SkewY -= (float)Math.PI * 2f;
                                }

                                if (prevFrame.TweenRotate < 1)
                                {
                                    frame.Transform.SkewX += (float)Math.PI * 2f * ((float)prevFrame.TweenRotate + 1f);
                                    frame.Transform.SkewY += (float)Math.PI * 2f * ((float)prevFrame.TweenRotate + 1f);
                                }
                            }
                        }
                        else
                        {
                            frame.Transform.SkewX = prevFrame.Transform.SkewX + TransformUtil.FormatRadian(frame.Transform.SkewX - prevFrame.Transform.SkewX);
                            frame.Transform.SkewY = prevFrame.Transform.SkewY + TransformUtil.FormatRadian(frame.Transform.SkewY - prevFrame.Transform.SkewY);
                        }
                    }

                    prevFrame = frame;
                }
                timeline.Transformed = true;
            }
        }
Esempio n. 9
0
    static ArmatureData DecodeArmature(JSONClass parent, JSONClass json)
    {
        ArmatureData data = new ArmatureData();

        data.name        = json["name"].Value;
        data.frameRate   = TryGetInt(json, "frameRate", parent["frameRate"].AsInt);
        data.type        = TryGetString(json, "type", "Armature");
        data.vertexDatas = new VertexData();

        //bone
        JSONArray bones = json["bone"].AsArray;

        BoneData[] boneDatas = new BoneData[bones.Count];
        for (int i = 0; i < bones.Count; i++)
        {
            boneDatas[i] = DecodeBone(bones[i].AsObject);
        }
        data.boneDatas = boneDatas;



        //slot
        JSONArray slots = json["slot"].AsArray;

        SlotData[] slotDatas = new SlotData[slots.Count];
        for (int i = 0; i < slots.Count; i++)
        {
            slotDatas[i] = DecodeSlot(slots[i].AsObject);
        }
        data.slotDatas = slotDatas;


        JSONArray          skins       = json["skin"].AsArray;
        List <DisplayData> displayData = new List <DisplayData>();

        for (int i = 0; i < skins.Count; i++)
        {
            JSONClass skin    = skins[i].AsObject;
            JSONArray d_slots = skin["slot"].AsArray;
            for (int j = 0; j < d_slots.Count; j++)
            {
                JSONClass d_slot      = d_slots[j].AsObject;
                string    d_slot_name = d_slot["name"];
                JSONArray d_displays  = d_slot["display"].AsArray;
                for (int k = 0; k < d_displays.Count; k++)
                {
                    displayData.Add(DecodeDisplay(d_displays[k].AsObject, d_slot_name));
                }
            }
        }
        data.displayDatas          = displayData.ToArray();
        data.vertexDatas.vertices  = vertices.ToArray();
        data.vertexDatas.uvs       = uvs.ToArray();
        data.vertexDatas.triangles = triangles.ToArray();
        data.vertexDatas.weights   = weights.ToArray();
        JSONArray animations = json["animation"].AsArray;

        data.animations = new AnimationData[animations.Count];
        for (int i = 0; i < animations.Count; i++)
        {
            data.animations[i] = DecodeAnimation(animations[i].AsObject);
        }

        return(data);
    }
Esempio n. 10
0
    public static void MakeUgData()
    {
        vertices  = new List <float>();
        uvs       = new List <float>();
        triangles = new List <int>();
        weights   = new List <float>();
        //string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        string    path         = "Assets/bingyao_ske.json";
        string    texture_path = "Assets/bingyao_tex.json";
        JSONClass json         = JSON.Parse(File.ReadAllText(path).Replace("null", "\"null\"")).AsObject;

        string save = "Assets/d.asset";

        ugData = AssetDatabase.LoadAssetAtPath <UgData>(save);
        if (ugData == null)
        {
            ugData = ScriptableObject.CreateInstance <UgData>();
            AssetDatabase.CreateAsset(ugData, save);
            AssetDatabase.Refresh();
        }

        ugData.name      = json["name"].Value;
        ugData.version   = json["version"].Value;
        ugData.frameRate = json["frameRate"].AsInt;


        //armature
        JSONArray armature = json["armature"].AsArray;

        ArmatureData[] ads = new ArmatureData[armature.Count];
        for (int i = 0; i < armature.Count; i++)
        {
            ads[i] = DecodeArmature(json, armature[i].AsObject);
        }

        JSONClass   json_tex = JSON.Parse(File.ReadAllText(texture_path).Replace("null", "\"null\"")).AsObject;
        TextureData td       = new TextureData();

        td.width     = json_tex["width"].AsInt;
        td.height    = json_tex["height"].AsInt;
        td.imagePath = json_tex["imagePath"].Value;
        td.name      = json_tex["name"].Value;
        List <SubTextureData> stds         = new List <SubTextureData>();
        JSONArray             sub_textures = json_tex["SubTexture"].AsArray;

        for (int i = 0; i < sub_textures.Count; i++)
        {
            SubTextureData std = new SubTextureData();
            JSONClass      jc  = sub_textures[i].AsObject;
            std.width  = jc["width"].AsInt;
            std.height = jc["height"].AsInt;
            std.x      = jc["x"].AsInt;
            std.y      = jc["y"].AsInt;
            std.name   = jc["name"].Value;
            stds.Add(std);
        }
        td.datas            = stds.ToArray();
        ads[0].textureDatas = td;
        ugData.armatures    = ads;
        EditorUtility.SetDirty(ugData);
        AssetDatabase.SaveAssets();
    }
        /**
         * Build and returns a new Armature instance.
         * @example
         * <listing>
         * var armature:Armature = factory.buildArmature('dragon');
         * </listing>
         * @param	armatureName The name of this Armature instance.
         * @param	The name of this animation.
         * @param	The name of this SkeletonData.
         * @param	The name of this textureAtlas.
         * @param	The name of this skin.
         * @return A Armature instance.
         */
        public Armature BuildArmature(string armatureName, string animationName = null, string skeletonName = null, string textureAtlasName = null, string skinName = null)
        {
            SkeletonData data                  = null;
            ArmatureData armatureData          = null;
            ArmatureData animationArmatureData = null;

            if (skeletonName != null)
            {
                data = _dataDic[skeletonName];
                if (data != null)
                {
                    armatureData = data.GetArmatureData(armatureName);
                }
            }
            else
            {
                foreach (KeyValuePair <string, SkeletonData> skeleton in _dataDic)
                {
                    data         = _dataDic[skeleton.Key];
                    armatureData = data.GetArmatureData(armatureName);
                    if (armatureData != null)
                    {
                        break;
                    }
                }
            }

            if (armatureData == null)
            {
                return(null);
            }

            _currentDataName = skeletonName;

            if (textureAtlasName != null)
            {
                _currentTextureAtlasName = textureAtlasName;
            }
            else
            {
                _currentTextureAtlasName = skeletonName;
            }

            Armature armature = generateArmature();

            armature.Name = armatureName;
            Bone bone;

            foreach (BoneData boneData in armatureData.BoneDataList)
            {
                bone               = new Bone();
                bone.Name          = boneData.Name;
                bone.FixedRotation = boneData.FixedRotation;
                bone.ScaleMode     = boneData.ScaleMode;
                bone.Origin.Copy(boneData.Transform);

                if (armatureData.GetBoneData(boneData.Parent) != null)
                {
                    armature.AddBone(bone, boneData.Parent);
                }
                else
                {
                    armature.AddBone(bone);
                }
            }

            if (animationName != null && animationName != armatureName)
            {
                animationArmatureData = data.GetArmatureData(animationName);
                if (animationArmatureData == null)
                {
                    foreach (KeyValuePair <string, SkeletonData> skeleton in _dataDic)
                    {
                        data = _dataDic[skeleton.Key];
                        animationArmatureData = data.GetArmatureData(animationName);
                        if (animationArmatureData != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (animationArmatureData != null)
            {
                armature.Animation.AnimationDataList = animationArmatureData.AnimationDataList;
            }
            else
            {
                armature.Animation.AnimationDataList = armatureData.AnimationDataList;
            }

            SkinData skinData = armatureData.GetSkinData(skinName);

            if (skinData == null)
            {
                throw new ArgumentException();
            }

            Slot          slot;
            DisplayData   displayData;
            Armature      childArmature;
            int           i;
            List <object> helpArray = new List <object>();

            foreach (SlotData slotData in skinData.SlotDataList)
            {
                bone = armature.GetBone(slotData.Parent);
                if (bone == null)
                {
                    continue;
                }
                slot                 = generateSlot();
                slot.Name            = slotData.Name;
                slot.BlendMode       = slotData.BlendMode;
                slot._originZOrder   = slotData.ZOrder;
                slot._dislayDataList = slotData.DisplayDataList;

                helpArray.Clear();
                i = slotData.DisplayDataList.Count;
                while (i-- > 0)
                {
                    displayData = slotData.DisplayDataList[i];

                    switch (displayData.Type)
                    {
                    case DisplayData.ARMATURE:
                        childArmature = BuildArmature(displayData.Name, null, _currentDataName, _currentTextureAtlasName);
                        if (childArmature != null)
                        {
                            helpArray.Insert(0, childArmature);
                        }
                        break;

                    case DisplayData.IMAGE:
                    default:
                        helpArray.Insert(0, generateDisplay(_textureAtlasDic[_currentTextureAtlasName], displayData.Name, displayData.Pivot.X, displayData.Pivot.Y));
                        break;
                    }
                }
                slot.DisplayList = helpArray;
                slot.changeDisplay(0);
                bone.AddChild(slot);
            }

            //
            i = armature._boneList.Count;
            while (i-- > 0)
            {
                armature._boneList[i].update();
            }

            i = armature._slotList.Count;
            while (i-- > 0)
            {
                slot = armature._slotList[i];
                slot.update();
            }
            armature.UpdateSlotsZOrder();

            return(armature);
        }