Example #1
0
        public GameSettingsViewModel(AssetViewModelConstructionParameters parameters)
            : base(parameters)
        {
            gameSettingsAsset  = (GameSettingsAsset)AssetItem.Asset;
            displayOrientation = gameSettingsAsset.GetOrCreate <RenderingSettings>().DisplayOrientation;

            var platformFiltersNode = AssetRootNode[nameof(GameSettingsAsset.PlatformFilters)].Target;

            platformFiltersNode.ItemChanging += PlatformFiltersNodeChanging;
            platformFiltersNode.ItemChanged  += PlatformFiltersNodeChanged;
        }
Example #2
0
        protected override void OnSessionSaved()
        {
            base.OnSessionSaved();

            var currentOrientation = gameSettingsAsset.GetOrCreate <RenderingSettings>().DisplayOrientation;

            if (displayOrientation != currentOrientation && Session.CurrentProject != null)
            {
                GameSettingsAssetCompiler.SetPlatformOrientation(Session.CurrentProject.Project, currentOrientation);

                displayOrientation = currentOrientation;
            }
        }
Example #3
0
        protected override void OnSessionSaved()
        {
            base.OnSessionSaved();

            //display orientation needs changes in ios / android manifest files
            var currentOrientation = gameSettingsAsset.GetOrCreate <RenderingSettings>().DisplayOrientation;

            if (displayOrientation != currentOrientation && Session.CurrentProject != null)
            {
                GameSettingsAssetCompiler.SetPlatformOrientation(Session.CurrentProject.Project, currentOrientation);

                displayOrientation = currentOrientation;
            }
        }
Example #4
0
        protected override void OnSessionSaved()
        {
            base.OnSessionSaved();

            //display orientation needs changes in ios / android manifest files
            var currentOrientation = gameSettingsAsset.GetOrCreate <RenderingSettings>().DisplayOrientation;

            if (displayOrientation != currentOrientation)
            {
                foreach (var profile in Session.CurrentPackage.Package.Profiles)
                {
                    GameSettingsAssetCompiler.SetPlatformOrientation(Session.CurrentPackage.Package, profile.Platform, currentOrientation);
                }

                displayOrientation = currentOrientation;
            }
        }
Example #5
0
        public static void SetPlatformOrientation(SolutionProject project, RequiredDisplayOrientation orientation)
        {
            switch (project.Platform)
            {
            case PlatformType.Android:
            {
                if (project.FullPath == null)
                {
                    return;
                }

                var activityFileName = project.Name + "Activity.cs";
                var activityFile     = UPath.Combine(project.FullPath.GetFullDirectory(), new UFile(activityFileName));
                if (!File.Exists(activityFile))
                {
                    return;
                }

                var activitySource = File.ReadAllText(activityFile);

                string orientationString;
                switch (orientation)
                {
                case RequiredDisplayOrientation.Default:
                    orientationString = "Android.Content.PM.ScreenOrientation.Landscape";
                    break;

                case RequiredDisplayOrientation.LandscapeLeft:
                    orientationString = "Android.Content.PM.ScreenOrientation.Landscape";
                    break;

                case RequiredDisplayOrientation.LandscapeRight:
                    orientationString = "Android.Content.PM.ScreenOrientation.ReverseLandscape";
                    break;

                case RequiredDisplayOrientation.Portrait:
                    orientationString = "Android.Content.PM.ScreenOrientation.Portrait";
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                activitySource = Regex.Replace(activitySource, @"(\[Activity(?:.*[\n,\r]*)+?[\n,\r,\s]*ScreenOrientation\s*=\s*)([\w,\d,\.]+)(\s*,)", $"$1{orientationString}$3");

                File.WriteAllText(activityFile, activitySource);
            }
            break;

            case PlatformType.iOS:
            {
                var exeProjectLocation = project.FullPath;
                if (exeProjectLocation == null)
                {
                    return;
                }

                var plistFile = UPath.Combine(exeProjectLocation.GetFullDirectory(), new UFile("Info.plist"));
                if (!File.Exists(plistFile))
                {
                    return;
                }

                var xmlDoc             = XDocument.Load(plistFile);
                var orientationKey     = xmlDoc.Descendants("key").FirstOrDefault(x => x.Value == "UISupportedInterfaceOrientations");
                var orientationElement = ((XElement)orientationKey?.NextNode)?.Descendants("string").FirstOrDefault();
                if (orientationElement != null)
                {
                    switch (orientation)
                    {
                    case RequiredDisplayOrientation.Default:
                        orientationElement.Value = "UIInterfaceOrientationLandscapeRight";
                        break;

                    case RequiredDisplayOrientation.LandscapeLeft:
                        orientationElement.Value = "UIInterfaceOrientationLandscapeLeft";
                        break;

                    case RequiredDisplayOrientation.LandscapeRight:
                        orientationElement.Value = "UIInterfaceOrientationLandscapeRight";
                        break;

                    case RequiredDisplayOrientation.Portrait:
                        orientationElement.Value = "UIInterfaceOrientationPortrait";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                xmlDoc.Save(plistFile);
            }
            break;
            }
        }
Example #6
0
 public static void SetPlatformOrientation(SolutionProject project, RequiredDisplayOrientation orientation)
 {
 }