Exemplo n.º 1
0
    private static void getEvent(string eventPath, ref Dictionary <string, animEventTotal> events)
    {
        Dictionary <int, List <string> > dict = new Dictionary <int, List <string> >();

        getExcelByPath(eventPath, ref dict);
        foreach (var item in dict)
        {
            List <string>  vals     = item.Value;
            animEventTotal allEvent = new animEventTotal();
            addEvent(vals, 1, ref allEvent);
            events.Add(vals[0], allEvent);
        }
    }
Exemplo n.º 2
0
 //递归查找excel里面的帧事件
 private static void addEvent(List <string> vals, int index, ref animEventTotal allEvent)
 {
     if (vals.Count <= index)
     {
         return;
     }
     if (vals[index].StartsWith("play"))
     {
         animEvent e = new animEvent();
         e.clipName  = vals[0];
         e.eventName = vals[index];
         e.frame     = float.Parse(vals[index + 1]);
         e.args      = vals[index + 2];
         allEvent.eventLst.Add(e);
         addEvent(vals, index + 3, ref allEvent);
     }
 }
Exemplo n.º 3
0
    private static void getEvent(string eventPath, ref Dictionary <string, animEventTotal> events)
    {
        Dictionary <int, List <string> > dict = new Dictionary <int, List <string> >();

        getExcelByPath(eventPath, ref dict);
        foreach (var item in dict)
        {
            List <string>  vals     = item.Value;
            animEventTotal allEvent = new animEventTotal();
            addEvent(vals, 1, ref allEvent);
            animEvent enterEvent = new animEvent();
            enterEvent.clipName  = vals[0];
            enterEvent.eventName = "enterState";
            enterEvent.frame     = 0;
            enterEvent.args      = vals[0];
            allEvent.eventLst.Add(enterEvent);
            events.Add(vals[0], allEvent);
        }
    }
Exemplo n.º 4
0
    private static void createCilp(string objPath, string eventPath, List <animClip> clips)
    {
        string path          = objPath + ".FBX";
        var    modelImporter = AssetImporter.GetAtPath(path) as ModelImporter;

        if (modelImporter == null)
        {
            return;
        }

        int    index    = objPath.LastIndexOf("/");
        string savePath = objPath.Remove(index);

        savePath = Path.Combine(savePath, "bin/clip");
        if (Directory.Exists(savePath))
        {
            Directory.Delete(savePath, true);
        }
        if (!Directory.Exists(savePath))
        {
            Directory.CreateDirectory(savePath);
        }

        //帧事件信息
        Dictionary <string, animEventTotal> events = new Dictionary <string, animEventTotal>();

        getEvent(eventPath, ref events);

        modelImporter.animationType      = ModelImporterAnimationType.Generic;
        modelImporter.importAnimation    = true;
        modelImporter.generateAnimations = ModelImporterGenerateAnimations.GenerateAnimations;
        ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[clips.Count];
        for (int i = 0; i < clips.Count; i++)
        {
            ModelImporterClipAnimation tempClip = new ModelImporterClipAnimation();
            tempClip.name       = clips[i].clipName;
            tempClip.firstFrame = clips[i].startIndex;
            tempClip.lastFrame  = clips[i].endIndex;
            tempClip.loopTime   = clips[i].isLoop;
            tempClip.wrapMode   = clips[i].isLoop ? WrapMode.Loop : WrapMode.Default;
            if (events.ContainsKey(tempClip.name))
            {
                animEventTotal   total      = events[tempClip.name];
                AnimationEvent[] clipEvents = new AnimationEvent[total.eventLst.Count];
                for (int k = 0; k < total.eventLst.Count; k++)
                {
                    AnimationEvent ae = new AnimationEvent();
                    ae.functionName    = total.eventLst[k].eventName;
                    ae.stringParameter = total.eventLst[k].args;
                    ae.time            = total.eventLst[k].frame;
                    clipEvents[k]      = ae;
                }
                tempClip.events = clipEvents;
            }
            animations[i] = tempClip;
        }
        modelImporter.clipAnimations = animations;

        UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(path);
        for (int i = 0; i < objs.Length; i++)
        {
            if (objs[i] is AnimationClip && !objs[i].name.StartsWith("_"))
            {
                AnimationClip old     = objs[i] as AnimationClip;
                AnimationClip newClip = new AnimationClip();
                EditorUtility.CopySerialized(old, newClip);
                AssetDatabase.CreateAsset(newClip, Path.Combine(savePath, newClip.name + ".anim"));
            }
        }
        AssetDatabase.ImportAsset(modelImporter.assetPath);
        AssetDatabase.Refresh();
    }