using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Security.Cryptography;
|
using System.Text;
|
|
using UnityEngine;
|
using System.Threading;
|
|
[XLua.LuaCallCSharp]
|
public class Config : Singleton<Config>
|
{
|
|
bool isPlaying = true;
|
|
bool m_Inited = false;
|
public bool inited {
|
get { return m_Inited; }
|
private set { m_Inited = value; }
|
}
|
|
public IEnumerator Co_LoadConfigs()
|
{
|
|
while (!AllCompleted())
|
{
|
var completedCount = 0;
|
for (int i = 0; i < configTasks.Count; i++)
|
{
|
var task = configTasks[i];
|
if (task.state == TaskState.ParseSuccess)
|
{
|
completedCount++;
|
}
|
}
|
|
var allowTaskCount = completedCount <= 8 ? GetMinWorkingTaskCount() : GetMaxWorkingTaskCount();
|
var workingCount = 0;
|
for (int i = 0; i < configTasks.Count; i++)
|
{
|
var task = configTasks[i];
|
if (task.state > TaskState.None && task.state < TaskState.ParseSuccess)
|
{
|
workingCount++;
|
}
|
}
|
|
if (workingCount < allowTaskCount)
|
{
|
var leisureCount = allowTaskCount - workingCount;
|
var startedTasksCount = 0;
|
for (int i = 0; i < configTasks.Count; i++)
|
{
|
var task = configTasks[i];
|
if (task.state == TaskState.None)
|
{
|
StartAsyncTask(task);
|
startedTasksCount++;
|
}
|
|
if (startedTasksCount >= leisureCount)
|
{
|
break;
|
}
|
}
|
}
|
|
yield return null;
|
}
|
|
}
|
|
public void SyncLoadConfigs()
|
{
|
}
|
|
int GetMinWorkingTaskCount()
|
{
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 3.2f * 1024)
|
{
|
return 4;
|
}
|
else if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 2.5f * 1024)
|
{
|
return 2;
|
}
|
else
|
{
|
return 1;
|
}
|
case RuntimePlatform.IPhonePlayer:
|
if (DeviceUtility.cpu > 1 && DeviceUtility.memory > 1.5f * 1024)
|
{
|
return 4;
|
}
|
else
|
{
|
return 1;
|
}
|
case RuntimePlatform.WindowsEditor:
|
return 4;
|
default:
|
return 1;
|
}
|
}
|
|
int GetMaxWorkingTaskCount()
|
{
|
switch (Application.platform)
|
{
|
case RuntimePlatform.Android:
|
if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 3.2f * 1024)
|
{
|
return 20;
|
}
|
else if (DeviceUtility.cpu >= 4 && DeviceUtility.memory > 2.5f * 1024)
|
{
|
return 10;
|
}
|
else if (DeviceUtility.cpu > 1 && DeviceUtility.memory > 1.5f * 1024)
|
{
|
return 4;
|
}
|
else
|
{
|
return 1;
|
}
|
case RuntimePlatform.IPhonePlayer:
|
if (DeviceUtility.cpu > 1 && DeviceUtility.memory > 1.5f * 1024)
|
{
|
return 10;
|
}
|
else
|
{
|
return 1;
|
}
|
case RuntimePlatform.WindowsEditor:
|
return 20;
|
default:
|
return 5;
|
}
|
}
|
|
private void OnApplicationOut()
|
{
|
isPlaying = false;
|
}
|
|
}
|