Exemplo n.º 1
0
	void DrawLeftNavigation()
	{
		GUI.Box(new Rect(0,50,300,canvas.height+30),"");
		
		GUILayoutOption[] leftOptions = new GUILayoutOption[3];
		leftOptions[0] = GUILayout.MinWidth(300);
		leftOptions[1] = GUILayout.MaxWidth(300);
		leftOptions[2] = GUILayout.MinHeight(480);
		GUILayout.BeginArea(new Rect(0,0,300,480));
		EditorGUILayout.BeginVertical(leftOptions);
		
		
		string[] titles;
		#if QUADUI_1_2
		
		GUILayout.Space(20);
		titles = new string[3]{"Quad","Camera","Settings"};
		
		#elif QUADUI_1_3
		
		titles = new string[4]{"Quad","Complex","Camera","Settings"};
		
		#endif
		
		
		currentPage = GUILayout.Toolbar(currentPage, titles);
		GUILayout.Space(10);
		
		switch(currentPage)
		{
			case 0:
				GUILayout.Label ("Create a New Quad:", EditorStyles.boldLabel);
				GUILayout.Space(20);
				_material = (Material) EditorGUILayout.ObjectField (_material, typeof(Material));
				GUILayout.Space(10);
				_name = EditorGUILayout.TextField ("Name:", _name);
				GUILayout.Space(10);
				
				#if QUADUI_1_2
				_reg = (RegistrationPoint) EditorGUILayout.EnumPopup ("Pivot Point:", _reg);
				#elif QUADUI_1_3
				EditorGUILayout.PrefixLabel("Quad Pivot Point:");
				GUILayout.BeginHorizontal(new GUILayoutOption[1]{GUILayout.Width(200)});
				GUILayout.Space(100);
				_reg = (RegistrationPoint) GUILayout.SelectionGrid((int)_reg,new string[9]{"","","","","","","","",""},3,new GUILayoutOption[1]{GUILayout.Width(100)});
				GUILayout.EndHorizontal();
				GUILayout.Space(20);
				#endif
			
				_layer = EditorGUILayout.LayerField("Layer:", _layer);
				GUILayout.Space(20);
				_prevClass = _class;
				_class = (QuadUIClass) EditorGUILayout.EnumPopup ("Class:", _class);

				GUILayout.Space(10);
			
				switch(_class)
				{
					case QuadUIClass.None: //We don't want to be part of the framework, just generate a quad.
					currentFrame = -1;
					numFrames = 0;
					FixFrames();
					_uv = EditorGUILayout.Vector2Field("UV Top-Left:", _uv);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height", widthHeight);
					break;
					
					case QuadUIClass.Static:
					numFrames = 0;
					currentFrame = -1;
					FixFrames();
					_uv = EditorGUILayout.Vector2Field("UV Top-Left:", _uv);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height", widthHeight);
					break;
					
					case QuadUIClass.Button:
					
					numFrames = 3;
					FixFrames();			
					if(_prevClass != _class) _frames[0].position = _uv;
					_frames[0] = new Frame(0, _frames[0].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[0].position, "Up State");
					_frames[1] = new Frame(1, _frames[1].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[1].position, "Down State");
					_frames[2] = new Frame(2, _frames[2].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[2].position, "Over State");
					
					_frames[currentFrame].position = EditorGUILayout.Vector2Field(_frames[currentFrame].state + "'s UV Top-Left:", _frames[currentFrame].position);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height:", widthHeight);
					
					break;
					
					case QuadUIClass.Toggle:
					
					numFrames = 4;
					FixFrames();			
					if(_prevClass != _class) _frames[0].position = _uv;
					_frames[0] = new Frame(0, _frames[0].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[0].position, "Off State");
					_frames[1] = new Frame(1, _frames[1].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[1].position, "Off Hover State");
					_frames[2] = new Frame(2, _frames[2].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[2].position, "On State");
					_frames[3] = new Frame(3, _frames[3].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[3].position, "On Hover State");
					
					_frames[currentFrame].position = EditorGUILayout.Vector2Field(_frames[currentFrame].state + "'s UV Top-Left:", _frames[currentFrame].position);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height:", widthHeight);
					
					break;
					
					case QuadUIClass.Sprite:
					numFrames = Mathf.Clamp(EditorGUILayout.IntField("# Frames:",numFrames),2,1000);
					FixFrames();
					if(_prevClass != _class) _frames[0].position = _uv;
					for(int i = 0; i < numFrames; i++)
					{
						_frames[i] = new Frame(i, _frames[i].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[i].position, "Frame "+(i+1));
					}
					
					_frames[currentFrame].position = EditorGUILayout.Vector2Field(_frames[currentFrame].state + "'s UV Top-Left:", _frames[currentFrame].position);
					GUILayout.Space(20);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height:", widthHeight);
					
					break;
					
					case QuadUIClass.InteractiveSprite:
					numFrames = Mathf.Clamp(EditorGUILayout.IntField("# Frames:",numFrames),2,1000);
					FixFrames();
					if(_prevClass != _class) _frames[0].position = _uv;
					for(int i = 0; i < numFrames; i++)
					{
						_frames[i] = new Frame(i, _frames[i].selected, (int) widthHeight.x, (int) widthHeight.y, _frames[i].position, "Frame "+(i+1));
					}
					
					_frames[currentFrame].position = EditorGUILayout.Vector2Field(_frames[currentFrame].state + "'s UV Top-Left:", _frames[currentFrame].position);
					GUILayout.Space(20);
					widthHeight = EditorGUILayout.Vector2Field("Quad Width and Height:", widthHeight);
					break;
				}
								
				GUILayout.Space(20);
				
			
				if(GUILayout.Button("Bake!")) BakeQuad();
			
				//GUILayout.Space(40);
				//_zoom = EditorGUILayout.IntSlider(_zoom,1,4);	
			
			break;
			
			#if QUADUI_1_3
			
			case 1:
			
			//GUILayout.Label ("Complex Component Definition", EditorStyles.boldLabel);
			complexComponentType = (QuadUIComplexComponent) EditorGUILayout.EnumPopup("Class:", complexComponentType);
			
			break;
			
			case 2:
			
			#elif QUADUI_1_2
			case 1:
			#endif
			
			GUILayout.Label ("Define Screen Space", EditorStyles.boldLabel);
			_camName = EditorGUILayout.TextField ("Name", _camName);
			
			
			
			#if UNITY_IPHONE
			_specialRes = (QuadUI.Resolution) EditorGUILayout.EnumPopup("Resolution: ", _specialRes, new GUILayoutOption[0]{});
			
			switch(_specialRes)
			{
				case QuadUI.Resolution.iPadLandscape:
				res = new Vector2(1024,768);
				break;
				
				case QuadUI.Resolution.iPadPortrait:
				res = new Vector2(768,1024);
				break;
				
				case QuadUI.Resolution.iPhone4Landscape:
				res = new Vector2(960,640);
				break;
				
				case QuadUI.Resolution.iPhone4Portrait:
				res = new Vector2(640,960);
				break;
				
				case QuadUI.Resolution.iPhoneLandscape:
				res = new Vector2(480,320);
				break;
				
				case QuadUI.Resolution.iPhonePortrait:
				res = new Vector2(320,480);
				break;
			}
			
			#elif UNITY_ANDROID
			_specialRes = (QuadUI.Resolution) EditorGUILayout.EnumPopup("Resolution: ", _specialRes, new GUILayoutOption[0]{});
			
			switch(_specialRes)
			{
				case QuadUI.Resolution.HTCLegendTall:
					res = new Vector2(320,480);
				break;
				case QuadUI.Resolution.HTCLegendWide:
					res = new Vector2(480,320);
				break;
				case QuadUI.Resolution.NexusOneTall:
					res = new Vector2(480,800);
				break;
				case QuadUI.Resolution.NexusOneWide:
					res = new Vector2(800,480);
				break;
				case QuadUI.Resolution.MotorolaDroidTall:
					res = new Vector2(480,854);
				break;
				case QuadUI.Resolution.MotorolaDroidWide:
					res = new Vector2(854,480);
				break;
				case QuadUI.Resolution.TegraTabletTall:
					res = new Vector2(600,1024);
				break;
				case QuadUI.Resolution.TegraTabletWide:
					res = new Vector2(1024,600);
				break;
				case QuadUI.Resolution.Custom:
					res = EditorGUILayout.Vector2Field("Screen Size", res);
				break;
			}
			
			#else
			res = EditorGUILayout.Vector2Field("Screen Size", res);
			#endif
			
			_cullingMask[0] = EditorGUILayout.LayerField("Culling Mask ",_cullingMask[0]);
			GUILayout.Space(20);
			if(GUILayout.Button("Generate 2D Camera")) GenerateCamera();
			
			break;
			
			#if QUADUI_1_3
			case 3:
			#elif QUADUI_1_2
			case 2:
			#endif
			GUILayout.Label ("Tool Settings", EditorStyles.boldLabel);
			_selectedColor = EditorGUILayout.ColorField("Selected", _selectedColor);
			_dragColor = EditorGUILayout.ColorField("Drag", _dragColor);
			_gridColor = EditorGUILayout.ColorField("Grid", _gridColor);
			_crosshairColor = EditorGUILayout.ColorField("Crosshairs", _crosshairColor);
			
			_showGrid = EditorGUILayout.BeginToggleGroup("Show Grid",_showGrid);
			_gridSize = Mathf.Max(EditorGUILayout.IntField("Grid Size", _gridSize),2);
			EditorGUILayout.EndToggleGroup();
			_meshOutputPath = EditorGUILayout.TextField("Mesh Path", _meshOutputPath);
			_prefabOutputPath = EditorGUILayout.TextField("Prefab Path", _prefabOutputPath);
			
			break;
		}	
		
		EditorGUILayout.EndVertical();
		GUILayout.EndArea();
	}
Exemplo n.º 2
0
    private void InternalInitFromImage(Texture2D texture, float pixelsPerMeter, string shaderType, RegistrationPoint regPoint, Rect? rect = null)
    {
        _texture = texture;
        _textureRect = rect.GetValueOrDefault(new Rect(0f, 0f, (float)_texture.width, (float)_texture.height));

        if (pixelsPerMeter == 0)
            pixelsPerMeter = CinchOptions.DefaultPixelsPerMeter;

        this._pixelsPerMeter = pixelsPerMeter;
        _regPoint = regPoint;

        //flip the y-axis
        if (CinchOptions.UseTopLeftSpriteSheetCoordinates)
        {
            var h = _textureRect.height;
            _textureRect.yMin = _texture.height - (_textureRect.yMin + _textureRect.height);
            _textureRect.height = h;
        }

        var scaledRect = new Rect(_textureRect.x/_texture.width, _textureRect.y/_texture.height, _textureRect.width/_texture.width, _textureRect.height/_texture.height);

        _originalMesh = new Mesh();
        _originalMesh.name = "Scripted_Plane_New_Mesh";
        var fullWidth = _textureRect.width / pixelsPerMeter;
        var fullHeight = _textureRect.height / pixelsPerMeter;
        var left = fullWidth * (0f-regPoint.X);
        var right = fullWidth * (1f-regPoint.X);
        var top = fullHeight * (0f-regPoint.Y);
        var bottom = fullHeight * (1f-regPoint.Y);
        var front = -.1f;
        var flt = new Vector3(left,  top, front);
        var frt = new Vector3(right, top, front);
        var frb = new Vector3(right, bottom, front);
        var flb = new Vector3(left,  bottom, front);

        _originalMesh.vertices = new Vector3[] {
                                    flt, frt, frb, flb
        };

        _originalMesh.uv = new Vector2[] {
            new Vector2 (scaledRect.xMin, scaledRect.yMin),
            new Vector2 (scaledRect.xMax, scaledRect.yMin),
            new Vector2 (scaledRect.xMax, scaledRect.yMax),
            new Vector2 (scaledRect.xMin, scaledRect.yMax)
        };

        _originalMesh.triangles = new int[] {
            3 , 2 , 1 , 0 , 3 , 1
        };
        _originalMesh.RecalculateNormals();

        _meshFilter = gameObject.AddComponent<MeshFilter>();
        _meshFilter.sharedMesh = _transformedMesh;

        var shader = ShaderCache.GetShader(shaderType);
        _meshRenderer = gameObject.AddComponent<MeshRenderer>();
        _meshRenderer.castShadows = false;
        _meshRenderer.receiveShadows = false;
        _material = _meshRenderer.material;
        _material.shader = shader;
        _material.mainTexture = _texture;
        _material.color = new Color( 1f, 1f, 1f, 1f );
        _material.mainTexture.wrapMode = TextureWrapMode.Clamp;

        if (Parent == null)
            _meshRenderer.enabled = false; //default it to false until it gets added

        __UpdateMesh();
    }
Exemplo n.º 3
0
 private void InternalInitFromImage(string texturePath, float pixelsPerMeter, string shaderType, RegistrationPoint regPoint, Rect? rect = null)
 {
     var texture = TextureCache.GetCachedTexture(texturePath);
     InternalInitFromImage(texture, pixelsPerMeter, shaderType, regPoint, rect);
 }
Exemplo n.º 4
0
 protected void InitFromImage(string texturePath, float pixelsPerMeter = 0, RegistrationPoint? regPoint = null, Rect? rect = null)
 {
     InternalInitFromImage(texturePath, pixelsPerMeter, CinchOptions.DefaultShader, regPoint.GetValueOrDefault(RegistrationPoint.Center), rect);
 }
Exemplo n.º 5
0
    /// <summary>
    /// Creates a new CinchSprite from a portion of the supplied sprite sheet texture.  See http://www.codeandweb.com/what-is-a-sprite-sheet for more on sprite sheets.
    /// </summary>
    /// <returns>
    /// The new CinchSprite.
    /// </returns>
    /// <param name='texturePath'>
    /// CinchSprite sheet to build CinchSprite from.
    /// </param>
    /// <param name='left'>
    /// Left side of sprite sheet coordinates, in pixels.
    /// </param>
    /// <param name='top'>
    /// Top side of sprite sheet coordinates, in pixels.
    /// </param>
    /// <param name='width'>
    /// Width of sprite sheet coordinates, in pixels.
    /// </param>
    /// <param name='height'>
    /// Height of sprite sheet coordinates, in pixels.
    /// </param>
    /// <param name='pixelsPerMeter'>
    /// Pixels per meter.  Specifying 100 with a 100x100 sprite rectangle will produce a 1x1 meter CinchSprite.  You can pass in CinchOptions.DefaultPixelsPerMeter to keep everything the same size.
    /// </param>
    /// <param name='regPoint'>
    /// The registration point (center to pivot around).  Defaults to center.  You can use any of the constants defined on the RegistrationPoint struct, new() up one.
    /// </param>
    public static CinchSprite NewFromSpriteSheet(string texturePath, float left, float top, float width, float height, float pixelsPerMeter = 0, RegistrationPoint? regPoint = null)
    {
        GameObject go = new GameObject(texturePath);
        var sprite = go.AddComponent<CinchSprite>();

        sprite.InternalInitFromImage(texturePath, pixelsPerMeter, CinchOptions.DefaultShader, regPoint.GetValueOrDefault(RegistrationPoint.Center), new Rect(left, top, width, height));
        return sprite;
    }
Exemplo n.º 6
0
    public static CinchSprite NewFromImage(UnityEngine.Sprite inputSprite, float pixelsPerMeter = 0, RegistrationPoint? regPoint = null)
    {
        GameObject go = new GameObject("newSprite");
        var sprite = go.AddComponent<CinchSprite>();

        sprite.InternalInitFromImage(inputSprite.texture, pixelsPerMeter, CinchOptions.DefaultShader, regPoint.GetValueOrDefault(RegistrationPoint.Center));
        return sprite;
    }