public static void checkAnimatorControllers()
 {
     foreach (var genTemplate in genTemplates)
     {
         characterTemplate = genTemplate;
         foreach (var directory in Directory.GetDirectories(genTemplate.prefix))
         {
             characterName = directory.Substring(characterTemplate.prefix.Length);
             var low  = characterName.ToLower();
             var path = characterTemplate.controllerPath(characterName);
             if (File.Exists(path))
             {
                 checkAnimatorController();
             }
             else if (low.Equals("common"))
             {
                 //ignore
             }
             else
             {
                 EditorLogger.Log("AnimatorController不存在 {0}", path);
             }
         }
     }
 }
Beispiel #2
0
        private static void DoBuild(BuildTarget target)
        {
            var platform   = GetPlatformForAssetBundles(target);
            var outputPath = "AssetBundles/" + platform;

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            Dictionary <string, DateTime> oldFileLastWriteTimes = collectFileLastWriteTimes(outputPath, true);

            var sw = Stopwatch.StartNew();

            EditorLogger.Log("BuildAssetBundles to {0} Start ========================", outputPath);
            var manifest = BuildPipeline.BuildAssetBundles(outputPath,
                                                           BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression |
                                                           BuildAssetBundleOptions.DisableWriteTypeTree,
                                                           target);

            EditorLogger.Log("BuildAssetBundles to {0} Ok, Used {1}", outputPath, sw.Elapsed);

            HashSet <string> neededFiles = collectNeededFiles(manifest, platform);

            CheckFiles(outputPath, neededFiles, oldFileLastWriteTimes);
        }
 private static void printUnusedMotions()
 {
     foreach (var kv in motions)
     {
         if (!usedmotions.Contains(kv.Key))
         {
             EditorLogger.Log("动画文件未使用 {0}", kv.Key);
         }
     }
 }
Beispiel #4
0
        public static void CopyToAssets()
        {
            var platform   = GetPlatformForAssetBundles(EditorUserBuildSettings.activeBuildTarget);
            var outputPath = "AssetBundles/" + platform;
            var sw         = Stopwatch.StartNew();

            EditorLogger.Log("CopyToAssets from {0} Start ========================", outputPath);
            CopyFiles(outputPath, platform, "Assets/StreamingAssets");
            EditorLogger.Log("CopyToAssets from {0} Ok, Used {1}", outputPath, sw.Elapsed);
        }
Beispiel #5
0
        public void OnGUI()
        {
            _clip = EditorGUILayout.ObjectField("Clip", _clip, typeof(AnimationClip), false) as AnimationClip;

            if (_clip != null)
            {
                var bindings = AnimationUtility.GetCurveBindings(_clip);
                EditorGUILayout.LabelField("Curve Count=" + bindings.Length);

                var propertyCount = new Dictionary <string, ClipPropStat>();
                foreach (var binding in bindings)
                {
                    var          curve = AnimationUtility.GetEditorCurve(_clip, binding);
                    ClipPropStat old;

                    if (propertyCount.TryGetValue(binding.propertyName, out old))
                    {
                        old.Count  += 1;
                        old.KeySum += curve.keys.Length;
                    }
                    else
                    {
                        propertyCount[binding.propertyName] = new ClipPropStat()
                        {
                            Count  = 1,
                            KeySum = curve.keys.Length
                        };
                    }
                }

                foreach (var pc in propertyCount)
                {
                    EditorGUILayout.LabelField(pc.Key + " count = " + pc.Value.Count + ", keysum = " + pc.Value.KeySum);
                }

                _filter = EditorGUILayout.TextField("Property Filter", _filter);

                if (GUILayout.Button("Log"))
                {
                    foreach (var binding in bindings)
                    {
                        var curve = AnimationUtility.GetEditorCurve(_clip, binding);
                        if (binding.propertyName.Contains(_filter))
                        {
                            EditorLogger.Log(binding.path + ", " + binding.propertyName + ", Keys: " + curve.keys.Length);
                        }
                    }
                }
            }
        }
        public static void generateAnimatorController()
        {
            AnimatorController originController =
                AssetDatabase.LoadAssetAtPath <AnimatorController>(characterTemplate.templatePath());
            string             controllername = characterTemplate.controllerPath(characterName);
            AnimatorController newController  = AnimatorController.CreateAnimatorControllerAtPath(controllername);

            EditorLogger.Log("----生成开始 {0}", controllername);
            initMotions();
            copyController(originController, newController);
            assignControllerToAnimator(newController);
            printUnusedMotions();
            EditorLogger.Log("----生成完毕 {0}", controllername);
        }
Beispiel #7
0
        private static void Trim(string dir)
        {
            foreach (var animFile in Directory.GetFiles(dir, "*.anim", SearchOption.AllDirectories))
            {
                var           anim = animFile.Replace("\\", "/");
                AnimationClip clip = AssetDatabase.LoadAssetAtPath(anim, typeof(AnimationClip)) as AnimationClip;
                if (clip != null)
                {
                    if (clip.length > 0)
                    {
                        AnimationClip copiedClip = Object.Instantiate(clip);
                        copiedClip.ClearCurves();
                        int trimScale = 0;

                        foreach (var editorCurveBinding in AnimationUtility.GetCurveBindings(clip))
                        {
                            var curve = AnimationUtility.GetEditorCurve(clip, editorCurveBinding);

                            if (editorCurveBinding.propertyName.StartsWith("m_LocalScale"))
                            {
                                trimScale++;
                            }
                            else
                            {
                                copiedClip.SetCurve(editorCurveBinding.path, editorCurveBinding.type,
                                                    editorCurveBinding.propertyName, curve);
                            }
                        }

                        if (trimScale > 0)
                        {
                            EditorLogger.Log("{0} trim scale count ={1}", anim, trimScale);
                            AssetDatabase.CreateAsset(copiedClip, anim);
                        }
                    }
                    else
                    {
                        Debug.LogErrorFormat("animation clip length <= 0: {0} {1}", anim, clip.length);
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Can't load animation clip: {0}", anim);
                }
            }
        }
        public static void checkAnimatorController()
        {
            string             controllername = characterTemplate.controllerPath(characterName);
            AnimatorController controller     = AssetDatabase.LoadAssetAtPath <AnimatorController>(controllername);

            if (controller == null)
            {
                return;
            }


            EditorLogger.Log("----检测开始 {0}", controllername);
            initMotions();
            if (controller.layers.Length > 0)
            {
                foreach (ChildAnimatorState cstate in controller.layers[0].stateMachine.states)
                {
                    var statename = cstate.state.name;
                    if (!containsMotion(statename))
                    {
                        EditorLogger.Log("动画文件不存在 {0}", statename);
                    }
                }

                foreach (AnimatorStateTransition anyTransition in controller.layers[0].stateMachine.anyStateTransitions)
                {
                    var statename = anyTransition.destinationState.name;
                    if (anyTransition.conditions.Length == 1)
                    {
                        var param = anyTransition.conditions[0].parameter;
                        if (param != statename)
                        {
                            EditorLogger.Log("AnyState 到 {0} 的condition {1} 和目的状态名字不一致", statename, param);
                        }
                    }
                    else
                    {
                        EditorLogger.Log("AnyState 到 {0} 不止一个condition", statename);
                    }
                }
            }

            printUnusedMotions();
            EditorLogger.Log("----检测完毕 {0}", controllername);
        }
        private static void assignControllerToAnimator(AnimatorController newController)
        {
            string     prefabPath = string.Format("{0}{1}.prefab", characterTemplate.prefix, characterName);
            GameObject prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);

            if (prefab == null)
            {
                EditorLogger.Log("找不到怪物预制体: {0}", prefabPath);
                return;
            }

            Animator animator = prefab.GetComponent <Animator>();

            if (animator == null)
            {
                EditorLogger.Log("怪物预制体上没有Animator组件: {0}", prefabPath);
                return;
            }
            animator.runtimeAnimatorController = newController;
        }
Beispiel #10
0
        public void MarkAllAndSave(string saveTo)
        {
            AssetDatabase.RemoveUnusedAssetBundleNames();
            notInterestedOldAssets.Clear();
            allMarks.Clear();

            foreach (var bundle in AssetDatabase.GetAllAssetBundleNames())
            {
                foreach (var assetpath in AssetDatabase.GetAssetPathsFromAssetBundle(bundle))
                {
                    var asset = assetpath.Replace("\\", "/");
                    if (notInterestedOldAssets.ContainsKey(asset))
                    {
                        EditorLogger.Log("duplicate {0}", asset);
                    }
                    else
                    {
                        //EditorLogger.Log("old asset = {0}, bundle = {1}", asset, bundle);
                        notInterestedOldAssets.Add(asset, bundle);
                    }
                }
            }

            DoMark();

            foreach (var old in notInterestedOldAssets)
            {
                var importer = AssetImporter.GetAtPath(old.Key);
                importer.assetBundleName = null;
                EditorLogger.Log("unmark asset = {0}, bundle = {1}", old.Key, old.Value);
            }
            using (var sw = new StreamWriter(saveTo, false)) //no bom
            {
                foreach (var kv in allMarks)
                {
                    sw.WriteLine(kv.Key + "," + kv.Value);
                }
            }
        }
Beispiel #11
0
        public static void ExportAnimationTime()
        {
            var anim2Time = new Dictionary <string, float>();

            Collect("Assets/Hero", anim2Time);
            Collect("Assets/Monster", anim2Time);
            Collect("Assets/Npc", anim2Time);
            Collect("Assets/Pet", anim2Time);

            using (var sw = new StreamWriter("../config/animationtime.csv", false, Encoding.GetEncoding("GBK")))
            {
                sw.WriteLine("DO NOT EDIT,clip length in second");
                sw.WriteLine("anim,time");

                foreach (var animtime in anim2Time)
                {
                    sw.WriteLine(animtime.Key.ToLower() + "," + animtime.Value);
                }
            }

            EditorLogger.Log("generated animationtime.csv count={0}", anim2Time.Count);
        }
Beispiel #12
0
        protected void MarkName(string assetPath, string assetBundleName)
        {
            var asset     = assetPath.Replace("\\", "/");
            var bundle    = assetBundleName.Replace("\\", "/").ToLower() + ".bundle";
            var brifasset = asset.Substring(7).ToLower();

            //EditorLogger.Log("asset = {0}, bundle = {1}", brifasset, bundle);
            allMarks[brifasset] = bundle;
            string oldBundle;

            if (notInterestedOldAssets.TryGetValue(asset, out oldBundle))
            {
                notInterestedOldAssets.Remove(asset);
                if (oldBundle.Equals(bundle))
                {
                    return;
                }
            }
            var importer = AssetImporter.GetAtPath(asset);

            EditorLogger.Log("mark asset = {0}, bundle = {1}", asset, bundle);
            importer.assetBundleName = bundle;
        }
Beispiel #13
0
 private static void logMiss(string fn)
 {
     EditorLogger.Log(EditorLogger.AddColor("ERROR MISS FILE " + fn, LoggerColor.red));
 }
Beispiel #14
0
 private static void logModifiy(string fn)
 {
     EditorLogger.Log("MODIFY FILE {0}", fn);
 }
Beispiel #15
0
 private static void logDelDir(string dir)
 {
     EditorLogger.Log(EditorLogger.AddColor("DELETE DIR " + dir, LoggerColor.purple));
 }
Beispiel #16
0
 private static void logDel(string fn)
 {
     EditorLogger.Log(EditorLogger.AddColor("DELETE FILE " + fn, LoggerColor.purple));
 }
        private static void copyController(AnimatorController originController, AnimatorController newController)
        {
            //parameter
            foreach (var parameter in originController.parameters)
            {
                if (parameter.type != AnimatorControllerParameterType.Trigger || containsMotion(parameter.name))
                {
                    newController.AddParameter(parameter.name, parameter.type);
                }
                else
                {
                    EditorLogger.Log("忽略参数 {0}", parameter.name);
                }
            }

            //state
            AnimatorStateMachine newStateMachine    = newController.layers[0].stateMachine;
            AnimatorStateMachine originStateMachine = originController.layers[0].stateMachine;

            newStateMachine.entryPosition    = originStateMachine.entryPosition;
            newStateMachine.anyStatePosition = originStateMachine.anyStatePosition;
            newStateMachine.exitPosition     = originStateMachine.exitPosition;

            foreach (ChildAnimatorState cstate in originStateMachine.states)
            {
                var statename = cstate.state.name;
                if (containsMotion(statename))
                {
                    var newState = newStateMachine.AddState(statename, cstate.position);
                    newState.motion = motions[statename];
                    foreach (StateMachineBehaviour behaviour in cstate.state.behaviours)
                    {
                        newState.AddStateMachineBehaviour(behaviour.GetType());
                    }
                }
                else
                {
                    EditorLogger.Log("忽略状态 {0}", statename);
                }
            }
            newStateMachine.defaultState = findState(originStateMachine.defaultState.name, newStateMachine);


            //transition
            foreach (ChildAnimatorState originChildState in originStateMachine.states)
            {
                AnimatorState newState = findState(originChildState.state.name, newStateMachine);
                if (newState != null)
                {
                    foreach (AnimatorStateTransition originTransition in originChildState.state.transitions)
                    {
                        AnimatorState destState = findState(originTransition.destinationState.name, newStateMachine);
                        if (destState != null)
                        {
                            var newTransition = newState.AddTransition(destState);
                            copyTransition(originTransition, newTransition);
                        }
                    }
                }
            }
            foreach (AnimatorStateTransition anyTransition in originStateMachine.anyStateTransitions)
            {
                AnimatorState destState = findState(anyTransition.destinationState.name, newStateMachine);
                if (destState != null)
                {
                    var newTransition = newStateMachine.AddAnyStateTransition(destState);
                    copyTransition(anyTransition, newTransition);
                }
            }
        }
Beispiel #18
0
 private static void logAdd(string fn)
 {
     EditorLogger.Log(EditorLogger.AddColor("ADD FILE " + fn, LoggerColor.orange));
 }
Beispiel #19
0
    public static void Check()
    {
        string[] names =
        {
            "arise",
            "attack01",
            "attack02",
            "attack03",
            "attack04",
            "backtocity",
            "battlestand",
            "behit",
            "born",
            "dead",
            "die",
            "fear",
            "flydown",
            "flyloop",
            "flyup",
            "gather",
            "idleforchoose",
            "idleforchooseloop",
            "idleshow",
            "qinggong",
            "rideseat",
            "rideskill01",
            "rideskill02",
            "ridestand",
            "run",
            "seated",
            "sitdown",
            "skill01",
            "skill02",
            "skill03",
            "skill04",
            "skill11",
            "skill12",
            "skill13",
            "skill14",
            "skill21",
            "skill22",
            "skill23",
            "skill24",
            "sprint",
            "standup",
            "stun",
            "win",
            "idlestand",
            "chuidizi",
            "idlewing",
            "openwing",
            "closewing"
        };

        var aniFiles = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
        var path     = new string[aniFiles.Length];

        var index = 0;

        foreach (var file in aniFiles)
        {
            path[index] = AssetDatabase.GetAssetPath(file);
            index++;
        }

        foreach (var p in path)
        {
            var i    = p.LastIndexOfAny(new[] { '/' }) + 1;
            var file = p.Substring(i);

            var count = 0;

            var aniNames = Directory.GetFiles(p, "*.anim");

            if (aniNames.Length == 0)
            {
                EditorLogger.Log(file + "  There is no Animation.");
            }

            foreach (var f in aniNames)
            {
                var indexs     = f.LastIndexOfAny(new[] { '\\' }) + 1;
                var motionname = f.Substring(indexs, f.Length - indexs - 5);

                var isHave = false;
                foreach (var a in names)
                {
                    if (motionname.Equals(a))
                    {
                        isHave = true;
                        break;
                    }
                }
                if (isHave == false)
                {
                    EditorLogger.Log("<color=red><b>" + file + "</b></color>" + "  <color=red><b>" + motionname +
                                     "</b></color>" + "  is  wrong.");
                    count++;
                }
            }

            if (count == 0 && aniNames.Length != 0)
            {
                EditorLogger.Log(file + "   <color=green><b>All  Animation's  name  is  right.</b></color>");
            }
            if (count != 0)
            {
                EditorLogger.Log("<color=red><b>" + file + "</b></color>  There  is  <color=red><b>" + count +
                                 "</b></color>  wrong  names.");
            }
        }
    }