public static void ResizeRectTransform(ResolutionPolicy type, RectTransform rect, bool isFullScreen = false) { float scaleX = Screen.width / Config.UI_DESIGN_WIDTH; float scaleY = Screen.height / Config.UI_DESIGN_HEIGHT; float scale = scaleX; if (scaleX > scaleY & isFullScreen == false || scaleX < scaleY && isFullScreen == true) { scale = scaleY; } rect.localScale = new Vector3(scale, scale, scale); if (type == ResolutionPolicy.LeftBottom) { rect.localPosition = new Vector3(-(Screen.width * 0.5f - rect.sizeDelta.x * scale * 0.5f), -(Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f)); } else if (type == ResolutionPolicy.LeftMiddle) { rect.localPosition = new Vector3(-(Screen.width * 0.5f - rect.sizeDelta.x * scale * rect.pivot.x), 0); } else if (type == ResolutionPolicy.LeftTop) { rect.localPosition = new Vector3(-(Screen.width * 0.5f - rect.sizeDelta.x * scale * 0.5f), Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f); } else if (type == ResolutionPolicy.Middle) { rect.localPosition = new Vector3(0, 0); } else if (type == ResolutionPolicy.MiddleBottom) { rect.localPosition = new Vector3(0, -(Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f)); } else if (type == ResolutionPolicy.MiddleTop) { rect.localPosition = new Vector3(0, Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f); } else if (type == ResolutionPolicy.RightBottom) { rect.localPosition = new Vector3(Screen.width * 0.5f - rect.sizeDelta.x * scale * 0.5f, -(Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f)); } else if (type == ResolutionPolicy.RightMiddle) { rect.localPosition = new Vector3(Screen.width * 0.5f - rect.sizeDelta.x * scale * 0.5f, 0); } else if (type == ResolutionPolicy.RightTop) { rect.localPosition = new Vector3(Screen.width * 0.5f - rect.sizeDelta.x * scale * 0.5f, Screen.height * 0.5f - rect.sizeDelta.y * scale * 0.5f); } }
public static void SetDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy) { Debug.Assert(resolutionPolicy != ResolutionPolicy.UnKnown, "should set resolutionPolicy"); if (width == 0.0f || height == 0.0f) { return; } m_obDesignResolutionSize.Width = width; m_obDesignResolutionSize.Height = height; m_fScaleX = m_obScreenSize.Width / m_obDesignResolutionSize.Width; m_fScaleY = m_obScreenSize.Height / m_obDesignResolutionSize.Height; if (resolutionPolicy == ResolutionPolicy.NoBorder) { m_fScaleX = m_fScaleY = Math.Max(m_fScaleX, m_fScaleY); } if (resolutionPolicy == ResolutionPolicy.ShowAll) { m_fScaleX = m_fScaleY = Math.Min(m_fScaleX, m_fScaleY); } // calculate the rect of viewport float viewPortW = m_obDesignResolutionSize.Width * m_fScaleX; float viewPortH = m_obDesignResolutionSize.Height * m_fScaleY; m_obViewPortRect = new CCRect((m_obScreenSize.Width - viewPortW) / 2, (m_obScreenSize.Height - viewPortH) / 2, viewPortW, viewPortH); m_eResolutionPolicy = resolutionPolicy; // reset director's member variables to fit visible rect CCDirector.SharedDirector.m_obWinSizeInPoints = Size; CCDirector.SharedDirector.m_obWinSizeInPixels = new CCSize(m_obDesignResolutionSize.Width * CCMacros.CCContentScaleFactor(), m_obDesignResolutionSize.Height * CCMacros.CCContentScaleFactor()); CCDirector.SharedDirector.CreateStatsLabel(); CCDirector.SharedDirector.SetGlDefaultValues(); }
public static void Init(GraphicsDevice graphicsDevice) { CCDrawManager.graphicsDevice = graphicsDevice; spriteBatch = new SpriteBatch(graphicsDevice); m_defaultEffect = new BasicEffect(graphicsDevice); PrimitiveEffect = new BasicEffect(graphicsDevice) { TextureEnabled = false, VertexColorEnabled = true }; m_DepthEnableStencilState = new DepthStencilState { DepthBufferEnable = true, DepthBufferWriteEnable = true, TwoSidedStencilMode = true }; m_DepthDisableStencilState = new DepthStencilState { DepthBufferEnable = false }; #if !WINDOWS_PHONE && !XBOX && !WINDOWS && !NETFX_CORE && !PSM List <string> extensions = CCUtils.GetGLExtensions(); foreach (string s in extensions) { switch (s) { case "GL_OES_depth24": m_PlatformDepthFormat = DepthFormat.Depth24; break; case "GL_IMG_texture_npot": m_AllowNonPower2Textures = true; break; case "GL_NV_depth_nonlinear": // nVidia Depth 16 non-linear m_PlatformDepthFormat = DepthFormat.Depth16; break; case "GL_NV_texture_npot_2D_mipmap": // nVidia - nPot textures and mipmaps m_AllowNonPower2Textures = true; break; } } #endif PresentationParameters pp = graphicsDevice.PresentationParameters; //pp.RenderTargetUsage = RenderTargetUsage.PreserveContents; //_renderTarget = new RenderTarget2D(graphicsDevice, pp.BackBufferWidth, (int)pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.PreserveContents); m_fScaleY = 1.0f; m_fScaleX = 1.0f; m_eResolutionPolicy = ResolutionPolicy.UnKnown; m_obViewPortRect = new CCRect(0, 0, pp.BackBufferWidth, pp.BackBufferHeight); m_obScreenSize = m_obDesignResolutionSize = m_obViewPortRect.Size; CCDrawingPrimitives.Init(graphicsDevice); }
/// <summary> /// Starts a task which asynchronously opens a snapshot with the given fileName. /// If createIfNotFound is set to true, the specified snapshot will be created if it does not already exist. /// /// Required Scopes: SCOPE_GAMES_LITE and SCOPE_APPFOLDER. /// </summary> /// <param name="fileName"> /// The name of the snapshot file to open. /// Must be between 1 and 100 non-URL-reserved characters (a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "~"). /// </param> /// <param name="createIfNotFound">If true, the snapshot will be created if one cannot be found.</param> /// <param name="conflictPolicy">The conflict resolution policy to use for this snapshot.</param> /// <param name="callback">The task callback</param> public void Open(string fileName, bool createIfNotFound, ResolutionPolicy conflictPolicy, Action <AN_LinkedObjectResult <AN_Snapshot> > callback) { AN_GMS_Lib.Snapshots.Open(this, fileName, createIfNotFound, (int)conflictPolicy, callback); }