public static void Init() { _procotols = new List <Protocol>(); var types = from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.Name.Contains("Protocol") select type; foreach (var t in types) { ConnectTargetEnum connectTarget = ConnectTargetEnum.Game; var connectServerAttr = t.GetCustomAttributes(typeof(ConnectServerAttribute), true) as ConnectServerAttribute[]; if (connectServerAttr.Length != 0) { connectTarget = connectServerAttr[0].ConnectTarget; } var fields = t.GetFields().Where(f => f.FieldType.IsSubclassOf(typeof(Protocol))); foreach (var f in fields) { var dontCheckTokenAttr = f.GetCustomAttributes(typeof(DontCheckTokenAttribute), true); var protocol = f.GetValue(null) as Protocol; if (protocol == null) { protocol = Activator.CreateInstance(f.FieldType) as Protocol; f.SetValue(null, protocol); } protocol.Init( connectTarget, t.Name.Replace("Protocol", "/" + f.Name), dontCheckTokenAttr.Length == 0); _procotols.Add(protocol); } } Debug.Log("protocols has initialized"); }
public ConnectServerAttribute(ConnectTargetEnum server) { ConnectTarget = server; }
public virtual void Init(ConnectTargetEnum connectTarget, string subUrl, bool checkToken) { ConnectTarget = connectTarget; SubUrl = subUrl; CheckToken = checkToken; }