private void ContinueOpenFileiPad(Texture2D texture) { #if UNITY_IPHONE && !UNITY_EDITOR _function.SetBackgroundImage (texture); showLeftMenu = false; if (bgImgMode) { showBgImgMenu = false; } showRightMenu = false; canDisp = false; _mode = PoolDesignerMode.BackgroundScale; _backgroundEdge.GetPrevPoint2 ().Set (UnityEngine.Screen.width / 2 - 50, UnityEngine.Screen.height / 2); _backgroundEdge.GetNextPoint2 ().Set (UnityEngine.Screen.width / 2 + 50, UnityEngine.Screen.height / 2); //#if UNITY_IPHONE && !UNITY_EDITOR SetZoomTextureDimension (); #endif if(System.IO.File.Exists(iPadPath)) { Debug.Log("IMG STILL EXISTS: Deleting ..."); System.IO.File.Delete(iPadPath); } }
IEnumerator ContinueOpenFileWin(string s) { #if UNITY_STANDALONE_OSX s = s.Replace("\\","/"); #else s = s.Replace("/","\\"); #endif s = TextUtils.EncodeToHtml(s); string path = "file://"+s; WWW www = new WWW (path); yield return www; if (www.error != null) { Debug.LogWarning(www.error); yield return true; } else { Texture2D backgroundLoaded = new Texture2D(1,1); www.LoadImageIntoTexture (backgroundLoaded); www.Dispose (); _function.SetBackgroundImage (backgroundLoaded); showLeftMenu = false; if (bgImgMode) { showBgImgMenu = false; } showRightMenu = false; canDisp = false; _mode = PoolDesignerMode.BackgroundScale; _backgroundEdge.GetPrevPoint2 ().Set (UnityEngine.Screen.width / 2 - 50, UnityEngine.Screen.height / 2); _backgroundEdge.GetNextPoint2 ().Set (UnityEngine.Screen.width / 2 + 50, UnityEngine.Screen.height / 2); #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR SetZoomTextureDimension (); #endif yield return true; } }
public void updateGUI(GUIItemV2 itm,int val,bool reset) { switch (itm.getDepth ()) { case 0: if (val == 2) // move plan mode { _mode = PoolDesignerMode.PlanTransformation; bgImgMode = false; } else { if (val == -1 && lastUIValue != 10 && lastUIValue != 0) { selectEditMode = true; } _mode = PoolDesignerMode.PolygonEdition; } if (val == 4) // remove point { int selectedPointIndex = _polyDrawer.GetSelectedPointIndex (); if (selectedPointIndex >= 0) { _polyDrawer.ResetSelection (); _polygon.RemovePoint (selectedPointIndex); if (_polygon.GetPoints ().Count < 3) { _polygon.SetClosed (false); } } RightRoot.resetSelected (); } if (val == 5) // affichage du menu image { bgImgMode = true; showBgImgMenu = true; showRightMenu = false; } else if (val < 7 && (val != -1 || lastUIValue != 10)) { bgImgMode = false; showBgImgMenu = false; bgImgRoot.resetSelected (); } if (val == 7) // chargement de l'image { loadImage (); } if (itm == _showHideBackgroundImage) // afficher/masquer l'image { GUICheckbox ckbx = itm as GUICheckbox; _function.SetBackgroundImageVisible (ckbx.GetValue ()); } if (val == 9) // regler l'echelle de l'image { showLeftMenu = false; if (bgImgMode) { showBgImgMenu = false; } showRightMenu = false; canDisp = false; _mode = PoolDesignerMode.BackgroundScale; } if (val == 10) // translation de l'image { _mode = PoolDesignerMode.BackgroundTranslation; } if (val == 11) // suppression de l'image { Texture2D bgImg = _function.GetBackgroundImage (); if (bgImg != null) { _function.SetBackgroundImage (bgImg); Destroy (bgImg); } } if (val > 6 && val != 10) { bgImgRoot.resetSelected (); } break; case 1: if (itm == _alignedSnapping) // snap { GUICheckbox ckbx = itm as GUICheckbox; _snapper.SetAlignedPointSnapActive (ckbx.GetValue ()); } // if (itm == _angleSnapping) // { // GUICheckbox ckbx = itm as GUICheckbox; // } /*if (val == 2) { _planTransformation.ZoomToPolygon (_polygon); ((GUIItemV2)LeftRoot.getSubItems ()[2]).resetSelected (); }*/ if (itm == _squareCotation) // cotation global { GUICheckbox ckbx = itm as GUICheckbox; _polyDrawer.SetMaxDimensionVisible (ckbx.GetValue ()); val++; } if (itm == _edgeCotation) // cotation par segment { GUICheckbox ckbx = itm as GUICheckbox; _polyDrawer.SetCotationVisible (ckbx.GetValue ()); val++; } bgImgMode = false; showBgImgMenu = false; break; } lastUIValue = val; if(!_isSliding) ui2fcn (); }
protected void ValidateBackground() { float scaleFactor = 100 / _backgroundEdge.GetLength (); float width = UnityEngine.Screen.width * scaleFactor; float height = UnityEngine.Screen.height * scaleFactor; float x = (UnityEngine.Screen.width / 2 - width / 2); float y = (UnityEngine.Screen.height / 2 - height / 2); // on place l'image au milieu de la zone de travail // en fonction de la transformation du plan courante Matrix4x4 m = _planTransformation.GetMatrix ().inverse; Vector2 upRightCorner = m.MultiplyPoint (new Vector2 (x + width, y)); // Vector2 upLeftCorner = m.MultiplyPoint (new Vector2 (x - width, y)); Vector2 bottomLeftCorner = m.MultiplyPoint (new Vector2 (x, y + height)); Vector2 rectPosition = m.MultiplyPoint (new Vector2 (x, y)); float xOffset = (upRightCorner.x - rectPosition.x) / 2; float yOffset = (bottomLeftCorner.y - rectPosition.y) / 2; Rect backgroundRect = new Rect (rectPosition.x + xOffset - width / 2, rectPosition.y + yOffset - height / 2, width, height); _function.SetBackgroundRect (backgroundRect); _function.SetBackgroundImageVisible (true); _showHideBackgroundImage.SetValue (true); _mode = PoolDesignerMode.PolygonEdition; bgImgMode = true; canDisp = true; _planTransformation.ZoomToImage(backgroundRect,_polyDrawer.GetOffSet(),1.0f/scaleFactor); }
//----------------------------------------------------- private void OpenFileAndroid(string path, Texture2D texture) { #if UNITY_ANDROID && !UNITY_EDITOR if(GameObject.Find("MainScene").GetComponent<GUIStart>().enabled == true) return; if( path == null ) { OpenFileAndroidFailed("Path null"); return; } _function.SetBackgroundImage (texture); showLeftMenu = false; if (bgImgMode) { showBgImgMenu = false; } showRightMenu = false; canDisp = false; _mode = PoolDesignerMode.BackgroundScale; _backgroundEdge.GetPrevPoint2 ().Set (UnityEngine.Screen.width / 2 - 50, UnityEngine.Screen.height / 2); _backgroundEdge.GetNextPoint2 ().Set (UnityEngine.Screen.width / 2 + 50, UnityEngine.Screen.height / 2); SetZoomTextureDimension (); #endif }
public void SetCurrentMode(PoolDesignerMode mode) { _mode = mode; }
private void ParamUI() { GUI.BeginGroup(m_paramRect,"","bg"); m_tmpParamRect.y = 0; magnet = GUI.Toggle(m_tmpParamRect,_snapper.IsAlignedPointSnapActivate(),TextManager.GetText(m_paramMenus[0])); if(magnet != _snapper.IsAlignedPointSnapActivate()) { _snapper.SetAlignedPointSnapActive(magnet); _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; } m_tmpParamRect.y += m_btnH; size = GUI.Toggle(m_tmpParamRect,_polyDrawer.IsMaxDimensionVisible(),TextManager.GetText(m_paramMenus[1])); if(size != _polyDrawer.IsMaxDimensionVisible()) { _polyDrawer.SetMaxDimensionVisible(size); _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; } m_tmpParamRect.y += m_btnH; bool tmp = GUI.Toggle(m_tmpParamRect,_polyDrawer.IsGridVisible(),TextManager.GetText(m_paramMenus[2]));//Afficher/cacher if(tmp !=_polyDrawer.IsGridVisible()) { _polyDrawer.SetGridVisible(tmp); _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; } GUI.EndGroup(); }
private void PlanUI() { GUI.BeginGroup(m_planRect,"","bg"); m_tmpPlanRect.y = 0; if(GUI.Button(m_tmpPlanRect,TextManager.GetText(m_planMenus[0]),"bg"))//Charger { loadImage (); m_subMenuSelected = false; } m_tmpPlanRect.y += m_btnH; if(GUI.Button(m_tmpPlanRect,TextManager.GetText(m_planMenus[1]),"bg"))//PLacer { // _mode = PoolDesignerMode.BackgroundTranslation; _mode = PoolDesignerMode.PlanTransformation; m_open = false; m_subMenuSelected = true; } if(!_function.HasBackgroundImage()) { if(m_planRect.height != 2*m_btnH) m_planRect.height = 2*m_btnH; GUI.EndGroup(); return; } else if(m_planRect.height != m_planMenus.Length* m_btnH) { m_planRect.height = m_planMenus.Length* m_btnH; } /*m_tmpPlanRect.y += m_btnH; if(GUI.Button(m_tmpPlanRect,TextManager.GetText(m_planMenus[2]),"bg"))//Echelle { _mode = PoolDesignerMode.BackgroundScale; m_open = false; m_subMenuSelected = false; }*/ m_tmpPlanRect.y += m_btnH; if(GUI.Button(m_tmpPlanRect,TextManager.GetText(m_planMenus[2]),"bg"))//Supprimer { // Texture2D bgImg = _function.GetBackgroundImage (); // if (bgImg != null) // { // _function.SetBackgroundImage (bgImg); // Destroy (bgImg); // } m_confirmedAction = SuppressPlan; m_askMessage = TextManager.GetText(m_planMenus[2])+"?"; m_askConfirmation = true; m_subMenuSelected = false; } m_tmpPlanRect.y += m_btnH; /*bool tmp = GUI.Toggle(m_tmpPlanRect,_function.IsBackgroundImageVisible(),TextManager.GetText(m_planMenus[4]));//Afficher/cacher if(tmp != _function.IsBackgroundImageVisible()) { _function.SetBackgroundImageVisible(tmp); }*/ GUI.EndGroup(); }
void OnGUI() { GUI.depth = -11; GUI.skin = skin; //CONFIRMATION BOX if(m_askConfirmation) { GUI.BeginGroup(m_askRect,"","bg"); GUI.Label(new Rect(0,0,m_askRect.width,m_askRect.height/2f),m_askMessage,"msgbox"); if(GUI.Button(new Rect(m_askRect.width/12f,m_askRect.height*2f/3f,m_askRect.width/3f,m_askRect.height/4f),"OK","btn")) { if(m_confirmedAction!=null) m_confirmedAction(); m_askConfirmation = false; } if(GUI.Button(new Rect(m_askRect.width*7f/12f,m_askRect.height*2f/3f,m_askRect.width/3f,m_askRect.height/4f),"Cancel","btn")) { m_confirmedAction = null; m_askConfirmation = false; } GUI.EndGroup(); return; } //SUBMENUS GUI.BeginGroup(m_mainView); DrawUI(); PlanUI(); ParamUI(); GUI.EndGroup(); //FOOTER SLIDER ARRONDI if(_mode == PoolDesignerMode.PolygonEdition) { selectedPointIndex = _polyDrawer.GetSelectedPointIndex (); GUI.BeginGroup(new Rect(0,Screen.height-m_btnH,Screen.width,m_btnH),"","bg"); if (selectedPointIndex >= 0) { GUI.Label(new Rect(0,0,100,m_btnH),TextManager.GetText("PoolDesigner.RightTitle")+" : "); //TXTFIELD tmpStr = GUI.TextField(new Rect(100,0,m_btnH,m_btnH),tmpStr); GUI.Label(new Rect(130,0,20,m_btnH),"m"); if(tmpStr != sldVal.ToString("F2") && GUI.Button(new Rect(160f,0,m_btnH,m_btnH),"","rfrsh")) { sldVal = float.Parse(tmpStr); sldVal = Mathf.Clamp(sldVal,0,sldMax); tmpStr = sldVal.ToString("F2"); } //SLIDER float tmpVal = GUI.HorizontalSlider(new Rect(200f,0,Screen.width - 400f,m_btnH),sldVal,0,sldMax); if(tmpVal != sldVal) { sldVal = tmpVal; tmpStr = sldVal.ToString("F2"); } //Btn suppression de point if(GUI.Button(new Rect(Screen.width-m_btnW,0,m_btnW,m_btnH),TextManager.GetText("PoolDesigner.RemovePoint"),"suppr")) { m_confirmedAction = DeleteSelectedPoint; m_askMessage = TextManager.GetText("PoolDesigner.RemovePoint")+"?"; m_askConfirmation = true; } } else { #if (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX) GUI.Label(new Rect(0,0,3*m_btnWL,m_btnH),TextManager.GetText("PoolDesigner.Footer")); #else GUI.Label(new Rect(0,0,3*m_btnWL,m_btnH),TextManager.GetText("PoolDesigner.FooterTablette")); #endif } GUI.EndGroup(); } //MENUBAR GUI.BeginGroup(m_headerRect,"","bg"); for(int i=0;i<3;i++) { if(GUI.Button(new Rect(i*m_btnW,0,m_btnW,m_btnH),TextManager.GetText(m_menuTxts[i]),(i==m_selM? m_menuStylesOn[i]:m_menuStylesOff[i]))) { if(m_selM == i) m_open = !m_open; else { m_selM = i; m_open = true; m_subMenuSelected = false; _mode = PoolDesignerMode.None; } } } //--------- if(GUI.Button(new Rect(Screen.width-74-100,0,100,m_btnH),"","quit")) { //Close without save Reset(); Validate(); } if(GUI.Button(new Rect(Screen.width-74,0,74,m_btnH),"","valid")) { // save and close Validate(); } GUI.EndGroup(); if (_mode == PoolDesignerMode.BackgroundScale && _function.GetBackgroundImage () != null) { // dessin de l'image de fond en mode taille max par rapport a l'ecran // pour regler l'echelle Rect backgroundRect = new Rect (0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height); // GUI.DrawTexture (backgroundRect, _function.GetBackgroundImage (), ScaleMode.ScaleToFit); /* Point2 prevPt = _backgroundEdge.GetPrevPoint2 (); Point2 nextPt = _backgroundEdge.GetNextPoint2 (); Vector2 prevPtV = prevPt; Vector2 nextPtV = nextPt; // dessin du segment EdgeDrawer.Draw (_backgroundEdge, Matrix4x4.identity); // dessin des points de reference pour regler l'echelle if (GUI.RepeatButton (new Rect (prevPt.GetX () - 25, prevPt.GetY () - 25, 50, 50), "", "viewfinder")) { _movingBgPoint = prevPt; _movingBgPointOffset = PC.In.GetCursorPosInvY() - prevPtV; } if (GUI.RepeatButton (new Rect (nextPt.GetX () - 25, nextPt.GetY () - 25, 50, 50), "", "viewfinder")) { _movingBgPoint = nextPt; _movingBgPointOffset = PC.In.GetCursorPosInvY() - nextPtV; } float angle = Vector2.Angle (nextPtV - prevPtV, Vector2.right); if (prevPtV.y > nextPtV.y) { angle = -angle; } Matrix4x4 m = GUI.matrix; GUIUtility.RotateAroundPivot (angle, prevPtV); // taille du segment apres transformation matricielle float edgeLength = Vector2.Distance (nextPtV, prevPtV); GUI.Label (new Rect (prevPtV.x + edgeLength / 2 - 20, prevPtV.y - 30, 40, 20), "1m", "dimension label"); GUI.matrix = m;*/ ValidateBackground (); /*if (_movingBgPoint == null) { Rect validateRect = new Rect (0,150,250,50); if (GUI.Button (validateRect, TextManager.GetText("PoolDesigner.ValidateScale"), "validate scale")) { ValidateBackground (); } } #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR else { Vector2 mBgPt = _movingBgPoint; GUI.DrawTexture (new Rect (mBgPt.x - ZOOM_SIZE / 2, mBgPt.y - 80, ZOOM_SIZE, ZOOM_SIZE), _zoomTexture, ScaleMode.StretchToFill); GUI.Box (new Rect (mBgPt.x - ZOOM_SIZE / 2, mBgPt.y - 80, ZOOM_SIZE, ZOOM_SIZE), "", "viewfinder"); } #endif */ } }
private void DrawUI() { GUI.BeginGroup(m_drawRect,"","bg"); m_tmpDrawRect.y = 0; if(GUI.Button(m_tmpDrawRect,TextManager.GetText(m_drawMenus[0]),"bg"))//Editer { _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; } m_tmpDrawRect.y += m_btnH; if(GUI.Button(m_tmpDrawRect,TextManager.GetText(m_drawMenus[1]),"bg"))//Placer { // _mode = PoolDesignerMode.PlanTransformation; _mode = PoolDesignerMode.PolygonMoveAndScale; m_open = false; m_subMenuSelected = true; } m_tmpDrawRect.y += m_btnH; if(GUI.Button(m_tmpDrawRect,TextManager.GetText(m_drawMenus[2]),"bg"))//Nouveau { // Clear(); m_confirmedAction = Clear; m_askMessage = TextManager.GetText(m_drawMenus[2])+"?"; m_askConfirmation = true; m_open = false; m_subMenuSelected = true; _justCloseMenu = true; } m_tmpDrawRect.y += m_btnH; if(GUI.Button(m_tmpDrawRect,TextManager.GetText(m_drawMenus[3]),"bg"))//Reset { // Reset(); m_confirmedAction = Reset; m_askMessage = TextManager.GetText(m_drawMenus[3])+"?"; m_askConfirmation = true; m_open = false; m_subMenuSelected = true; _justCloseMenu = true; } m_tmpDrawRect.y += m_btnH; if(GUI.Button(m_tmpDrawRect,TextManager.GetText(m_drawMenus[4]),"bg"))//Recentrer { Vector2 v2direction = new Vector2(Screen.width* 0.5f, Screen.height * 0.5f) - _polygon.GetPolygonCenter(); float fmagnitude = v2direction.magnitude; v2direction.Normalize(); while(fmagnitude > 10.0f) { _polyDrawer.MovePolygon(v2direction * fmagnitude * 0.5f); v2direction = new Vector2(Screen.width* 0.5f, Screen.height * 0.5f) - _polygon.GetPolygonCenter(); fmagnitude = v2direction.magnitude; v2direction.Normalize(); } _polyDrawer.ChangeSize(); } GUI.EndGroup(); }
protected void Reset() { _polyDrawer.Clear (); _polygon = new Polygon (_function.GetPointsDataBackup ()); _polyDrawer.SetPolygon (_polygon); _snapper.SetPolygon (_polygon); _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; //_planTransformation.ZoomToPolygon (_polygon); }
public void DoActionUI(GameObject gameobject) { // UnityEngine.Camera.mainCamera.enabled = false; GetComponent<GUIMenuConfiguration>().setVisibility(false); GetComponent<GUIMenuInteraction>().setVisibility(false); GetComponent<GUIMenuInteraction>().isConfiguring = false; GetComponent<GUIMenuLeft> ().setVisibility (false); GetComponent<HelpPanel>().enabled = false; _renderCamera.GetComponent<GuiTextureClip>().enabled = false; _renderCamera.GetComponent<ObjInteraction>().setSelected(null,true); _renderCamera.GetComponent<ObjInteraction>().setActived(false); _renderCamera.GetComponent<Mode2D>().enabled = false; //_renderCamera.enabled = false; _function = gameobject.GetComponent<Function_PoolDesigner> (); _polygon = _function.GetPolygon (); _polyDrawer.SetPolygon (_polygon); _snapper.SetPolygon (_polygon); _planCamera.enabled = true; _snapper.enabled = true; _polyDrawer.enabled = true; _planTransformation.enabled = true; canDisp = true; enabled = true; _mode = PoolDesignerMode.PolygonEdition; //m_open = false; //m_subMenuSelected = true; _planTransformation.ZoomToPolygon (_polygon,_polyDrawer.GetOffSet()); //_mode = PoolDesignerMode.PolygonEdition; #if UNITY_IPHONE && !UNITY_EDITOR EtceteraManager.imagePickerChoseImageEvent += OpenFileIpad; EtceteraManager.imagePickerCancelledEvent += OpenFileIpadFailed; #endif #if UNITY_ANDROID && !UNITY_EDITOR EtceteraAndroidManager.albumChooserSucceededEvent += OpenFileAndroid; EtceteraAndroidManager.albumChooserCancelledEvent += OpenFileAndroidFailed; #endif _mode = PoolDesignerMode.PolygonEdition; m_open = false; m_subMenuSelected = true; }
void Update() { //Animation des panneaux if(m_selM == c_drawId && m_open) m_drawRect.y += m_speed; else m_drawRect.y -= m_speed; m_drawRect.y = Mathf.Clamp(m_drawRect.y,-m_drawMenus.Length* m_btnH,0); if(m_selM == c_planId && m_open) m_planRect.y += m_speed; else m_planRect.y -= m_speed; m_planRect.y = Mathf.Clamp(m_planRect.y,-m_planMenus.Length* m_btnH,0); if(m_selM == c_paramId && m_open) m_paramRect.y += m_speed; else m_paramRect.y -= m_speed; m_paramRect.y = Mathf.Clamp(m_paramRect.y,-m_paramMenus.Length* m_btnH,0); //Clic dans le vide pour fermer les menus if(PC.In.Click1Down() && _mode != PoolDesignerMode.BackgroundScale) { if(PC.In.CursorOnUI(m_mainView)) { Rect r1 = m_drawRect; r1.y+=m_btnH; Rect r2 = m_planRect; r2.y+=m_btnH; Rect r3 = m_paramRect; r3.y+=m_btnH; if(!PC.In.CursorOnUIs(r1,r2,r3)) { m_open = false; if(!m_subMenuSelected) { m_selM = -1; _mode = PoolDesignerMode.PolygonEdition; } return; } } } UpdateCurveSliderValue (); // gestion des points de reference permettant la mise à l'echelle // de l'image de fond if (PC.In.Click1Up()) { _movingBgPoint = null; } if (_movingBgPoint != null) { Vector2 newPosition = PC.In.GetCursorPosInvY() - _movingBgPointOffset; _movingBgPoint.Set (newPosition); } // gestion de la translation de l'image de fond if (_mode == PoolDesignerMode.BackgroundTranslation) { if(PC.In.Click1Down()) { prevMousePosition = PC.In.GetCursorPosInvY(); } if(PC.In.Click1Hold()) { float scale = _planTransformation.GetScale ().x; Vector2 mousePosition = PC.In.GetCursorPosInvY(); Vector2 translation = mousePosition - prevMousePosition; Rect backgroundRect = _function.GetBackgroundRect (); backgroundRect.x = backgroundRect.x + translation.x / scale; backgroundRect.y = backgroundRect.y + translation.y / scale; _function.SetBackgroundRect (backgroundRect); prevMousePosition = mousePosition; } } //New déplacement/scale du tracé if(_mode == PoolDesignerMode.PolygonMoveAndScale) { Vector2 deltaMove; float deltaZoom; if(PC.In.Zoom_n_drag1(out deltaZoom,out deltaMove)) { deltaMove.y *=-1; _polyDrawer.MovePolygon(deltaMove); Rect backgroundRect = _function.GetBackgroundRect();//, deltaZoom*10f); if(Mathf.Abs(deltaZoom)>0) { float heightBefore = (backgroundRect.height!=0)?backgroundRect.height:UnityEngine.Screen.height; float widthBefore =(backgroundRect.width!=0)?backgroundRect.width:UnityEngine.Screen.width; float xBefore = backgroundRect.x; float yBefore = backgroundRect.y; float heightAfter = heightBefore * (1+deltaZoom); float widthAfter = widthBefore * (1+deltaZoom); Rect newPlanRect = new Rect( backgroundRect.x + (widthBefore-widthAfter)/2, backgroundRect.y + (heightBefore-heightAfter)/2, widthAfter, heightAfter ); _planTransformation.ZoomToImage(newPlanRect,_polyDrawer.GetOffSet(),(1+deltaZoom), true); heightAfter = heightBefore / (1+deltaZoom); widthAfter = widthBefore / (1+deltaZoom); Rect newBgRect = new Rect( backgroundRect.x + (widthBefore-widthAfter)/2, backgroundRect.y + (heightBefore-heightAfter)/2, widthAfter, heightAfter ); _function.SetBackgroundRect (newBgRect); } } } #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR // copie la texture de fond pour dessiner la zone au dessus du doigt if (_mode == PoolDesignerMode.BackgroundScale && _movingBgPoint != null) { // calcule taille de l'image de fond selon les dimensions de l'ecran Texture2D bgTex = _function.GetBackgroundImage (); float wFactor = (float)bgTex.width / (float)UnityEngine.Screen.width; float hFactor = (float)bgTex.height / (float)UnityEngine.Screen.height; float factor = (float)bgTex.width / (float)bgTex.height; int w; int h; if (wFactor > hFactor) { w = UnityEngine.Screen.width; h = Mathf.RoundToInt ((float)w / factor); } else { h = UnityEngine.Screen.height; w = Mathf.RoundToInt (h * factor); } // decalage entre les dimensions de l'image et celles de l'ecran int wOffset = (UnityEngine.Screen.width - w) / 2; int hOffset = (UnityEngine.Screen.height - h) / 2; // facteur entre l'image reel et redimensionnée float wMult = (float)bgTex.width / (float)w; float hMult = (float)bgTex.height / (float)h; Vector2 movingBgPt = _movingBgPoint; movingBgPt.x = movingBgPt.x - (ZOOM_SIZE / 2) / wMult; movingBgPt.y = UnityEngine.Screen.height - (movingBgPt.y + (ZOOM_SIZE / 2) / hMult); int reelX = (int)((movingBgPt.x - wOffset) * wMult); int reelY = (int)((movingBgPt.y - hOffset) * hMult); // dimension du carre de pixel apres transformation int pW = (int)(ZOOM_SIZE * wMult); int pH = (int)(ZOOM_SIZE * hMult); // position du carre de pixel apres transformation int x = reelX - (pW - ZOOM_SIZE) / 2; int y = reelY - (pH - ZOOM_SIZE) / 2; Color [] cols = new Color [pW * pH]; // copie des pixels for (int row = 0; row < pH; ++row) { for (int col = 0; col < pW; ++col) { int colIndex = col + row * pH; int xI = col + x; int yI = row + y; if (xI < 0 || yI < 0 || yI > bgTex.height || xI > bgTex.width) { cols[colIndex] = OUT_OF_BOUND_COLOR; } else { cols[colIndex] = bgTex.GetPixel (xI, yI); } } } _zoomTexture.SetPixels (cols); _zoomTexture.Apply (); } #endif }