示例#1
0
        public xARMScreenCap[] CreateNavigationBarVersion()
        {
//			xARMScreenCap newScreenCap;
            int     MDPINavigationBarHeight = 48;
            int     navigationBarHeight = Mathf.RoundToInt(MDPINavigationBarHeight * this.DPIFactor);
            Vector2 navBarRes, navBarResToReplace;

            // on smartphones the navigation bar is always at the same spot
            if (this.IsLandscape && this.Diagonal <= 6.5f)
            {
                navBarRes          = new Vector2(this.Resolution.x - navigationBarHeight, this.Resolution.y);
                navBarResToReplace = new Vector2(this.Resolution.x, this.Resolution.y - navigationBarHeight); // incorrect resolution
            }
            else                                                                                              // NavBar is allways at the bottom
            {
                navBarRes          = new Vector2(this.Resolution.x, this.Resolution.y - navigationBarHeight);
                navBarResToReplace = navBarRes;                 // keep all values
            }

            xARMScreenCap newScreenCap = new xARMScreenCap(this.Name, navBarRes,
                                                           this.ResolutionLabel + "~", this.AspectLabel, this.Diagonal, this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning,
                                                           this.StatisticsUsedPercent, this.Description + " (navigation bar version)");

            newScreenCap.IsBaseRes = false;

            xARMScreenCap screenCapToReplace = new xARMScreenCap(this.Name, navBarResToReplace,
                                                                 this.ResolutionLabel + "~", this.AspectLabel, this.Diagonal, this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning,
                                                                 this.StatisticsUsedPercent, this.Description + " (navigation bar version)");

            return(new xARMScreenCap[] { newScreenCap, screenCapToReplace });
        }
示例#2
0
文件: xARMProxy.cs 项目: unit9/swip3
	private IEnumerator WaitXFrames(xARMScreenCap screenCap, int frameCount){
		while (frameCount > 0){
			yield return null; // wait until next frame
			
			frameCount--;
		}
		xARMManager.UpdateScreenCapAtEOF (screenCap);
	}
示例#3
0
        public xARMScreenCap Clone(bool switchResolutionXY = false)
        {
            xARMScreenCap newScreenCap;

            if (switchResolutionXY)
            {
                newScreenCap = new xARMScreenCap(this.Name, new Vector2(this.Resolution.y, this.Resolution.x), this.ResolutionLabel, this.AspectLabel, this.Diagonal,
                                                 this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, this.StatisticsUsedPercent, this.Description);
            }
            else
            {
                newScreenCap = new xARMScreenCap(this.Name, this.Resolution, this.ResolutionLabel, this.AspectLabel, this.Diagonal,
                                                 this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, this.StatisticsUsedPercent, this.Description);
            }

            return(newScreenCap);
        }
示例#4
0
	public static void ChangeActiveScreenCap (int screenCapIndex){
		if(screenCapIndex >= activeScreenCaps.Count) screenCapIndex = 0; // reset if active SC list is shorter now
		xARMManager.Config.PreviewSelectedScreenCapIndex = screenCapIndex;

		// repaint window on next update
		repaintNextUpdate = true;

		if(activeScreenCaps.Count > 0){
			xARMScreenCap previousScreenCap = selectedScreenCap;

			selectedScreenCap = activeScreenCaps[screenCapIndex]; // get Ref to selected SC
			xARMManager.DefaultGameViewResolution = selectedScreenCap.Resolution; // set as new default resolution

			// change GameView resolution if activated and selection was changed
			if(xARMManager.Config.GameViewInheritsPreviewSize && !selectedScreenCap.Equals(previousScreenCap)){
				// switch Game View resolution via next Update() (doesn't work correctly inside OnGUI)
				resizeGameViewToNewDefault = true;
			}
		}
	}
    private static int getScreenCapIndex(xARMScreenCap screenCapToCheck)
    {
        for (int x= 0; x< AvailScreenCaps.Count; x++){
            if(AvailScreenCaps[x] == screenCapToCheck) return x;
        }

        return -1;
    }
 // export ScreenCap as PNG file
 private static void ExportScreenCapToFile(xARMScreenCap screenCap, string path)
 {
     FileStream fs = new FileStream(path, FileMode.Create);
     BinaryWriter bw = new BinaryWriter(fs);
     bw.Write (screenCap.Texture.EncodeToPNG ());
     bw.Close ();
     fs.Close ();
 }
示例#7
0
		public xARMScreenCap Clone(bool switchResolutionXY = false){
			xARMScreenCap newScreenCap;
			
			if(switchResolutionXY){
				newScreenCap = new xARMScreenCap(this.Name, new Vector2(this.Resolution.y, this.Resolution.x), this.ResolutionLabel, this.AspectLabel, this.Diagonal, 
					this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, this.StatisticsUsedPercent, this.Description);
				
			} else{
				newScreenCap = new xARMScreenCap(this.Name, this.Resolution, this.ResolutionLabel, this.AspectLabel, this.Diagonal, 
					this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, this.StatisticsUsedPercent, this.Description);
			}
			
			return newScreenCap;
		}
 // coroutine to wait a few frames between resolution change and SC update
 public void StartWaitXFramesCoroutine(xARMScreenCap screenCap, int frameCount)
 {
     StartCoroutine (WaitXFrames (screenCap, frameCount));
 }
 public static void UpdateScreenCapAtEOF(xARMScreenCap screenCap)
 {
     // capture Render at EndOfFrame
     Proxy.StartUpdateScreenCapCoroutine (screenCap);
     // force EndOfFrame - to execute yield
     GameView.Repaint ();
 }
    public static void UpdateScreenCap(xARMScreenCap screenCap)
    {
        ResizeGameView (screenCap.Resolution);
        // run custom code
        if(OnPreScreenCapUpdate != null) OnPreScreenCapUpdate ();

        xARMManager.ScreenCapUpdateInProgress = true;

        // wait x frames to ensure correct results with other (lazy) plugins
        if(xARMManager.CurrEditorMode == EditorMode.Play){ // don't wait in Play mode
            Proxy.StartWaitXFramesCoroutine (screenCap, 0);

        } else {
            Proxy.StartWaitXFramesCoroutine (screenCap, xARMManager.Config.FramesToWait);
        }
    }
    // save one SC as file
    public static void SaveScreenCapFile(xARMScreenCap screenCap)
    {
        if(screenCap.Texture.width != 4){ // not placeholder
            string defaultFileName = screenCap.Name + " " + screenCap.Diagonal + " " +screenCap.DPILabel + " " + screenCap.Resolution.x + "x" + screenCap.Resolution.y  + ".png";
            // open export to file panel
            string exportFilePath = EditorUtility.SaveFilePanel ("Export ScreenCap as PNG", xARMManager.Config.ExportPath, defaultFileName, "png");

            // export
            if(exportFilePath.Length > 0) ExportScreenCapToFile (screenCap, exportFilePath);

        } else {
            Debug.LogWarning ("xARM: ScreenCap not exported. Please update it before export.");
        }
    }
    public static void ReadScreenCapFromGameView(xARMScreenCap screenCap)
    {
        int width = (int)screenCap.Resolution.x;
        int height = (int)screenCap.Resolution.y;

        // check if the GameView has the correct size
        if(screenCap.Resolution.x == Screen.width && screenCap.Resolution.y == Screen.height){
            // read screen to Tex2D
            Texture2D screenTex = new Texture2D(width, height, TextureFormat.RGB24, false);
            screenTex.ReadPixels (new Rect(0, 0, width, height), 0, 0, false);
            screenTex.Apply (false, false); // readable to enable export as file

            // update ScreenCap
            screenCap.Texture = screenTex;
            screenCap.LastUpdateTime = lastChangeInEditorTime;
            screenCap.LastUpdateTryTime = lastChangeInEditorTime;
            screenCap.UpdatedSuccessful = true;

            // repaint editor windows
            if(myxARMPreviewWindow) myxARMPreviewWindow.Repaint ();
            if(myxARMGalleryWindow) myxARMGalleryWindow.Repaint ();

        } else {
            // mark this ScreenCap as not updated and display message
            screenCap.LastUpdateTryTime = lastChangeInEditorTime;
            screenCap.UpdatedSuccessful = false;
            xARMGalleryWindow.WarningBoxText = "Could not update all ScreenCaps. Switch 'GameView' to 'Free Aspect'.";
            xARMPreviewWindow.WarningBoxText = "Could not update all ScreenCaps. Switch 'GameView' to 'Free Aspect'.";
        }

        // run custom code
        if(OnPostScreenCapUpdate != null) OnPostScreenCapUpdate ();
    }
 public static bool IsToUpdate(xARMScreenCap screenCap)
 {
     if(screenCap.LastUpdateTime != lastChangeInEditorTime && screenCap.LastUpdateTryTime != lastChangeInEditorTime){
         return true;
     } else {
         return false;
     }
 }
示例#14
0
		public xARMScreenCap[] CreateNavigationBarVersion(){
//			xARMScreenCap newScreenCap;
			int MDPINavigationBarHeight = 48;
			int navigationBarHeight = Mathf.RoundToInt (MDPINavigationBarHeight * this.DPIFactor);
			Vector2 navBarRes, navBarResToReplace;

			// on smartphones the navigation bar is always at the same spot
			if (this.IsLandscape && this.Diagonal <= 6.5f){
				navBarRes = new Vector2(this.Resolution.x - navigationBarHeight, this.Resolution.y);
				navBarResToReplace = new Vector2(this.Resolution.x, this.Resolution.y - navigationBarHeight); // incorrect resolution

			} else { // NavBar is allways at the bottom
				navBarRes = new Vector2(this.Resolution.x, this.Resolution.y - navigationBarHeight);
				navBarResToReplace = navBarRes; // keep all values
			}

			xARMScreenCap newScreenCap = new xARMScreenCap(this.Name, navBarRes, 
				this.ResolutionLabel + "~", this.AspectLabel, this.Diagonal, this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, 
				this.StatisticsUsedPercent, this.Description + " (navigation bar version)");
			newScreenCap.IsBaseRes = false;

			xARMScreenCap screenCapToReplace = new xARMScreenCap(this.Name, navBarResToReplace, 
			    this.ResolutionLabel + "~", this.AspectLabel, this.Diagonal, this.DPI, this.DPILabel, this.Group, this.StatisticsPositioning, 
			    this.StatisticsUsedPercent, this.Description + " (navigation bar version)");

			return new xARMScreenCap[] {newScreenCap, screenCapToReplace};
		}
    private static void addOrReplaceScreenCap(xARMScreenCap screenCapToAdd, xARMScreenCap screenCapToReplace)
    {
        int screenCapIndexToReplace = getScreenCapIndex (screenCapToReplace);
        int screenCapIndexToAdd = getScreenCapIndex (screenCapToAdd);

        if(screenCapIndexToReplace >= 0){ // replace
            // values to keep
            bool origEnabledState = AvailScreenCaps[screenCapIndexToReplace].Enabled;

            AvailScreenCaps[screenCapIndexToReplace] = screenCapToAdd;
            AvailScreenCaps[screenCapIndexToReplace].Enabled = origEnabledState;

        } else if(screenCapIndexToAdd >= 0){ // update (don't add duplicates)
            // values to keep
            bool origEnabledState = AvailScreenCaps[screenCapIndexToAdd].Enabled;

            AvailScreenCaps[screenCapIndexToAdd] = screenCapToAdd;
            AvailScreenCaps[screenCapIndexToAdd].Enabled = origEnabledState;

        } else { // add
            AvailScreenCaps.Add (screenCapToAdd);
        }
    }
示例#16
0
 public void StartUpdateScreenCapCoroutine(xARMScreenCap screenCapToUpdate)
 {
     StartCoroutine (UpdateScreenCapCoroutine (screenCapToUpdate));
 }
    private static void addOrUpdateScreenCap(xARMScreenCap screenCapToAdd)
    {
        int screenCapIndex = getScreenCapIndex (screenCapToAdd);

        if(screenCapIndex >= 0){ // update (don't add duplicates)
            // values to keep
            bool origEnabledState = AvailScreenCaps[screenCapIndex].Enabled;

            AvailScreenCaps[screenCapIndex] = screenCapToAdd;
            AvailScreenCaps[screenCapIndex].Enabled = origEnabledState;

        } else { // add
            AvailScreenCaps.Add (screenCapToAdd);
        }
    }
示例#18
0
 // coroutine to update the ScreenCap at the end of the current frame
 private IEnumerator UpdateScreenCapCoroutine(xARMScreenCap screenCapToUpdate)
 {
     yield return new WaitForEndOfFrame();
     xARMManager.ReadScreenCapFromGameView (screenCapToUpdate);
     xARMManager.ScreenCapUpdateInProgress = false;
 }
示例#19
0
	private static void DrawScreenCap (xARMScreenCap screenCap, int screenCapIndex){
		Rect screenCapRect, screenCapBox;
		float screenCapPXOnScreen; // SC px width 
		
		// create Box and Rect
		if(xARMManager.Config.UseFixedScreenCapSize){
			screenCapBox = EditorGUILayout.BeginVertical ("box", GUILayout.Width (xARMManager.Config.FixedScreenCapSize.x), GUILayout.Height (xARMManager.Config.FixedScreenCapSize.y));
			screenCapRect = GUILayoutUtility.GetRect (xARMManager.Config.FixedScreenCapSize.x, xARMManager.Config.FixedScreenCapSize.y);
			screenCapPXOnScreen = xARMManager.Config.FixedScreenCapSize.x;
			
		} else {
			screenCapBox =  EditorGUILayout.BeginVertical ("box");	
			screenCapRect = GUILayoutUtility.GetAspectRect (screenCap.Aspect, GUILayout.MinWidth (screenCapMinWidth), GUILayout.MinHeight (screenCapMinHeight));
			screenCapPXOnScreen = myWindow.position.width / xARMManager.Config.GalleryScreenCapsPerRow; // estimate SC width
		}
		
		// draw SC
		if(screenCap.UpdatedSuccessful){
#if UNITY_3_3 || UNITY_3_4 || UNITY_3_5
			// standard draw (with Play mode tint)
			GUI.DrawTexture (screenCapRect, screenCap.Texture, ScaleMode.ScaleToFit);
#else
			// draw ScreenCap in prepared rect (use EditorGUI.DrawTextureTransparent to draw it without Play mode tint)
			EditorGUI.DrawTextureTransparent (screenCapRect, screenCap.Texture, ScaleMode.ScaleToFit);
#endif

			// select SC in xARM Preview on click
			if(screenCapBox.Contains (Event.current.mousePosition)){
				if(Event.current.type == EventType.MouseDown && Event.current.button == 0){
					xARMPreviewWindow.ChangeActiveScreenCap (screenCapIndex);
				}
			}

		} else {
#if UNITY_3_3 || UNITY_3_4
			GUILayout.Label ("ScreenCap could not been updated");
#else
			EditorGUILayout.HelpBox ("ScreenCap could not been updated", MessageType.Warning, true); // Unity 3.3 Error
#endif
		}
		
		GUILayout.Space (2);
		
		// description
		EditorGUILayout.BeginHorizontal ();
		if(screenCap.IsLandscape){
			GUILayout.Label (screenCap.Name + " " + screenCap.Diagonal + charInch + " " + screenCap.DPILabel + " (" + screenCap.AspectLabel + ")" + "\n" + 
				screenCap.Resolution.x + "x" + screenCap.Resolution.y + "px (" + screenCap.ResolutionLabel + " " + charLandscape + ")", labelStyle);
		} else {
			GUILayout.Label (screenCap.Name + " " + screenCap.Diagonal + charInch + " " + screenCap.DPILabel + " (" + screenCap.AspectLabel + ")" + "\n" + 
				screenCap.Resolution.x + "x" + screenCap.Resolution.y + "px (" + screenCap.ResolutionLabel + " " + charPortrait + ")", labelStyle);
		}
		
		// scale ratio
		if(xARMManager.Config.EditorDPI > 0){
			float scaleRatioPhySizeInch = xARMManager.Config.ScaleRatioInch;
			float scaleRatioPhySizePX = xARMManager.Config.EditorDPI * scaleRatioPhySizeInch; // phy size of fingerprint with Editor DPI
			float screenCapPhySizeOnScreen = screenCap.Resolution.x * xARMManager.Config.EditorDPI / screenCap.DPI; // phy size of SC with Editor DPI
			if(Event.current.type.Equals(EventType.Repaint)) screenCapPXOnScreen = screenCapRect.width; // get precise SC width
			float scaleRatioPX = scaleRatioPhySizePX * screenCapPXOnScreen / screenCapPhySizeOnScreen; // px widht/height of fingerprint
			
			Rect scaleRatioRect = GUILayoutUtility.GetRect (scaleRatioPX, scaleRatioPX, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false));
			GUI.DrawTexture (scaleRatioRect, EditorGUIUtility.whiteTexture, ScaleMode.ScaleToFit, false);
		}
		
		EditorGUILayout.EndHorizontal ();
		EditorGUILayout.EndVertical ();
	}