static object PerformMemberwiseClone(ref object o) { var ins = new UnityEngine.Resolution(); ins = (UnityEngine.Resolution)o; return(ins); }
/// <summary> /// Gets the specified scene name with a resolution appended, /// which best fits the specified game resolution. /// </summary> /// <returns>Scene name string with the best resolution appended.</returns> /// <param name="sceneName">Scene name.</param> /// <param name="gameResolution">Game resolution.</param> /// <param name="mode">Desired scene scale mode.</param> public string GetBest(string sceneName, UnityEngine.Resolution gameResolution, SceneMode mode) { if (!this.scenesWithResolutions.ContainsKey(sceneName)) { return(sceneName); } var comparer = this.GetComparer(mode); if (comparer != null) { comparer.GameResolution = gameResolution; this.availableResolutions.Sort(comparer); } var resolution = this.availableResolutions.FirstOrDefault(item => { return(this.scenesWithResolutions[sceneName].Contains(item)); }); if (resolution == null) { return(sceneName); } return(string.Format("{0}{1}", sceneName, resolution.ToExtension())); }
/// <summary> /// Gets the aspect ratio factor of the specified <see cref="UnityEngine.Resolution"/>. /// </summary> /// <returns>The aspect ratio factor of the specified <see cref="UnityEngine.Resolution"/>.</returns> /// <param name="resolution"><see cref="UnityEngine.Resolution"/> to compute aspect ratio for.</param> public static float GetAspectRatioFactor(this UnityEngine.Resolution resolution) { if (resolution.width <= 0 || resolution.height <= 0) { return(0f); } var width = (float)resolution.width; var height = (float)resolution.height; return((width > height) ? (width / height) : (height / width)); }
/// <summary> /// Sets the specified width and height to the <see cref="UnityEngine.Resolution"/>. /// If at least one of the specified values <c><= 0</c>, /// than both the width and height of the resolution are set to <c>0</c>. /// Otherwise, the specified values are used. /// </summary> /// <returns><see cref="UnityEngine.Resolution"/> with new width and height.</returns> /// <param name="resolution"><see cref="UnityEngine.Resolution"/> to set width and height.</param> /// <param name="width">Resolution width.</param> /// <param name="height">Resolution height.</param> public static UnityEngine.Resolution Set(this UnityEngine.Resolution resolution, int width, int height) { if (width > 0 && height > 0) { resolution.width = width; resolution.height = height; } else { resolution.width = 0; resolution.height = 0; } return(resolution); }
static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.Resolution instance_of_this_method) { ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.Object: { __mStack[ptr_of_this_method->Value] = instance_of_this_method; } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { var t = __domain.GetType(___obj.GetType()) as CLRType; t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method); } } break; case ObjectTypes.StaticFieldReference: { var t = __domain.GetType(ptr_of_this_method->Value); if (t is ILType) { ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.Resolution[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method; } break; } }
static StackObject *ToString_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.Resolution instance_of_this_method = (UnityEngine.Resolution) typeof(UnityEngine.Resolution).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); var result_of_this_method = instance_of_this_method.ToString(); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); __intp.Free(ptr_of_this_method); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
/// <summary> /// Selects a resolution from available for the specified scene and appends it to the scene name. /// The one is chosen, which best fits the specified game resolution. /// </summary> /// <returns>Scene name with resolution.</returns> /// <param name="sceneName">Scene name.</param> /// <param name="gameWidth">Game resolution width.</param> /// <param name="gameHeight">Game resolution height.</param> /// <param name="mode">Desired scene scale mode.</param> public static string PickResolution(this string sceneName, int gameWidth, int gameHeight, SceneMode mode) { if (sceneName == null) { return(null); } if (AvailableResolutions == null) { SceneResolutionPicker.LoadAvailableResolutions(); } var gameResolution = new UnityEngine.Resolution().Set(gameWidth, gameHeight); var best = AvailableResolutions.GetBest(sceneName, gameResolution, mode); Log.Info(string.Format("Sorted available resolutions for game resolution {0}x{1} (the first is the best):\n{2}", gameResolution.width, gameResolution.height, AvailableResolutions.ResolutionsListToString())); Log.Info(string.Format("Best available scene is: '{0}'.", best)); return(best); }
static StackObject *set_refreshRate_5(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @value = ptr_of_this_method->Value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.Resolution instance_of_this_method = (UnityEngine.Resolution) typeof(UnityEngine.Resolution).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); instance_of_this_method.refreshRate = value; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); __intp.Free(ptr_of_this_method); return(__ret); }
public static Resolution ToUniject(this UnityEngine.Resolution r) { return(new Resolution(r.width, r.height, r.refreshRate)); }
/// <summary> /// Checks the resolutions A and B for being equal and checks them for equality against the game resolution. /// If at least one of resolutions A and B is <c>null</c>, they are treated as equal. If A is equal /// to B, they are (surprise!) equal. If A is equal to game resolution, and B isn't, A is "bigger". /// If B is equal to game resolution, and A isn't, B is "bigger". If nothing of the above is correct, /// further comparison is necessary. /// </summary> /// <returns><c>true</c>, if the comparison is finished, and /// <c>false</c>, if further comparison is necessary.</returns> /// <param name="result">The result of the comparison: 0 if resolutions are equal or if /// the further comparison is necessary, -1 if A is "bigger", 1 if B is "bigger".</param> /// <param name="resolutionA">First resolution to compare.</param> /// <param name="resolutionB">Second resolution to compare.</param> /// <param name="gameResolution">Game resolution.</param> public bool Compare(out int result, Resolution resolutionA, Resolution resolutionB, UnityEngine.Resolution gameResolution) { result = 0; if (resolutionA == null || resolutionB == null) { return(true); } if (resolutionA.Equals(resolutionB)) { return(true); } if (resolutionA.Width == gameResolution.width && resolutionA.Height == gameResolution.height) { result = -1; return(true); } if (resolutionB.Width == gameResolution.width && resolutionB.Height == gameResolution.height) { result = 1; return(true); } return(false); }
/// <summary> /// Compares specified resolutions A and B to <c>null</c>. /// If both A and B are <c>null</c>, they are equal. If A is not /// <c>null</c> and B is <c>null</c>, A is "bigger". If B is /// not <c>null</c> and A is <c>null</c>, B is "bigger". If /// they both aren't <c>null</c>, further comparison is necessary. /// </summary> /// <returns><c>true</c>, if the comparison is finished, and /// <c>false</c>, if further comparison is necessary.</returns> /// <param name="result">The result of the comparison: 0 if resolutions are equal or if /// the further comparison is necessary, -1 if A is "bigger", 1 if B is "bigger".</param> /// <param name="resolutionA">First resolution to compare.</param> /// <param name="resolutionB">Second resolution to compare.</param> /// <param name="gameResolution">Game resolution.</param> public bool Compare(out int result, Resolution resolutionA, Resolution resolutionB, UnityEngine.Resolution gameResolution) { result = 0; if (resolutionA == null && resolutionB == null) { return(true); } if (resolutionB == null) { result = -1; return(true); } if (resolutionA == null) { result = 1; return(true); } return(false); }
public Resolution(UnityEngine.Resolution other) { this.Width = other.width; this.Height = other.height; }
/// <summary> /// Compares the aspect ratios of specified resolutions A and B and checks them against the /// aspect ratio of game resolution. If at least one of resolutions A and B is <c>null</c>, /// they are treated as equal. If the aspect ratio factors of A and B are nearly equal, /// further comparison is necessary. If aspect ratio factor of A is nearly equal to the /// aspect ratio factor of game resolution, A is "bigger"; and, if aspect ratio factor /// of B is nearly equal to the aspect ratio factor of game resolution, B is "bigger". /// If aspect ratio factor's of A and B both are greater or both are lower than the /// aspect ratio factor of game resolution, the resolution with aspect ratio factor, which is /// closer to the aspect ratio factor of game resolution, is "bigger". If resolution /// A, B and game resolution all have portrait orientation, the resolution with greater /// aspect ratio factor is "bigger". If game resolution is landscape, and both A and B are /// portrait, the resolution with smaller aspect ratio is "bigger". If game resolution is /// portrait and both A and B are landscape, the resolution with smaller aspect ratio is /// "bigger". If resolution A, B and game resolution all are landscape, the resolution with /// smaller aspect ratio is "bigger". Otherwise, further comparison is necessary. Note, /// that aspect ratios of landscape and portrait resolutions of same sizes (in opposite /// dimensions, of course) are treated as equal. /// </summary> /// <returns><c>true</c>, if the comparison is finished, and /// <c>false</c>, if further comparison is necessary.</returns> /// <param name="result">The result of the comparison: 0 if resolutions are equal or if /// the further comparison is necessary, -1 if A is "bigger", 1 if B is "bigger".</param> /// <param name="resolutionA">First resolution to compare.</param> /// <param name="resolutionB">Second resolution to compare.</param> /// <param name="gameResolution">Game resolution.</param> public bool Compare(out int result, Resolution resolutionA, Resolution resolutionB, UnityEngine.Resolution gameResolution) { result = 0; if (resolutionA == null || resolutionB == null) { return(true); } var aspectA = resolutionA.GetAspectRatioFactor(); var aspectB = resolutionB.GetAspectRatioFactor(); var gameAspect = gameResolution.GetAspectRatioFactor(); if (aspectA.NearlyEquals(aspectB, FloatHelper.EpsilonForComparisonOfAspectRatioFactors)) { return(false); } if (aspectA.NearlyEquals(gameAspect, FloatHelper.EpsilonForComparisonOfAspectRatioFactors)) { result = -1; return(true); } if (aspectB.NearlyEquals(gameAspect, FloatHelper.EpsilonForComparisonOfAspectRatioFactors)) { result = 1; return(true); } if ((aspectB <= aspectA && aspectA <= gameAspect) || (aspectB >= aspectA && aspectA >= gameAspect)) { result = -1; return(true); } if ((aspectA <= aspectB && aspectB <= gameAspect) || (aspectA >= aspectB && aspectB >= gameAspect)) { result = 1; return(true); } bool bothAAndBArePortrait = resolutionA.IsPortrait() && resolutionB.IsPortrait(); bool needGreaterAspect = gameResolution.IsPortrait() && bothAAndBArePortrait; if (needGreaterAspect) { result = (aspectA >= aspectB) ? -1 : 1; return(true); } bool bothAAndBAreLandscape = resolutionA.IsLandscape() && resolutionB.IsLandscape(); bool needSmallerAspect = (gameResolution.IsLandscape() && bothAAndBAreLandscape) || (gameResolution.IsLandscape() && bothAAndBArePortrait) || (gameResolution.IsPortrait() && bothAAndBAreLandscape); if (needSmallerAspect) { result = (aspectA <= aspectB) ? -1 : 1; return(true); } return(false); }
/// <summary> /// Determines whether the specified <see cref="UnityEngine.Resolution"/> has landscape orientation. /// </summary> /// <returns><c>true</c> if the specified <see cref="UnityEngine.Resolution"/> /// has landscape orientation; otherwise, <c>false</c>.</returns> /// <param name="resolution"><see cref="UnityEngine.Resolution"/> to check the orientation.</param> public static bool IsLandscape(this UnityEngine.Resolution resolution) { return((resolution.width <= 0 || resolution.height <= 0) || (resolution.width >= resolution.height)); }
/// <summary> /// Compares orientations of resolutions A and B against orientation of the game resolution. /// If at least one of resolutions A and B is <c>null</c>, they are treated as equal. /// If game resolution has landscape orientation, A has landscape orientation and B has /// portrait orientation - A is "bigger". If game resolution has portrait orientation, /// A has portrait orientation and B has landscape orientation - A is "bigger". If game /// resolution has landscape orientation, B has landscape orientation and A has portrait /// orientation - B is "bigger". If game resolution has portrait orientation, B has portrait /// orientation and A has landscape orientation - B is "bigger". Otherwise, further comparison /// is necessary. /// </summary> /// <returns><c>true</c>, if the comparison is finished, and /// <c>false</c>, if further comparison is necessary.</returns> /// <param name="result">The result of the comparison: 0 if resolutions are equal or if /// the further comparison is necessary, -1 if A is "bigger", 1 if B is "bigger".</param> /// <param name="resolutionA">First resolution to compare.</param> /// <param name="resolutionB">Second resolution to compare.</param> /// <param name="gameResolution">Game resolution.</param> public bool Compare(out int result, Resolution resolutionA, Resolution resolutionB, UnityEngine.Resolution gameResolution) { result = 0; if (resolutionA == null || resolutionB == null) { return(true); } if ((!gameResolution.IsPortrait() && resolutionA.IsLandscape() && !resolutionB.IsLandscape()) || (!gameResolution.IsLandscape() && resolutionA.IsPortrait() && !resolutionB.IsPortrait())) { result = -1; return(true); } if ((!gameResolution.IsPortrait() && !resolutionA.IsLandscape() && resolutionB.IsLandscape()) || (!gameResolution.IsLandscape() && !resolutionA.IsPortrait() && resolutionB.IsPortrait())) { result = 1; return(true); } return(false); }
/// <summary> /// Compares the sizes of resolutions A and B and checks them against the size of game resolution. /// If at least one of resolutions A and B is <c>null</c>, they are treated as equal. If the results /// of sizes comparison in two single dimensions are equal, this value is chosen as the comparison /// result. If game resolution has landscape orientation or is square and the widths comparison /// result is equality, the resolution with smaller height is "bigger". If game resolution has /// landscape orientation or is square and the width comparison result isn't equality, the resolution /// with smaller width is "bigger". If game resolution has portrait orientation and the heights /// comparison result is equality, the resolution with smaller width is "bigger". If game resolution /// has portrait orientation and the heights comparison result isn't equality, the resolution with /// smaller height is "bigger". This <see cref="EasyResolutions.IResolutionComparisonComponent"/> /// is final, no further comparison necessary. /// </summary> /// <returns>Always <c>true</c>, which means, that the comparison is finished.</returns> /// <param name="result">The result of the comparison: 0 if resolutions are /// equal, -1 if A is "bigger", 1 if B is "bigger".</param> /// <param name="resolutionA">First resolution to compare.</param> /// <param name="resolutionB">Second resolution to compare.</param> /// <param name="gameResolution">Game resolution.</param> public bool Compare(out int result, Resolution resolutionA, Resolution resolutionB, UnityEngine.Resolution gameResolution) { result = 0; if (resolutionA == null || resolutionB == null) { return(true); } if (this.WidthComparer == null || this.HeightComparer == null) { return(true); } var widthResult = this.WidthComparer.Compare(resolutionA.Width, resolutionB.Width, gameResolution.width); var heightResult = this.HeightComparer.Compare(resolutionA.Height, resolutionB.Height, gameResolution.height); if (widthResult == heightResult) { result = widthResult; return(true); } if (gameResolution.IsLandscape()) { if (widthResult == 0) { result = (resolutionA.Height <= resolutionB.Height) ? -1 : 1; } else { result = (resolutionA.Width <= resolutionB.Width) ? -1 : 1; } } else { if (heightResult == 0) { result = (resolutionA.Width <= resolutionB.Width) ? -1 : 1; } else { result = (resolutionA.Height <= resolutionB.Height) ? -1 : 1; } } return(true); }
/// <summary> /// Determines whether the specified <see cref="UnityEngine.Resolution"/> has portrait orientation. /// </summary> /// <returns><c>true</c> if the specified <see cref="UnityEngine.Resolution"/> /// has portrait orientation; otherwise, <c>false</c>.</returns> /// <param name="resolution"><see cref="UnityEngine.Resolution"/> to check the orientation.</param> public static bool IsPortrait(this UnityEngine.Resolution resolution) { return((resolution.width <= 0 || resolution.height <= 0) || (resolution.width <= resolution.height)); }