Exemplo n.º 1
0
    // Called to apply all the curves to the clips.
    void Apply()
    {
        // Create a list with all the curves to be created.
        List <ClipAnimationInfoCurve> newCurves = new List <ClipAnimationInfoCurve>();

        for (int k = 0; k < clipCurves.Count; k++)
        {
            ClipAnimationInfoCurve newCurve = new ClipAnimationInfoCurve
            {
                name  = clipCurves.ElementAt(k).Key,
                curve = clipCurves.ElementAt(k).Value
            };
            newCurves.Add(newCurve);
        }

        // Go through all the fbx's clips and apply the curves to the clips that need them.
        for (int i = 0; i < fbxClips.Count; i++)
        {
            if (fbxClips[i].importer == null)
            {
                continue;
            }

            fbxClips[i].Apply(newCurves.ToArray());
            AssetDatabase.ImportAsset(fbxClips[i].path, ImportAssetOptions.ForceUpdate);
        }

        // Reset the window afterwards.
        Clear();
    }
Exemplo n.º 2
0
    void ParseAnimFile(string sAnimList, ref ArrayList List, ref ArrayList CurveKeys, int firstFrame, int lastFrame)
    {
        //Regex regexString = new Regex(" *(?<firstFrame>[0-9]+) *- *(?<lastFrame>[0-9]+) *(?<loop>(loop|noloop| )) *(?<name>[^\r^\n]*[^\r^\n^ ])",
        //Regex regexString = new Regex(" *(?<loop>(loop|noloop| )) *(?<eventFrame>[0-9]+|-) *(?<name>[^\r^\n]*[^\r^\n^ ]|-)",
        Regex regexString = new Regex(" *(?<name>\\w+) +(?<eventFrame>[0-9]+)? ?(?<value>[0-9]+)? ?(?<parameter>[A-z]*)",
                                      RegexOptions.Compiled | RegexOptions.ExplicitCapture);
        Match           match   = regexString.Match(sAnimList, 0);
        MatchCollection matches = regexString.Matches(sAnimList);

        Debug.Log(match.Groups);
        bool curve;

        foreach (Match item in matches)
        {
            AnimationEvent         aEvent = new AnimationEvent();
            Keyframe               key    = new Keyframe();
            ClipAnimationInfoCurve aCurve = new ClipAnimationInfoCurve();
            aCurve.curve = new AnimationCurve();
            aCurve.curve.AddKey(new Keyframe());
            curve = false;

            if (item.Groups["name"].Success)
            {
                string s = item.Groups["name"].Value.ToString();
                if (s == "loop")
                {
                    loop = true;
                    break;
                }
                else if (s == "curve")
                {
                    curve = true;
                }
                else
                {
                    aEvent.functionName = s;
                }
            }

            if (item.Groups["eventFrame"].Success)
            {
                string s = item.Groups["eventFrame"].Value.ToString();
                if (s == "-")
                {
                    return;
                }
                else if (curve)
                {
                    int EventFrame = ((System.Convert.ToInt32(s) - firstFrame));
                    int clipLength = lastFrame - firstFrame;
                    key.time = (float)EventFrame / clipLength;
                }
                else
                {
                    int EventFrame = ((System.Convert.ToInt32(s) - firstFrame));
                    int clipLength = lastFrame - firstFrame;
                    aEvent.time = (float)EventFrame / clipLength;
                    Debug.Log(aEvent.time);
                }
            }
            if (item.Groups["value"].Success)
            {
                string s = item.Groups["value"].Value.ToString();
                if (s == "-")
                {
                    return;
                }
                else
                {
                    key.value = ((float)(System.Convert.ToInt32(s)) / 100f);
                }
            }

            if (item.Groups["parameter"].Success)
            {
                string s = item.Groups["parameter"].Value.ToString();
                if (s == "-")
                {
                    return;
                }
                else
                {
                    CurveName = s;
                }
            }

            if (aEvent.functionName != "")
            {
                List.Add(aEvent);
            }
            if (curve)
            {
                CurveKeys.Add(key);
            }
            Debug.Log(key);
        }

        //while (match.Success)
        //{
        //    ModelImporterClipAnimation clip = new ModelImporterClipAnimation();

        //    if (match.Groups["firstFrame"].Success)
        //    {
        //        clip.firstFrame = System.Convert.ToInt32(match.Groups["firstFrame"].Value, 10);
        //    }
        //    if (match.Groups["lastFrame"].Success)
        //    {
        //        clip.lastFrame = System.Convert.ToInt32(match.Groups["lastFrame"].Value, 10);
        //    }
        //    if (match.Groups["loop"].Success)
        //    {
        //        clip.loop = match.Groups["loop"].Value == "loop";
        //    }
        //    if (match.Groups["name"].Success)
        //    {
        //        clip.name = match.Groups["name"].Value;
        //    }

        //    List.Add(clip);

        //    match = regexString.Match(sAnimList, match.Index + match.Length);
        //}
    }