Пример #1
0
        static Dictionary <int, Vector2> ComputeCenterPoints(MetaProcessingContext ctx, Layer layer)
        {
            var frames = new Dictionary <int, Vector2>();
            var file   = ctx.ImportContext.AseFile;

            foreach (var frame in file)
            {
                Cel cel;
                frame.TryGetCel(layer.Index, out cel);

                if (cel == null)
                {
                    continue;
                }

                Vector2 center;
                if (cel.ComputeWeightedCenter(out center))
                {
                    var pivot    = Vector2.Scale(ctx.ImportContext.Settings.PivotRelativePos, new Vector2(file.Width, file.Height));
                    var posWorld = (center - pivot) / ctx.ImportContext.Settings.PixelsPerUnit;
                    frames.Add(frame.FrameId, posWorld);
                }
            }

            return(frames);
        }
Пример #2
0
        public void Process(MetaProcessingContext ctx, Layer layer)
        {
            var childName = layer.GetParamString(0);
            var bindingX  = new EditorCurveBinding {
                path = childName, type = typeof(Transform), propertyName = "m_LocalPosition.x"
            };
            var bindingY = new EditorCurveBinding {
                path = childName, type = typeof(Transform), propertyName = "m_LocalPosition.y"
            };

            var framePositionByIndex = ComputeCenterPoints(ctx, layer);

            var file = ctx.ImportContext.AseFile;

            foreach (var frameTag in file.FrameTags)
            {
                AnimationClip clip;
                if (!ctx.TryGetClip(frameTag, out clip))
                {
                    continue;
                }

                var curveX = new AnimationCurve();
                var curveY = new AnimationCurve();

                float t = 0;
                for (var frameIndex = frameTag.From; frameIndex <= frameTag.To; frameIndex += 1)
                {
                    Vector2 pos;
                    if (framePositionByIndex.TryGetValue(frameIndex, out pos))
                    {
                        curveX.AddKey(t, pos.x);
                        curveY.AddKey(t, pos.y);
                    }

                    // Duration is given in milliseconds, but Unity wants seconds ..
                    t += file[frameIndex].Duration / 1000f;
                }

                if (curveX.length > 0)
                {
                    MakeConstant(curveX);
                    MakeConstant(curveY);

                    AnimationUtility.SetEditorCurve(clip, bindingX, curveX);
                    AnimationUtility.SetEditorCurve(clip, bindingY, curveY);

                    EditorUtility.SetDirty(clip);
                }
            }
        }
Пример #3
0
        public void Process(MetaProcessingContext ctx, Layer layer)
        {
            var path          = layer.GetParamString(0);
            var bindingOffX   = Binding(path, typeof(BoxCollider2D), "m_Offset.x");
            var bindingOffY   = Binding(path, typeof(BoxCollider2D), "m_Offset.y");
            var bindingSizeX  = Binding(path, typeof(BoxCollider2D), "m_Size.x");
            var bindingSizeY  = Binding(path, typeof(BoxCollider2D), "m_Size.y");
            var bindingEnable = Binding(path, typeof(BoxCollider2D), "m_Enabled");

            LayerParam changeEnableParam;
            var        changeEnable = layer.TryGetParam(1, LayerParamType.Bool, out changeEnableParam) && changeEnableParam.BoolValue;

            var file       = ctx.ImportContext.AseFile;
            var frameRects = ComputeFrameBoundingBoxes(layer, file);

            foreach (var frameTag in file.FrameTags)
            {
                AnimationClip clip;
                if (!ctx.TryGetClip(frameTag, out clip))
                {
                    continue;
                }

                var curveOffX   = new AnimationCurve();
                var curveOffY   = new AnimationCurve();
                var curveSizeX  = new AnimationCurve();
                var curveSizeY  = new AnimationCurve();
                var curveEnable = new AnimationCurve();

                float t         = 0;
                var   hasEnable = false;
                for (var frameIndex = frameTag.From; frameIndex <= frameTag.To; ++frameIndex)
                {
                    var rect   = frameRects[frameIndex];
                    var enable = rect.Size != Vector2.zero;
                    curveEnable.AddKey(new Keyframe(t, enable ? 1 : 0));
                    if (enable)
                    {
                        hasEnable = true;
                        curveOffX.AddKey(t, rect.Center.x);
                        curveOffY.AddKey(t, rect.Center.y);
                        curveSizeX.AddKey(t, rect.Size.x);
                        curveSizeY.AddKey(t, rect.Size.y);
                    }

                    t += file[frameIndex].Duration / 1000.0f;
                }

                if (hasEnable)
                {
                    MakeConstant(curveOffX);
                    MakeConstant(curveOffY);
                    MakeConstant(curveSizeX);
                    MakeConstant(curveSizeY);
                    MakeConstant(curveEnable);

                    AnimationUtility.SetEditorCurve(clip, bindingOffX, curveOffX);
                    AnimationUtility.SetEditorCurve(clip, bindingOffY, curveOffY);
                    AnimationUtility.SetEditorCurve(clip, bindingSizeX, curveSizeX);
                    AnimationUtility.SetEditorCurve(clip, bindingSizeY, curveSizeY);

                    if (changeEnable)
                    {
                        AnimationUtility.SetEditorCurve(clip, bindingEnable, curveEnable);
                    }

                    EditorUtility.SetDirty(clip);
                }
            }
        }
Пример #4
0
 public void Process(MetaProcessingContext context, Layer layer)
 {
 }
Пример #5
0
        public void Process(MetaProcessingContext ctx, Layer layer)
        {
            var file = ctx.ImportContext.AseFile;

            var eventFrames = ComputeEventFrameSet(layer, file);

            var paramType = layer.GetParamType(1);

            Debug.Log("Processing event " + layer.GetParamString(0));

            foreach (var frametag in file.FrameTags)
            {
                AnimationClip clip;
                if (!ctx.TryGetClip(frametag, out clip))
                {
                    continue;
                }

                var events = new List <EventCarrier>();
                foreach (var existingEvents in clip.events)
                {
                    events.Add(new EventCarrier(existingEvents, events.Count));
                }

                var time = 0.0f;
                for (var frameIndex = frametag.From; frameIndex <= frametag.To; ++frameIndex)
                {
                    if (eventFrames.Contains(frameIndex))
                    {
                        var evt = new AnimationEvent
                        {
                            time           = time,
                            functionName   = layer.GetParamString(0),
                            messageOptions = SendMessageOptions.DontRequireReceiver
                        };

                        // Debug.Log(paramType + ", " + layer.metaInfo.ParamCount);

                        if (paramType == LayerParamType.String)
                        {
                            evt.stringParameter = layer.GetParamString(1);
                        }
                        else if (paramType == LayerParamType.Number)
                        {
                            var fval = layer.GetParamFloat(1);
                            evt.floatParameter = fval;
                            if (Math.Abs(fval - Math.Floor(fval)) < 0.001f)
                            {
                                evt.intParameter = (int)fval;
                            }
                        }

                        events.Add(new EventCarrier(evt, events.Count));
                    }

                    time += file[frameIndex].Duration / 1000f;
                }

                var eventsArray = events.OrderBy(t => t, new EventCarrierComparer()).Select(t => t.Event).ToArray();
                AnimationUtility.SetAnimationEvents(clip, eventsArray);
                EditorUtility.SetDirty(clip);
            }
        }