/// <summary> /// Unregister this widget. /// </summary> void OnDestroy() { if (material != null && mScreen != null) { mScreen.RemoveWidget(this); } mScreen = null; }
/// <summary> /// Register this widget with the manager. /// </summary> void Start() { if (mScreen == null && material != null) { mColor = color; mTrans = transform; mPos = mTrans.position; mRot = mTrans.rotation; mScale = mTrans.lossyScale; mDepth = depth; mScreen = SGScreen.GetScreen(mMat = material, mLayer = gameObject.layer, mGroup = group, true); OnStart(); mScreen.AddWidget(this); } }
/// <summary> /// Check to see if anything has changed, and if it has, mark the screen as having changed. /// </summary> public bool ScreenUpdate() { // Call the virtual function bool retVal = OnUpdate(); // If the material or layer has changed, act accordingly if (mMat != material || mGroup != group || mLayer != gameObject.layer || mColor != color) { if (mMat != null) { mScreen.RemoveWidget(this); } mMat = material; mColor = color; mPos = mTrans.position; mRot = mTrans.rotation; mScale = mTrans.lossyScale; mLayer = gameObject.layer; mDepth = depth; mGroup = group; retVal = true; if (mMat != null) { mScreen = SGScreen.GetScreen(mMat, mLayer, mGroup, true); mScreen.AddWidget(this); } } // Check to see if the position, rotation or scale has changed else if (mMat != null) { Vector3 pos = mTrans.position; Quaternion rot = mTrans.rotation; Vector3 scale = mTrans.lossyScale; if (mDepth != depth || mPos != pos || mRot != rot || mScale != scale) { mPos = pos; mRot = rot; mScale = scale; mDepth = depth; retVal = true; } } return(retVal); }
private void Responsive() { float inch = SGScreen.PixelsToInch(Screen.width); bool orientationPortrait = SGScreen.PortraitOrientation(); Transform child; if (forceExpandCards > 0) { if (orientationPortrait) { cellSizeY = (rectTransformParent.rect.height - (gridLayoutGroup.padding.top + gridLayoutGroup.padding.bottom + gridLayoutGroup.spacing.y)) / forceExpandCards; } else { cellSizeY = (rectTransformParent.rect.height - (gridLayoutGroup.padding.top + gridLayoutGroup.padding.bottom + gridLayoutGroup.spacing.y)); } } if (fullScreen) { rectTransform.localPosition = Vector3.zero; // SGDebug.Log("1 coluna, fullscreen"); gridLayoutGroup.cellSize = new Vector2(rectTransformParent.rect.width, rectTransformParent.rect.height); } else if (orientationPortrait) { // SGDebug.Log("1 coluna"); gridLayoutGroup.cellSize = new Vector2(rectTransform.rect.width - (gridLayoutGroup.padding.left + gridLayoutGroup.spacing.x), cellSizeY); } else if (inch > breakPointWidthInch) { // SGDebug.Log("3 coluna, se possível"); gridLayoutGroup.cellSize = new Vector2(rectTransform.rect.width / 3 - (gridLayoutGroup.padding.left + gridLayoutGroup.spacing.x), cellSizeY); } else { // SGDebug.Log("2 coluna, se possível"); gridLayoutGroup.cellSize = new Vector2(rectTransform.rect.width / 2 - (gridLayoutGroup.padding.left + gridLayoutGroup.spacing.x), cellSizeY); } // ajusta a altura do content child = this.transform.GetChild(this.transform.childCount - 1); // ultimo filho rectTransform.sizeDelta = new Vector2(0, child.localPosition.y * -1 + cellSizeY); // seta novo valor }
/// <summary> /// Retrieve a UI screen for the specified material, creating one if necessary. /// </summary> static public SGScreen GetScreen(Material mat, int layer, int group, bool createIfMissing) { // Find an existing entry foreach (SGScreen s in mScreens) { if (s.mMat == mat && s.mGroup == group && s.gameObject.layer == layer) { return(s); } } // No existing entry found -- create a new one if (createIfMissing) { GameObject go = new GameObject("_UIScreen [" + mat.name + "]: " + LayerMask.LayerToName(layer) + " " + group); if (Application.isPlaying) { DontDestroyOnLoad(go); } else { go.hideFlags = HideFlags.DontSave | HideFlags.NotEditable; } // Use the specified layer go.layer = layer; // Add the UI screen script SGScreen screen = go.GetComponent <SGScreen>(); if (screen == null) { screen = go.AddComponent <SGScreen>(); } screen.mMat = mat; screen.mGroup = group; return(screen); } return(null); }