using System.Xml; using System.Xml.Linq; //Load string from xml into a list private static void BuildScenes() { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("ios_scenes.xml"); XmlNodeList sceneNode = xmlDocument.SelectNodes("//Scenes/Scene"); foreach(XmlNode node in sceneNode) { string sceneName = node.InnerText; levels.Add(sceneName); } } //Sample Xml <?xml version="1.0" encoding="us-ascii"?> <Scenes> <Scene>Any data </Scene> <Scene>Any data </Scene> <Scene>Any data </Scene> </Scenes>
Simple XML Parsing c#
MethodInfo Reflection to Create a Delegate
MethodInfo actionMethodInfo = typeof(AdvertisementHelper).GetMethod("AdResultCallback", BindingFlags.Static | BindingFlags.NonPublic); Action<bool> AdResultCallback = (Action<bool>)Delegate.CreateDelegate(typeof(Action<bool>), actionMethodInfo);
Find installed Apps on Android and Start the intent
import android.content.pm.ResolveInfo; import android.content.ComponentName; import android.content.pm.ActivityInfo; Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> pkgAppsList = UnityPlayer.currentActivity.getPackageManager().queryIntentActivities( mainIntent, 0); Log.d("Deeplink", String.valueOf(pkgAppsList.size())); for(ResolveInfo info : pkgAppsList) { ActivityInfo activity = info.activityInfo; Log.d("Deeplink", String.valueOf(activity.applicationInfo.packageName)); if(activity.applicationInfo.packageName.contains("your app bundle id")) { ComponentName name = new ComponentName(activity.applicationInfo.packageName,activity.name); Intent i = new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.setComponent(name); UnityPlayer.currentActivity.startActivity(i); Log.d("Deeplink", "Launching Intent"); } }
Retrive data From a CSV using Python and insert into sql
def begin_import(request_type): print '[*] Begin import' csv_file = open(csv_file_name, "rb") table = csv.DictReader(csv_file) try: session = Session() session_row = FlurryAppMetric() for row in table: if request_type == "month": # Ignore time zone as the current table does not support it session_row.date = parse(row["dateTime"]).replace(tzinfo=None) session_row.api_key = row["app|apiKey"] session_row.country = row["country|iso"] session_row.active_users_month = row["activeDevices"] try: session.merge(session_row) session.commit() except SQLAlchemyError as e: print '[*] Failed to merge!' + str(e) except SQLAlchemyError as e: print '[*] SQLAlchemyError thrown: ' + str(e) session.rollback() session.close() finally: session.close() csv_file.close()
Truncate c# string
private static string TruncateString(string value, int maxLength) { if (string.IsNullOrEmpty(value)) { return value; } return value.Length <= maxLength ? value : value.Substring(0, maxLength); }
Collect Unity Console logs - Used for Global exception catcher
Catch all the engine logs and send it to your native console or have a fancy Unity GUI console
Application.logMessageReceived += (output, stackTrace, logType) => {
StringBuilder consoleLogs = new StringBuilder();
consoleLogs.AppendLine("[*] Begin console log information");
consoleLogs.AppendLine("LogMessage:" + output);
consoleLogs.AppendLine("StackTrace:" + stackTrace);
consoleLogs.AppendLine("LogType:" + logType.ToString());
consoleLogs.AppendLine("[*] End console log information");
Utils.SendLogsToConsole("Console Log", consoleLogs.ToString());
};
Resume Orientaion on iOS
NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; for (NSString *orientation in supportedOrientations) { if ([orientation isEqualToString:@"UIInterfaceOrientationPortrait"] || [orientation isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) { NSLog(@"Portrait mode!"); NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; } else if ([orientation isEqualToString:@"UIInterfaceOrientationLandscapeLeft"] || [orientation isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) { NSLog(@"Landscape mode!"); NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; } }
Subscribe to:
Posts (Atom)