コード例 #1
0
ファイル: Reporter.cs プロジェクト: reaganq/MagnetBots_unity
	void AddLog( string condition, string stacktrace, LogType type )
	{
		float memUsage = 0f ;
		string _condition = "";
		if( cachedString.ContainsKey( condition ) )
		{
			_condition = cachedString[ condition ];
		}
		else 
		{
			_condition = condition ;
			cachedString.Add( _condition , _condition );
			memUsage += (string.IsNullOrEmpty(_condition)?0:_condition.Length*sizeof(char));
			memUsage += System.IntPtr.Size ;
		}
		string _stacktrace = "";
		if( cachedString.ContainsKey( stacktrace ) )
		{
			_stacktrace = cachedString[ stacktrace ];
		}
		else 
		{
			_stacktrace = stacktrace ;
			cachedString.Add( _stacktrace , _stacktrace );
			memUsage += (string.IsNullOrEmpty(_stacktrace)?0:_stacktrace.Length*sizeof(char));
			memUsage += System.IntPtr.Size ;
		}
		bool newLogAdded = false ;
		
		addSample();
		Log log = new Log(){ logType = (_LogType)type , condition = _condition  , stacktrace = _stacktrace , sampleId = samples.Count -1  };
		memUsage += log.GetMemoryUsage() ;
		//memUsage += samples.Count * 13 ;
		
		logsMemUsage += memUsage/1024/1024;
		
		if( TotalMemUsage > maxSize )
		{
			clear();
			Debug.Log( "Memory Usage Reach" + maxSize +" mb So It is Cleared");
			return;
		}
		
		bool isNew = false ;
		//string key = _condition;// + "_!_" + _stacktrace ;
		if( logsDic.ContainsKey( _condition ,stacktrace) )
		{
			isNew = false ;
			logsDic[ _condition ][stacktrace].count ++;
		}
		else 
		{
			isNew = true ;
			collapsedLogs.Add( log );
			logsDic[_condition][stacktrace] = log ;
			
			if( type == LogType.Log )
				numOfCollapsedLogs++;
			else if( type == LogType.Warning )
				numOfCollapsedLogsWarning++;
			else 
				numOfCollapsedLogsError++;
		}
		
		if( type == LogType.Log )
			numOfLogs++;
		else if( type == LogType.Warning )
			numOfLogsWarning++;
		else 
			numOfLogsError++;
		
		
		logs.Add( log );
		if( !collapse || isNew )
		{
			bool skip = false ;
			if( log.logType == _LogType.Log && !showLog )
				skip = true;
			if( log.logType == _LogType.Warning && !showWarning )
				skip = true;
			if( log.logType == _LogType.Error && !showError )
				skip = true;
			if( log.logType == _LogType.Assert && !showError )
				skip = true;
			if( log.logType == _LogType.Exception && !showError )
				skip = true;
			
			if( !skip)
			{
				if( string.IsNullOrEmpty(filterText ) || log.condition.ToLower().Contains( filterText.ToLower() ))
				{
					currentLog.Add( log );
					newLogAdded=true;
				}
			}
		}
		
		if( newLogAdded )
		{
			calculateStartIndex();
			int totalCount = currentLog.Count;
			int totalVisibleCount = (int)(Screen.height * 0.75f / size.y) ;
			if( startIndex >= ( totalCount - totalVisibleCount ))
				scrollPosition.y += size.y ;
		}
		
		try
		{
			gameObject.SendMessage( "OnLog" ,log );
		}
		catch( System.Exception e )
		{
			Debug.LogException( e );
		}
	}