/// <summary> /// Convenience method to configure and optionally instantiate a new UISprite for a font character. /// </summary> private UISprite configureSpriteForCharId(UISprite sprite, int charId, float xPos, float yPos, float scale, int depth) { var uvRect = new UIUVRect((int)_textureOffset.x + _fontDetails[charId].posX, (int)_textureOffset.y + _fontDetails[charId].posY, _fontDetails[charId].w, _fontDetails[charId].h, _manager.textureSize); // NOTE: This contains a bugfix from the previous version where offsetx was being used // in the wrong spot according to the angelcode spec. xadvance is the complete character width // and offsetx is supposed to be used only during character rendering, not during cursor advance. // Please note that yPos already has offsety built in. var rect = new Rect(xPos + _fontDetails[charId].offsetx * scale, yPos, _fontDetails[charId].w, _fontDetails[charId].h); if (sprite == null) { sprite = new UISprite(rect, depth, uvRect, false); _manager.addSprite(sprite); } else { sprite.uvFrame = uvRect; sprite.position = new Vector3(rect.x, -rect.y, depth); sprite.setSize(rect.width, rect.height); } // We scale the sprite this way so it will work with the container clipping sprite.autoRefreshPositionOnScaling = false; sprite.scale = new Vector3(scale, scale, 1); return(sprite); }
public UIZoomButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ):base( manager, frame, depth, uvFrame, highlightedUVframe ) { centerize(); autoRefreshPositionOnScaling = false; _zoomInAnimation = new UIAnimation( this, 0.3f, UIAnimationProperty.Scale, new Vector3( 1, 1, 1 ), new Vector3( 1.3f, 1.3f, 1.3f ), Easing.Quartic.easeInOut ); _zoomOutAnimation = new UIAnimation( this, 0.3f, UIAnimationProperty.Scale, new Vector3( 1.3f, 1.3f, 1.3f ), new Vector3( 1, 1, 1 ), Easing.Quartic.easeInOut ); }
public UIProgressBar( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite bar, bool rotated ) : base(frame, depth, uvFrame, rotated) { // Save the bar and make it a child of the container/border for organization purposes _bar = bar; _bar.parentUIObject = this; _barOriginalWidth = _bar.width; _barOriginalHeight = _bar.height; /* // Save the bars original size if (rotated) { _barOriginalWidth = _bar.width; _barOriginalHeight = _bar.height; } else { _barOriginalWidth = _bar.width; _barOriginalHeight = _bar.height; } */ /*if (!_rotated) normalFrame = new Rect( clientTransform.position.x, -clientTransform.position.y, width * touchesScale.x, height * touchesScale.y); else normalFrame = new Rect( clientTransform.position.x, -clientTransform.position.y - (width * touchesScale.y), height * touchesScale.x, width * touchesScale.y); */ _barOriginalUVframe = _bar.uvFrame; manager.addSprite( this ); }
public UIZoomButton(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(manager, frame, depth, uvFrame, highlightedUVframe) { centerize(); autoRefreshPositionOnScaling = false; _zoomInAnimation = new UIAnimation(this, 0.3f, UIAnimationProperty.Scale, new Vector3(1, 1, 1), new Vector3(1.3f, 1.3f, 1.3f), Easing.Quartic.easeInOut); _zoomOutAnimation = new UIAnimation(this, 0.3f, UIAnimationProperty.Scale, new Vector3(1.3f, 1.3f, 1.3f), new Vector3(1, 1, 1), Easing.Quartic.easeInOut); }
public UITexture( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame) : base(frame, depth, uvFrame) { _normalUVframe = uvFrame; manager.addSprite( this ); }
public UIColorPicker( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, Vector2 textureCoords ) : base(frame, depth, uvFrame) { //We store the coordinates of the top left of the subtexture this.textureCoords = textureCoords; manager.addTouchableSprite( this ); }
private UIUVRect[] loadFrames(string[] filenames) { UIUVRect[] frames = new UIUVRect[filenames.Length]; for (int i = 0; i < filenames.Length; i++) { frames[i] = manager.textureInfoForFilename(filenames[i]).uvRect; } return(frames); }
/// <summary> /// Shortcut for adding a new sprite using the raw materials /// </summary> private UISprite addSprite(Rect frame, UIUVRect uvFrame, int depth, bool gameObjectOriginInCenter) { // Create and initialize the new sprite UISprite newSprite = new UISprite(frame, depth, uvFrame, gameObjectOriginInCenter); addSprite(newSprite); return(newSprite); }
// draw text on screen, create each quad and send it to the manager private int drawText(string text, float xPos, float yPos, float scale, int depth, Color color) { float dx = xPos; float dy = 0; float textWidth; float offsetY; int fontLineSkip = 0; int charId = 0; UISprite[] sprites = null; int length = text.Length; sprites = new UISprite[length]; for (var i = 0; i < text.Length; i++) { charId = System.Convert.ToInt32(text[i]); // "10" is the new line char if (charId == 10) { // calculate the size to center text on Y axis, based on its scale // 77 is the "M" char usually big enough to get a proper spaced // lineskip, use any other char if you want fontLineSkip += (int)(_fontDetails[77].h * scale * lineSpacing); dx = xPos; } else { // calculate the size to center text on Y axis, based on its scale offsetY = _fontDetails[charId].offsety * scale; dy = yPos + offsetY + fontLineSkip; } // add quads for each char var uvRect = new UIUVRect((int)_textureOffset.x + _fontDetails[charId].posX, (int)_textureOffset.y + _fontDetails[charId].posY, _fontDetails[charId].w, _fontDetails[charId].h, _manager.textureSize); sprites[i] = new UISprite(new Rect(dx, dy, _fontDetails[charId].w * scale, _fontDetails[charId].h * scale), depth, uvRect, false); _manager.addSprite(sprites[i]); sprites[i].color = color; // calculate the size to advance, based on its scale textWidth = _fontDetails[charId].xadvance * scale; // advance the position to draw the next letter dx += textWidth + _fontDetails[charId].offsetx; } // add all sprites at once to the array, we use this later to delete the strings _textSprites.Add(sprites); return(_textSprites.Count - 1); }
/// <summary> /// Initializes a new instance of the <see cref="UISlice9"/> class. /// </summary> /// <param name='manager'> /// Manager. /// </param> /// <param name='frame'> /// Frame. /// </param> /// <param name='depth'> /// Depth. /// </param> /// <param name='uvFrame'> /// Uv frame. /// </param> /// <param name='width'> /// Final width /// </param> /// <param name='height'> /// Final height /// </param> /// <param name='sTP'> /// Top Margin /// </param> /// <param name='sRT'> /// Right Margin /// </param> /// <param name='sBT'> /// Bottom Margin /// </param> /// <param name='sLT'> /// Left Margin /// </param> public UISlice9(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, int width, int height, int sTP, int sRT, int sBT, int sLT) : base(frame, depth, uvFrame) { int stretchedWidth = width - (sLT + sRT); int stretchedHeight = height - (sTP + sBT); this.manager = manager; manager.addSprite(this); // Top Left spriteSlices[0] = new UISprite(new Rect(frame.x, frame.y, sLT, sTP), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y, sLT, sTP, manager.textureSize)); manager.addSprite(spriteSlices[0]); spriteSlices[0].parentUIObject = this; // Top Middle spriteSlices[1] = new UISprite(new Rect(frame.x + sLT, frame.y, stretchedWidth, sTP), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y, uvFrame.frame.width - (sRT + sLT), sTP, manager.textureSize)); manager.addSprite(spriteSlices[1]); spriteSlices[1].parentUIObject = this; // Top Right spriteSlices[2] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y, sRT, sTP), depth, new UIUVRect(uvFrame.frame.x + sLT + (uvFrame.frame.width - (sRT + sLT)), uvFrame.frame.y, sRT, sTP, manager.textureSize)); manager.addSprite(spriteSlices[2]); spriteSlices[2].parentUIObject = this; // Middle Left spriteSlices[3] = new UISprite(new Rect(frame.x, frame.y + sTP, sLT, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y + sTP, sLT, uvFrame.frame.height - (sTP + sBT), manager.textureSize)); manager.addSprite(spriteSlices[3]); spriteSlices[3].parentUIObject = this; // Middle Middle spriteSlices[4] = new UISprite(new Rect(frame.x + sLT, frame.y + sTP, stretchedWidth, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y + sTP, uvFrame.frame.width - (sLT + sRT), uvFrame.frame.height - (sBT + sTP), manager.textureSize)); manager.addSprite(spriteSlices[4]); spriteSlices[4].parentUIObject = this; // Middle Right spriteSlices[5] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y + sTP, sRT, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x + (uvFrame.frame.width - sRT), uvFrame.frame.y + sTP, sRT, uvFrame.frame.height - (sBT + sTP), manager.textureSize)); manager.addSprite(spriteSlices[5]); spriteSlices[5].parentUIObject = this; // Bottom Left spriteSlices[6] = new UISprite(new Rect(frame.x, frame.y + sTP + stretchedHeight, sLT, sBT), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y + (uvFrame.frame.height - sBT), sLT, sBT, manager.textureSize)); manager.addSprite(spriteSlices[6]); spriteSlices[6].parentUIObject = this; // Bottom Middle spriteSlices[7] = new UISprite(new Rect(frame.x + sLT, frame.y + sTP + stretchedHeight, stretchedWidth, sBT), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y + (uvFrame.frame.height - sBT), uvFrame.frame.width - (sLT + sRT), sBT, manager.textureSize)); manager.addSprite(spriteSlices[7]); spriteSlices[7].parentUIObject = this; // Bottom Right spriteSlices[8] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y + sTP + stretchedHeight, sRT, sBT), depth, new UIUVRect(uvFrame.frame.x + sLT + (uvFrame.frame.width - (sRT + sLT)), uvFrame.frame.y + (uvFrame.frame.height - sBT), sRT, sBT, manager.textureSize)); manager.addSprite(spriteSlices[8]); spriteSlices[8].parentUIObject = this; this.setSize(width, height); }
public UIButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ):base( frame, depth, uvFrame ) { // If a highlighted frame has not yet been set use the normalUVframe if( highlightedUVframe == UIUVRect.zero ) highlightedUVframe = uvFrame; this.highlightedUVframe = highlightedUVframe; manager.addTouchableSprite( this ); }
private UIUVRect[] loadFrames(string[] filenames) { var frames = new UIUVRect[filenames.Length]; for (var i = 0; i < filenames.Length; i++) { var uv = this.manager.textureInfoForFilename(filenames[i]).uvRect; frames[i] = uv; } return(frames); }
/* public static UIControlTemplate create( string filename, string highlightedFilename, int xPos, int yPos, int depth = 1 ) { // create and return a new UIControlTemplate } */ public UIControlTemplate( Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ):base( frame, depth, uvFrame ) { // Save a copy of our uvFrame here so that when highlighting turns off we have the original UVs _tempUVframe = uvFrame; // If a highlighted frame has not yet been set use the normalUVframe if( highlightedUVframe == UIUVRect.zero ) highlightedUVframe = uvFrame; this.highlightedUVframe = highlightedUVframe; }
// Updates the UVs of the specified sprite and copies the new values into the mesh object. public void updateUV(UISprite sprite) { UIUVRect r = sprite.displayUV; UVs[sprite.vertexIndices.uv.one] = r.lowerLeftUV + Vector2.up * r.uvDimensions.y; // Upper-left UVs[sprite.vertexIndices.uv.two] = r.lowerLeftUV; // Lower-left UVs[sprite.vertexIndices.uv.three] = r.lowerLeftUV + Vector2.right * r.uvDimensions.x; // Lower-right UVs[sprite.vertexIndices.uv.four] = r.lowerLeftUV + r.uvDimensions; // Upper-right uvsChanged = true; meshIsDirty = true; }
public UIProgressBar(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite bar) : base(frame, depth, uvFrame) { // Save the bar and make it a child of the container/border for organization purposes _bar = bar; _bar.parentUIObject = this; // Save the bars original size _barOriginalWidth = _bar.width; _barOriginalUVframe = _bar.uvFrame; manager.addSprite(this); }
public UIButton(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(frame, depth, uvFrame) { // If a highlighted frame has not yet been set use the normalUVframe if (highlightedUVframe == UIUVRect.zero) { highlightedUVframe = uvFrame; } this.highlightedUVframe = highlightedUVframe; manager.addTouchableSprite(this); }
public UISprite( Rect frame, int depth, UIUVRect uvFrame, bool gameObjectOriginInCenter ) : base() { this.gameObjectOriginInCenter = gameObjectOriginInCenter; // Setup our GO client.transform.position = new Vector3( frame.x, -frame.y, depth ); // Depth will affect z-index // Save these for later. The manager will call initializeSize() when the UV's get setup _width = frame.width; _height = frame.height; _uvFrame = uvFrame; }
public UISlider(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite sliderKnob, UISliderLayout layout) : base(frame, depth, uvFrame) { this.layout = layout; // save the sliderKnob and make it a child of the slider for organization purposes _sliderKnob = sliderKnob; _sliderKnob.parentUIObject = this; // setup the min/max position values for the sliderKnob updateSliderKnobConstraints(); manager.addTouchableSprite(this); }
/* * public static UIControlTemplate create( string filename, string highlightedFilename, int xPos, int yPos, int depth = 1 ) * { * // create and return a new UIControlTemplate * } */ public UIControlTemplate(Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(frame, depth, uvFrame) { // Save a copy of our uvFrame here so that when highlighting turns off we have the original UVs _normalUVframe = uvFrame; // If a highlighted frame has not yet been set use the normalUVframe if (highlightedUVframe == UIUVRect.zero) { highlightedUVframe = uvFrame; } this.highlightedUVframe = highlightedUVframe; }
public UIProgressBar( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite bar ) : base(frame, depth, uvFrame) { // Save the bar and make it a child of the container/border for organization purposes _bar = bar; _bar.parentUIObject = this; // Save the bars original size _barOriginalWidth = _bar.width; _barOriginalUVframe = _bar.uvFrame; manager.addSprite( this ); }
public UISprite(Rect frame, int depth, UIUVRect uvFrame, bool gameObjectOriginInCenter) : base() { this.gameObjectOriginInCenter = gameObjectOriginInCenter; // Setup our GO client.transform.position = new Vector3(frame.x, -frame.y, depth); // Depth will affect z-index // Save these for later. The manager will call initializeSize() when the UV's get setup _width = frame.width; _height = frame.height; _uvFrame = uvFrame; }
public UISlider( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite sliderKnob, UISliderLayout layout, bool rotated ):base( frame, depth, uvFrame, rotated ) { this.layout = layout; // save the sliderKnob and make it a child of the slider for organization purposes _sliderKnob = sliderKnob; _sliderKnob.parentUIObject = this; // setup the min/max position values for the sliderKnob updateSliderKnobConstraints(); manager.addTouchableSprite( this ); }
public UIButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ):base( frame, depth, uvFrame ) { // Save a copy of our uvFrame here so that when highlighting turns off we have the original UVs _normalUVframe = uvFrame; // If a highlighted frame has not yet been set use the normalUVframe if( highlightedUVframe == UIUVRect.zero ) highlightedUVframe = uvFrame; this.highlightedUVframe = highlightedUVframe; manager.addTouchableSprite( this ); }
public UIButton(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(frame, depth, uvFrame) { // Save a copy of our uvFrame here so that when highlighting turns off we have the original UVs _normalUVframe = uvFrame; // If a highlighted frame has not yet been set use the normalUVframe if (highlightedUVframe == UIUVRect.zero) { highlightedUVframe = uvFrame; } this.highlightedUVframe = highlightedUVframe; manager.addTouchableSprite(this); }
public UIProgressBar( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, bool rightToLeft ):base( frame, depth, uvFrame ) { manager.addSprite( this ); // Save the bars original size _barOriginalWidth = frame.width; _barOriginalUVframe = uvFrame; this.rightToLeft = rightToLeft; // Update the bar size based on the value if( rightToLeft ) setSize( _value * -_barOriginalWidth, frame.height ); else setSize( _value * _barOriginalWidth, frame.height ); }
public UIProgressBar(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, bool rightToLeft) : base(frame, depth, uvFrame) { manager.addSprite(this); // Save the bars original size _barOriginalWidth = frame.width; _barOriginalUVframe = uvFrame; this.rightToLeft = rightToLeft; // Update the bar size based on the value if (rightToLeft) { setSize(_value * -_barOriginalWidth, frame.height); } else { setSize(_value * _barOriginalWidth, frame.height); } }
public UIProgressBar( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UISprite bar ) : base(frame, depth, uvFrame) { // Save the bar and make it a child of the container/border for organization purposes _bar = bar; _bar.parentUIObject = this; // Save the bars original size _barOriginalWidth = _bar.width; _barOriginalUVframe = _bar.uvFrame; // Update the bar size based on the value if (rightToLeft) _bar.setSize(_value * -_barOriginalWidth, _bar.height); else _bar.setSize(_value * _barOriginalWidth, _bar.height); manager.addSprite( this ); }
public UIJoystick(UIToolkit manager, Rect frame, int depth, UISprite joystickSprite, float xPos, float yPos) : base(frame, depth, UIUVRect.zero) { // Save out the uvFrame for the sprite so we can highlight _normalUVframe = joystickSprite.uvFrame; // Save the joystickSprite and make it a child of the us for organization purposes _joystickSprite = joystickSprite; _joystickSprite.parentUIObject = this; // Move the joystick to its default position after converting the offset to a vector3 _joystickOffset = new Vector3(xPos, yPos); // Set the maxMovement which will in turn calculate the _joystickBoundary this.maxJoystickMovement = _maxJoystickMovement; resetJoystick(); manager.addTouchableSprite(this); _manager = manager; }
public UIJoystick( UIToolkit manager, Rect frame, int depth, UISprite joystickSprite, float xPos, float yPos ):base( frame, depth, UIUVRect.zero ) { // Save out the uvFrame for the sprite so we can highlight _normalUVframe = joystickSprite.uvFrame; // Save the joystickSprite and make it a child of the us for organization purposes _joystickSprite = joystickSprite; _joystickSprite.parentUIObject = this; // Move the joystick to its default position after converting the offset to a vector3 _joystickOffset = new Vector3( xPos, yPos ); // Set the maxMovement which will in turn calculate the _joystickBoundary this.maxJoystickMovement = _maxJoystickMovement; resetJoystick(); manager.addTouchableSprite( this ); _manager = manager; }
private void updateDisplayUV() { if (clipped) { Rect r = _localVisibleRect; if (gameObjectOriginInCenter) { r.x += _width / 2; r.y += _height / 2; } _displayUV = _originalUV.Intersect(r, manager.textureSize); } else { _displayUV = _originalUV; } if (!_suspendUpdates && manager) { manager.updateUV(this); } }
public UISprite( Rect frame, int depth, UIUVRect uvFrame ) : this(frame, depth, uvFrame, false) { }
public UIStateSprite(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame) : base(frame, depth, uvFrame) { manager.addSprite(this); }
public UIStateButton(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(manager, frame, depth, uvFrame, highlightedUVframe) { }
/// <summary> /// Initializes a new instance of the <see cref="UISlice9"/> class. /// </summary> /// <param name='manager'> /// Manager. /// </param> /// <param name='frame'> /// Frame. /// </param> /// <param name='depth'> /// Depth. /// </param> /// <param name='uvFrame'> /// Uv frame. /// </param> /// <param name='highlightedUVframe'> /// Highlighted U vframe. /// </param> /// <param name='width'> /// Final width /// </param> /// <param name='height'> /// Final height /// </param> /// <param name='sTP'> /// Top Margin /// </param> /// <param name='sRT'> /// Right Margin /// </param> /// <param name='sBT'> /// Bottom Margin /// </param> /// <param name='sLT'> /// Left Margin /// </param> public UISlice9( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe, int width, int height, int sTP, int sRT, int sBT, int sLT ):base( frame, depth, uvFrame ) { // If a highlighted frame has not yet been set use the normalUVframe if( highlightedUVframe == UIUVRect.zero ) highlightedUVframe = uvFrame; this.highlightedUVframe = highlightedUVframe; int stretchedWidth = width - ( sLT + sRT ); int stretchedHeight = height - ( sTP + sBT ); this.manager = manager; // Top Left spriteSlices[0] = new UISprite( new Rect( frame.x, frame.y, sLT, sTP ), depth, new UIUVRect( uvFrame.frame.x, uvFrame.frame.y, sLT, sTP, manager.textureSize ) ); spriteSlices[0].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[0] ); // Top Middle spriteSlices[1] = new UISprite( new Rect( frame.x + sLT, frame.y, stretchedWidth, sTP ), depth, new UIUVRect( uvFrame.frame.x + sLT, uvFrame.frame.y, uvFrame.frame.width - ( sRT + sLT ), sTP, manager.textureSize ) ); spriteSlices[1].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[1] ); // Top Right spriteSlices[2] = new UISprite( new Rect( frame.x + sLT + stretchedWidth, frame.y, sRT, sTP ), depth, new UIUVRect( uvFrame.frame.x + sLT + ( uvFrame.frame.width - ( sRT + sLT ) ), uvFrame.frame.y, sRT, sTP, manager.textureSize ) ); spriteSlices[2].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[2] ); // Middle Left spriteSlices[3] = new UISprite( new Rect( frame.x, frame.y + sTP, sLT, stretchedHeight ), depth, new UIUVRect( uvFrame.frame.x, uvFrame.frame.y + sTP, sLT, uvFrame.frame.height - ( sTP + sBT ), manager.textureSize ) ); spriteSlices[3].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[3] ); // Middle Middle spriteSlices[4] = new UISprite( new Rect( frame.x + sLT, frame.y + sTP, stretchedWidth, stretchedHeight ), depth, new UIUVRect( uvFrame.frame.x + sLT, uvFrame.frame.y + sTP, uvFrame.frame.height - ( sTP + sBT ), (int)frame.width - ( sLT + sRT ), manager.textureSize ) ); spriteSlices[4].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[4] ); // Middle Right spriteSlices[5] = new UISprite( new Rect( frame.x + sLT + stretchedWidth, frame.y + sTP, sRT, stretchedHeight ), depth, new UIUVRect( uvFrame.frame.x + ( uvFrame.frame.width - sRT ), uvFrame.frame.y + sTP, sRT, uvFrame.frame.height - ( sBT + sTP ), manager.textureSize ) ); spriteSlices[5].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[5] ); // Bottom Left spriteSlices[6] = new UISprite( new Rect( frame.x, frame.y + sTP + stretchedHeight, sLT, sBT ), depth, new UIUVRect( uvFrame.frame.x, uvFrame.frame.y + ( uvFrame.frame.height - sBT ), sLT, sBT, manager.textureSize ) ); spriteSlices[6].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[6] ); // Bottom Middle spriteSlices[7] = new UISprite( new Rect( frame.x + sLT, frame.y + sTP + stretchedHeight, stretchedWidth, sBT ), depth, new UIUVRect( uvFrame.frame.x + sLT, uvFrame.frame.y + ( uvFrame.frame.height - sBT ), uvFrame.frame.width - ( sLT + sRT ), sBT, manager.textureSize ) ); spriteSlices[7].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[7] ); // Bottom Right spriteSlices[8] = new UISprite( new Rect( frame.x + sLT + stretchedWidth, frame.y + sTP + stretchedHeight, sRT, sBT ), depth, new UIUVRect( uvFrame.frame.x + sLT + ( uvFrame.frame.width - ( sRT + sLT ) ), uvFrame.frame.y + ( uvFrame.frame.height - sBT ), sRT, sBT, manager.textureSize ) ); spriteSlices[8].client.transform.parent = this.client.transform; manager.addSprite( spriteSlices[8] ); this.setSize( width, height ); manager.addTouchableSprite( this ); }
// constructor for when the need to have a centered UISprite arises (I'm looking at you UIKnob) public UITouchableSprite( Rect frame, int depth, UIUVRect uvFrame, bool gameObjectOriginInCenter ):base( frame, depth, uvFrame, gameObjectOriginInCenter ) { }
public UIContinuousButton( UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe ) : base(manager, frame, depth, uvFrame, highlightedUVframe) { }
void CreateMeshes() { string assetPath = "Assets/test1.prefab"; // clone the model template //Object templatePrefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)); //GameObject template = (GameObject)EditorUtility.InstantiatePrefab(templatePrefab); // this way links will persist when we regenerate the mesh Object prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)); if (!prefab) { prefab = EditorUtility.CreateEmptyPrefab(assetPath); } // p1 p2 // *-------* // | | // | 0,0 | // | | // *-------* // p0 p3 float size = 1; float halfsize = size / 2; Vector3 p0; Vector3 p1; Vector3 p2; Vector3 p3; const bool faceFront = false; const bool faceUp = true; if (faceFront) { p0 = new Vector3(-halfsize, -halfsize, 0); p1 = new Vector3(-halfsize, halfsize, 0); p2 = new Vector3(halfsize, halfsize, 0); p3 = new Vector3(halfsize, -halfsize, 0); } else if (faceUp) { p0 = new Vector3(-halfsize, 0, -halfsize); p1 = new Vector3(-halfsize, 0, halfsize); p2 = new Vector3(halfsize, 0, halfsize); p3 = new Vector3(halfsize, 0, -halfsize); } float totw = 132; float toth = 132; int x = 66; int y = 1; int w = 32; int h = 32; UIUVRect test = new UIUVRect(x, y, w, h, new Vector2(totw, toth)); // sort of the same... Mesh mesh = (Mesh)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh)); if (!mesh) { mesh = new Mesh(); mesh.name = name; AssetDatabase.AddObjectToAsset(mesh, assetPath); } else { mesh.Clear(); } // generate your mesh in place mesh.name = "Scripted_Plane_New_Mesh"; mesh.vertices = new[] { p0, p1, p2, p3 }; mesh.uv = new[] { test.lowerLeftUV, test.lowerLeftUV + Vector2.up * test.uvDimensions.y, test.lowerLeftUV + test.uvDimensions, test.lowerLeftUV + Vector2.right * test.uvDimensions.x }; mesh.triangles = new[] { 0, 1, 2, 0, 2, 3 }; foreach (Vector2 v in mesh.uv) { Debug.Log(v); } mesh.RecalculateNormals(); GameObject obj = new GameObject("New_Plane_Fom_Script"); obj.AddComponent <MeshRenderer>(); obj.AddComponent <MeshFilter>().sharedMesh = mesh; obj.transform.position = new Vector3(1.45f, 0, 1.02f); // make sure EditorUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ReplaceNameBased); // get rid of the temporary object (otherwise it stays over in scene) Object.DestroyImmediate(obj); }
public void addFrames( UIUVRect[] normal, UIUVRect[] highlighted ) { _uvFrames = normal; maxState = _uvFrames.Length; _state = 0; if( highlighted == null || highlighted.Length == 0 ) { _uvHighlightFrames = normal; } else if( normal.Length == highlighted.Length ) { _uvHighlightFrames = highlighted; } else { // don't have same number of highlighted as normal Debug.LogError( "Highlight frames count does not match normal frames count" ); _uvHighlightFrames = normal; } }
private UIUVRect[] loadFrames( string[] filenames ) { var frames = new UIUVRect[filenames.Length]; for( var i = 0; i < filenames.Length; i++ ) { var uv = this.manager.textureInfoForFilename( filenames[i] ).uvRect; frames[i] = uv; } return frames; }
private UIUVRect[] loadFrames(string[] filenames) { UIUVRect[] frames = new UIUVRect[filenames.Length]; for (int i = 0; i < filenames.Length; i++) { frames[i] = manager.textureInfoForFilename(filenames[i]).uvRect; } return frames; }
public UISwipeDetector(Rect frame, int depth, UIUVRect uvFrame) : base(frame, depth, uvFrame) { touchInfoArray = new TouchInfo[12]; }
/// <summary> /// Convenience method to instantiate a new UISprite for a font character. /// </summary> private UISprite spriteForCharId( int charId, float xPos, float yPos, float scale, int depth ) { var uvRect = new UIUVRect( (int)_textureOffset.x + _fontDetails[charId].posX, (int)_textureOffset.y + _fontDetails[charId].posY, _fontDetails[charId].w, _fontDetails[charId].h, _manager.textureSize ); // NOTE: This contains a bugfix from the previous version where offsetx was being used // in the wrong spot according to the angelcode spec. xadvance is the complete character width // and offsetx is supposed to be used only during character rendering, not during cursor advance. // Please note that yPos already has offsety built in. return new UISprite( new Rect( xPos + _fontDetails[charId].offsetx * scale, yPos, _fontDetails[charId].w * scale, _fontDetails[charId].h * scale ), depth, uvRect, false ); }
public void addFrames(UIUVRect[] normal) { _uvFrames = normal; maxState = _uvFrames.Length; _state = 0; }
public UISwipeDetector( Rect frame, int depth, UIUVRect uvFrame ):base( frame, depth, uvFrame ) { touchInfoArray = new TouchInfo[5]; }
public UISprite(Rect frame, int depth, UIUVRect uvFrame) : this(frame, depth, uvFrame, false) { }
public UITextButton(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe) : base(manager, frame, depth, uvFrame, highlightedUVframe) { textButtonComponent = client.AddComponent <UITextButtonComponent>(); textButtonComponent.textButton = this; }
public UISprite( Rect frame, int depth, UIUVRect uvFrame, bool rotated ) : this(frame, depth, uvFrame, false, rotated) { }
/// <summary> /// Draw text on screen, create each quad and send it to the manager /// </summary> private int drawText( string text, float xPos, float yPos, float scale, int depth, Color color ) { float dx = xPos; float dy = 0; float textWidth; float offsetY; int fontLineSkip = 0; int charId = 0; UISprite[] sprites = null; int length = text.Length; sprites = new UISprite[length]; for( var i = 0; i < text.Length; i++ ) { charId = System.Convert.ToInt32( text[i] ); // "10" is the new line char if( charId == 10 ) { // calculate the size to center text on Y axis, based on its scale // 77 is the "M" char usually big enough to get a proper spaced // lineskip, use any other char if you want fontLineSkip += (int)( _fontDetails[77].h * scale * lineSpacing ); dx = xPos; } else { // calculate the size to center text on Y axis, based on its scale offsetY = _fontDetails[charId].offsety * scale; dy = yPos + offsetY + fontLineSkip; } // add quads for each char var uvRect = new UIUVRect( (int)_textureOffset.x + _fontDetails[charId].posX, (int)_textureOffset.y + _fontDetails[charId].posY, _fontDetails[charId].w, _fontDetails[charId].h, _manager.textureSize ); sprites[i] = new UISprite( new Rect( dx, dy, _fontDetails[charId].w * scale, _fontDetails[charId].h * scale ), depth, uvRect, false ); _manager.addSprite( sprites[i] ); sprites[i].color = color; // calculate the size to advance, based on its scale textWidth = _fontDetails[charId].xadvance * scale; // advance the position to draw the next letter dx += textWidth + _fontDetails[charId].offsetx; } // add all sprites at once to the array, we use this later to delete the strings _textSprites.Add( sprites ); return _textSprites.Count - 1; }
/// <summary> /// Convenience method to configure and optionally instantiate a new UISprite for a font character. /// </summary> private UISprite configureSpriteForCharId( UISprite sprite, int charId, float xPos, float yPos, float scale, int depth ) { var uvRect = new UIUVRect( (int)_textureOffset.x + _fontDetails[charId].posX, (int)_textureOffset.y + _fontDetails[charId].posY, _fontDetails[charId].w, _fontDetails[charId].h, _manager.textureSize ); // NOTE: This contains a bugfix from the previous version where offsetx was being used // in the wrong spot according to the angelcode spec. xadvance is the complete character width // and offsetx is supposed to be used only during character rendering, not during cursor advance. // Please note that yPos already has offsety built in. var rect = new Rect( xPos + _fontDetails[charId].offsetx* scale, yPos, _fontDetails[charId].w, _fontDetails[charId].h); if( sprite == null ) { sprite = new UISprite( rect, depth, uvRect, false ); _manager.addSprite( sprite ); } else { sprite.uvFrame = uvRect; sprite.position = new Vector3( rect.x, -rect.y, depth ); sprite.setSize( rect.width, rect.height ); } // We scale the sprite this way so it will work with the container clipping sprite.autoRefreshPositionOnScaling = false; sprite.scale = new Vector3( scale, scale, 1 ); return sprite; }
/// <summary> /// Shortcut for adding a new sprite using the raw materials /// </summary> private UISprite addSprite( Rect frame, UIUVRect uvFrame, int depth, bool gameObjectOriginInCenter ) { // Create and initialize the new sprite UISprite newSprite = new UISprite( frame, depth, uvFrame, gameObjectOriginInCenter ); addSprite( newSprite ); return newSprite; }
public void setJoystickHighlightedFilename(string filename) { var textureInfo = _manager.textureInfoForFilename(filename); highlightedUVframe = textureInfo.uvRect; }
public UITouchableSprite( Rect frame, int depth, UIUVRect uvFrame ):base( frame, depth, uvFrame ) { _tempUVframe = uvFrame; }
// constructor for when the need to have a centered UISprite arises (I'm looking at you UIKnob) public UITouchableSprite(Rect frame, int depth, UIUVRect uvFrame, bool gameObjectOriginInCenter) : base(frame, depth, uvFrame, gameObjectOriginInCenter) { }
public UITouchableSprite(Rect frame, int depth, UIUVRect uvFrame) : base(frame, depth, uvFrame) { _tempUVframe = uvFrame; }
public UIColorPicker(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, Vector2 textureCoords) : base(frame, depth, uvFrame) { //We store the coordinates of the top left of the subtexture this.textureCoords = textureCoords; manager.addTouchableSprite(this); }
// Sets the image to be displayed when the joystick is highlighted public void setJoystickHighlightedFilename( string filename ) { var textureInfo = _manager.textureInfoForFilename( filename ); highlightedUVframe = textureInfo.uvRect; }
/// <summary> /// Initializes a new instance of the <see cref="UISlice9"/> class. /// </summary> /// <param name='manager'> /// Manager. /// </param> /// <param name='frame'> /// Frame. /// </param> /// <param name='depth'> /// Depth. /// </param> /// <param name='uvFrame'> /// Uv frame. /// </param> /// <param name='highlightedUVframe'> /// Highlighted U vframe. /// </param> /// <param name='width'> /// Final width /// </param> /// <param name='height'> /// Final height /// </param> /// <param name='sTP'> /// Top Margin /// </param> /// <param name='sRT'> /// Right Margin /// </param> /// <param name='sBT'> /// Bottom Margin /// </param> /// <param name='sLT'> /// Left Margin /// </param> public UISlice9(UIToolkit manager, Rect frame, int depth, UIUVRect uvFrame, UIUVRect highlightedUVframe, int width, int height, int sTP, int sRT, int sBT, int sLT) : base(frame, depth, uvFrame) { // If a highlighted frame has not yet been set use the normalUVframe if (highlightedUVframe == UIUVRect.zero) { highlightedUVframe = uvFrame; } this.highlightedUVframe = highlightedUVframe; int stretchedWidth = width - (sLT + sRT); int stretchedHeight = height - (sTP + sBT); this.manager = manager; // Top Left spriteSlices[0] = new UISprite(new Rect(frame.x, frame.y, sLT, sTP), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y, sLT, sTP, manager.textureSize)); spriteSlices[0].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[0]); // Top Middle spriteSlices[1] = new UISprite(new Rect(frame.x + sLT, frame.y, stretchedWidth, sTP), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y, uvFrame.frame.width - (sRT + sLT), sTP, manager.textureSize)); spriteSlices[1].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[1]); // Top Right spriteSlices[2] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y, sRT, sTP), depth, new UIUVRect(uvFrame.frame.x + sLT + (uvFrame.frame.width - (sRT + sLT)), uvFrame.frame.y, sRT, sTP, manager.textureSize)); spriteSlices[2].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[2]); // Middle Left spriteSlices[3] = new UISprite(new Rect(frame.x, frame.y + sTP, sLT, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y + sTP, sLT, uvFrame.frame.height - (sTP + sBT), manager.textureSize)); spriteSlices[3].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[3]); // Middle Middle spriteSlices[4] = new UISprite(new Rect(frame.x + sLT, frame.y + sTP, stretchedWidth, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y + sTP, uvFrame.frame.height - (sTP + sBT), (int)frame.width - (sLT + sRT), manager.textureSize)); spriteSlices[4].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[4]); // Middle Right spriteSlices[5] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y + sTP, sRT, stretchedHeight), depth, new UIUVRect(uvFrame.frame.x + (uvFrame.frame.width - sRT), uvFrame.frame.y + sTP, sRT, uvFrame.frame.height - (sBT + sTP), manager.textureSize)); spriteSlices[5].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[5]); // Bottom Left spriteSlices[6] = new UISprite(new Rect(frame.x, frame.y + sTP + stretchedHeight, sLT, sBT), depth, new UIUVRect(uvFrame.frame.x, uvFrame.frame.y + (uvFrame.frame.height - sBT), sLT, sBT, manager.textureSize)); spriteSlices[6].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[6]); // Bottom Middle spriteSlices[7] = new UISprite(new Rect(frame.x + sLT, frame.y + sTP + stretchedHeight, stretchedWidth, sBT), depth, new UIUVRect(uvFrame.frame.x + sLT, uvFrame.frame.y + (uvFrame.frame.height - sBT), uvFrame.frame.width - (sLT + sRT), sBT, manager.textureSize)); spriteSlices[7].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[7]); // Bottom Right spriteSlices[8] = new UISprite(new Rect(frame.x + sLT + stretchedWidth, frame.y + sTP + stretchedHeight, sRT, sBT), depth, new UIUVRect(uvFrame.frame.x + sLT + (uvFrame.frame.width - (sRT + sLT)), uvFrame.frame.y + (uvFrame.frame.height - sBT), sRT, sBT, manager.textureSize)); spriteSlices[8].client.transform.parent = this.client.transform; manager.addSprite(spriteSlices[8]); this.setSize(width, height); manager.addTouchableSprite(this); }