コード例 #1
0
 private void OnEnable()
 {
     result = target as EZScriptStatisticResult;
 }
コード例 #2
0
        public void RefreshResult()
        {
            PathNormalize(statistics.includePaths);
            PathNormalize(statistics.excludePaths);
            EditorUtility.DisplayProgressBar("EZScriptStatistics", "Analysing", 0);
            List <string> scriptFilePaths = new List <string>();

            for (int i = 0; i < statistics.includePaths.Length; i++)
            {
                string includePath = statistics.includePaths[i];
                if (string.IsNullOrEmpty(includePath))
                {
                    continue;
                }
                for (int j = 0; j < statistics.filePatterns.Length; j++)
                {
                    string pattern = statistics.filePatterns[j];
                    if (string.IsNullOrEmpty(pattern))
                    {
                        continue;
                    }
                    try
                    {
                        scriptFilePaths.AddRange(Directory.GetFiles(includePath, pattern, SearchOption.AllDirectories));
                    }
                    catch { }
                }
            }
            PathNormalize(scriptFilePaths);
            List <ScriptInfo> scriptInfoList = new List <ScriptInfo>();

            for (int i = 0; i < scriptFilePaths.Count; i++)
            {
                var scriptInfo = GetScriptInfo(scriptFilePaths[i]);
                if (scriptInfo != null)
                {
                    scriptInfoList.Add(scriptInfo);
                }
            }
            if (scriptInfoList.Count == 0)
            {
                Debug.Log("No script file found");
                return;
            }

            EZScriptStatisticResult result = CreateInstance <EZScriptStatisticResult>();

            result.time = DateTime.Now.ToString("yyyyMMdd-HHmmss");
            result.name = "Result-" + result.time;
            int totalValidLineCount = 0;

            foreach (var contribution in scriptInfoList.GroupBy(info => info.author))
            {
                Contributor contributor = new Contributor(contribution.Key);
                foreach (ScriptInfo info in contribution.Cast <ScriptInfo>())
                {
                    contributor.scriptList.Add(info);
                    contributor.lineCount      += info.lineCount;
                    contributor.validLineCount += info.validLineCount;
                    totalValidLineCount        += info.validLineCount;
                }
                result.contributors.Add(contributor);
            }
            foreach (Contributor contributor in result.contributors)
            {
                contributor.proportion = (float)contributor.validLineCount / totalValidLineCount;
            }
            string assetPath = AssetDatabase.GetAssetPath(target);

            AssetDatabase.AddObjectToAsset(result, target);
            EditorUtility.ClearProgressBar();
            AssetDatabase.SaveAssets();
            Selection.activeObject = result;
        }