示例#1
0
    public static void AddWatch(string outputStr, Action del)
    {
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start(); //  开始监视代码运行时间

        if (del != null)
        {
            del();
        }

        stopwatch.Stop();                      //  停止监视
        TimeSpan timespan = stopwatch.Elapsed; //  获取当前实例测量得出的总时间
        //double seconds = timespan.TotalSeconds;  //  总秒数
        double  millseconds = timespan.TotalMilliseconds;
        decimal seconds     = (decimal)millseconds / 1000m;

        CBase.LogWarning(outputStr, seconds.ToString("F7")); // 7位精度
    }
示例#2
0
    public override void OnInit()
    {
        base.OnInit();

        HomeButton = GetControl <UIButton>("Button"); // child
        CBase.Assert(HomeButton);

        HomeLabel = GetControl <UILabel>("Button/Label"); // uri....
        CBase.Assert(HomeLabel);

        HomeButton = FindControl <UIButton>("Button"); // find by gameobject name
        CBase.Assert(HomeButton);

        HomeLabel = FindControl <UILabel>("Label"); // child name
        CBase.Assert(HomeLabel);

        HomeButton.onClick.Add(new EventDelegate(() => {
            CBase.LogWarning("Click Home Button!");
        }));
    }
示例#3
0
    public static System.Func <string, string> CustomGetResourcesPath;                                              // 自定义资源路径。。。

    public static string GetResourcesPath(string url)
    {
        if (string.IsNullOrEmpty(url))
        {
            CBase.LogError("尝试获取一个空的资源路径!");
        }

        string docUrl;
        bool   hasDocUrl = TryGetDocumentResourceUrl(url, out docUrl);

        string inAppUrl;
        bool   hasInAppUrl = TryGetInAppResourceUrl(url, out inAppUrl);

        if (ResourcePathType == CResourceManagerPathType.PersistentDataPathPriority)  // 優先下載資源模式
        {
            if (hasDocUrl)
            {
                if (Application.isEditor)
                {
                    CBase.LogWarning("使用外部资源 {0}", docUrl);
                }
                return(docUrl);
            }
            else
            {
                return(inAppUrl);  // 優先下載資源,但又沒有下載資源文件!使用本地資源目錄
            }
        }
        else
        {
            if (!hasInAppUrl)
            {
                CBase.LogError("找不到InApp的資源: {0}", url);
            }
            return(inAppUrl);  // 直接使用本地資源!

            // ?? 沒有本地資源但又遠程資源?竟然!!?
        }
    }
示例#4
0
    public static void LoadFromTab(Type type, ref CBaseInfo newT, ICTabReadble tabFile, int row)
    {
        CBase.Assert(typeof(CBaseInfo).IsAssignableFrom(type));

        FieldInfo[] fields = type.GetFields();
        foreach (FieldInfo field in fields)
        {
            if (!tabFile.HasColumn(field.Name))
            {
                CBase.LogError("表{0} 找不到表头{1}", type.Name, field.Name);
                continue;
            }
            object value;
            if (field.FieldType == typeof(int))
            {
                value = tabFile.GetInteger(row, field.Name);
            }
            else if (field.FieldType == typeof(long))
            {
                value = (long)tabFile.GetInteger(row, field.Name);
            }
            else if (field.FieldType == typeof(string))
            {
                value = tabFile.GetString(row, field.Name);
            }
            else if (field.FieldType == typeof(float))
            {
                value = tabFile.GetFloat(row, field.Name);
            }
            else if (field.FieldType == typeof(bool))
            {
                value = tabFile.GetBool(row, field.Name);
            }
            else if (field.FieldType == typeof(double))
            {
                value = tabFile.GetDouble(row, field.Name);
            }
            else if (field.FieldType == typeof(uint))
            {
                value = tabFile.GetUInteger(row, field.Name);
            }
            else if (field.FieldType == typeof(List <string>))
            {
                string sz = tabFile.GetString(row, field.Name);
                value = CTool.Split <string>(sz, '|');
            }
            else if (field.FieldType == typeof(List <int>))
            {
                List <int> retInt = new List <int>();
                string     szArr  = tabFile.GetString(row, field.Name);
                if (!string.IsNullOrEmpty(szArr))
                {
                    string[] szIntArr = szArr.Split('|');
                    foreach (string szInt in szIntArr)
                    {
                        float parseFloat;
                        float.TryParse(szInt, out parseFloat);
                        int parseInt_ = (int)parseFloat;
                        retInt.Add(parseInt_);
                    }
                    value = retInt;
                }
                else
                {
                    value = new List <int>();
                }
            }
            else if (field.FieldType == typeof(List <List <string> >))
            {
                string sz = tabFile.GetString(row, field.Name);
                if (!string.IsNullOrEmpty(sz))
                {
                    var      szOneList = new List <List <string> >();
                    string[] szArr     = sz.Split('|');
                    foreach (string szOne in szArr)
                    {
                        string[] szOneArr = szOne.Split('-');
                        szOneList.Add(new List <string>(szOneArr));
                    }
                    value = szOneList;
                }
                else
                {
                    value = new List <List <string> >();
                }
            }
            else if (field.FieldType == typeof(List <List <int> >))
            {
                string sz = tabFile.GetString(row, field.Name);
                if (!string.IsNullOrEmpty(sz))
                {
                    var      zsOneIntList = new List <List <int> >();
                    string[] szArr        = sz.Split('|');
                    foreach (string szOne in szArr)
                    {
                        List <int> retInts  = new List <int>();
                        string[]   szOneArr = szOne.Split('-');
                        foreach (string szOneInt in szOneArr)
                        {
                            float parseFloat;
                            float.TryParse(szOneInt, out parseFloat);
                            int parseInt_ = (int)parseFloat;
                            retInts.Add(parseInt_);
                        }
                        zsOneIntList.Add(retInts);
                    }
                    value = zsOneIntList;
                }
                else
                {
                    value = new List <List <int> >();
                }
            }
            else
            {
                CBase.LogWarning("未知类型: {0}", field.Name);
                value = null;
            }

            if (field.Name == "Id")  // 如果是Id主键,确保数字成整数!不是浮点数  因为excel转tab可能转成浮点
            {
                float fValue;
                if (float.TryParse((string)value, out fValue))
                {
                    try
                    {
                        value = ((int)fValue).ToString();
                    }
                    catch
                    {
                        CBase.LogError("转型错误...{0}", value.ToString());
                    }
                }
            }

            field.SetValue(newT, value);
        }
    }