Beispiel #1
0
        /// <summary>
        ///  触发事件, 带4个参数触发
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="handler"></param>
        public void Trigger <T, U, V, W>(string eventType, T arg1, U arg2, V arg3, W arg4)
        {
            Delegate d;

            if (!m_theRouter.TryGetValue(eventType, out d))
            {
                return;
            }
            OnTriggerBegin();
            var callbacks = d.GetInvocationList();

            for (int i = 0; i < callbacks.Length; i++)
            {
                if (IsDeleteEvent(callbacks[i]))
                {
                    continue;
                }
                Action <T, U, V, W> callback = callbacks[i] as Action <T, U, V, W>;

                if (callback == null)
                {
                    OnTriggerEnd();
                    throw new Exception(string.Format("TriggerEvent:{0} 参数不匹配 ", eventType));
                }
                try
                {
                    callback(arg1, arg2, arg3, arg4);
                }
                catch (Exception ex)
                {
                    Debuger.LogException(ex);
                }
            }
            OnTriggerEnd();
        }
 public static void CreateDirectory(string path, bool delete = false)
 {
     try
     {
         if (Directory.Exists(path))
         {
             if (delete)
             {
                 Directory.Delete(path, true);
             }
             else
             {
                 return;
             }
         }
         else if (File.Exists(path))
         {
             File.Delete(path);
         }
         Directory.CreateDirectory(path);
     }
     catch (Exception e)
     {
         Debuger.LogException(Author.File, e);
     }
 }
Beispiel #3
0
        public static string OfficialName(string type)
        {
            if (string.IsNullOrEmpty(type))
            {
                return(string.Empty);
            }

            switch (type)
            {
            case "bool":
                return(typeof(bool).Name);

            case "byte":
                return(typeof(byte).Name);

            case "int":
                return(typeof(int).Name);

            case "float":
                return(typeof(float).Name);

            case "double":
                return(typeof(double).Name);

            case "long":
                return(typeof(long).Name);

            case "string":
                return(typeof(string).Name);

            case "DateTime":
                return(typeof(DateTime).Name);

            case "int[]":
                return(string.Format("{0}[]", typeof(int).Name));

            case "float[]":
                return(string.Format("{0}[]", typeof(float).Name));

            case "long[]":
                return(string.Format("{0}[]", typeof(long).Name));

            default:
            {
                try
                {
                    return(Type.GetType(type, true).Name);
                }
                catch (Exception e)
                {
                    Debuger.LogException(Author.Data, e);
                }
            }
            break;
            }
            return(type);
        }
            public static void Write(string path, string content)
            {
                try
                {
                    CreateDirectory(Path.GetDirectoryName(path));

                    File.WriteAllText(path, content);
                }
                catch (Exception e)
                {
                    Debuger.LogException(Author.File, e);
                }
            }
            public static void Write(string path, byte[] buffer)
            {
                try
                {
                    CreateDirectory(Path.GetDirectoryName(path));

                    File.WriteAllBytes(path, buffer);
                }
                catch (Exception e)
                {
                    Debuger.LogException(Author.File, e);
                }
            }
Beispiel #6
0
 public static void Convert(string path, Encoding src, Encoding dst)
 {
     if (!File.Exists(path))
     {
         return;
     }
     try
     {
         File.WriteAllText(path, File.ReadAllText(path, src), dst);
     }
     catch (Exception e)
     {
         Debuger.LogException(Author.Utility, e);
     }
 }
            public static void WriteEncrypt(string path, string content, EncryptType encrypt = EncryptType.AES)
            {
                try
                {
                    byte[] buffer = Encoding.Default.GetBytes(Cryptogram.Decrypt(content, encrypt));

                    CreateDirectory(Path.GetDirectoryName(path));

                    File.WriteAllBytes(path, buffer);
                }
                catch (Exception e)
                {
                    Debuger.LogException(Author.File, e);
                }
            }
Beispiel #8
0
        public static void CreateAsset(DataTable table)
        {
            if (!Enter(table))
            {
                return;
            }

            if (CreateCSharp(table))
            {
                Debug.LogError("Create Scripte! Please Try Again!!!");
                return;
            }
            try
            {
                string script = string.Format("Data{0}", table.TableName);

                string path = string.Format("Assets/Package/Data/{0}.asset", script);

                Assembly assembly = typeof(DataBase).Assembly;

                Type TA = assembly.GetType(string.Format("Data.Data{0}", table.TableName));

                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                ScriptableObject asset = ScriptableObject.CreateInstance(script);

                asset.name = script;

                Type TI = assembly.GetType(string.Format("Data.{0}Information", table.TableName));

                object list = TI.GenerateCollection();

                for (int i = 2; i < row; i++)
                {
                    object target = Activator.CreateInstance(TI);

                    for (int j = 0; j < column; j++)
                    {
                        var field = TI.GetField(table.Rows[0][j].ToString(), BindingFlags.Instance | BindingFlags.Public);

                        object value;

                        switch (table.Rows[1][j].ToString())
                        {
                        case "int[]":
                        {
                            if (!table.Rows[i][j].ToString().TryParseArrayInt(out int[] array_int))
                            {
                            }
                            value = array_int;
                        }
                        break;

                        case "float[]":
                        {
                            if (!table.Rows[i][j].ToString().TryParseArrayFloat(out float[] array_float))
                            {
                            }
                            value = array_float;
                        }
                        break;

                        case "DateTime":
                        {
                            if (!table.Rows[i][j].ToString().TryParseDateTime(out DateTime time))
                            {
                            }
                            value = time;
                        }
                        break;

                        default:
                            value = Convert.ChangeType(table.Rows[i][j], field.FieldType);
                            break;
                        }
                        field.SetValue(target, value);
                    }
                    list.Call("Add", new object[] { target });
                }
                asset.SetMember("list", list);

                AssetDatabase.CreateAsset(asset, path);

                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debuger.LogException(Author.Data, e);
            }
        }