啥都不说,直接上代码
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[ExecuteInEditMode]
public class testmesh : Image
{
[SerializeField]
public float OffsetMax =0.5f;
private Matrix2x2 trans = new Matrix2x2(1,
OffsetMax , 0, 1);//正方体变平行四边形的矩阵
protected override void OnPopulateMesh(VertexHelper toFill)
{
base.OnPopulateMesh(toFill);
UIVertex pos2 = new UIVertex();
UIVertex pos3 = new UIVertex();
toFill.PopulateUIVertex(ref pos2, 1);//取出左上顶点
toFill.PopulateUIVertex(ref pos3,2);//取出右下顶点
pos2.position = trans*pos2.position;
pos3.position = trans * pos3.position;
toFill.SetUIVertex(pos2, 1);
toFill.SetUIVertex(pos3, 2);
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SVGImporter;
using UnityEngine.UI;
public class testSvgnew : SVGImage
{
private List<UIVertex> allUiVertices = new List<UIVertex>();
private Matrix2x2 trans = new Matrix2x2(1, 1, 0, 1);
protected override void OnPopulateMesh(VertexHelper vh)
{
base.OnPopulateMesh(vh);
if (sharedMesh == null) { base.OnPopulateMesh(vh); return; }
for (int i = 0; i < vh.currentVertCount; i++)
{
UIVertex tempos = new UIVertex();
vh.PopulateUIVertex(ref tempos, i);
tempos.position = trans * tempos.position;
vh.SetUIVertex(tempos, i);
}
}
}
/*******************************************************************
** 作者:luohong
** 时间:2017/5/31 15:03:14
** 文件名:Matrix2x2
** 版本:V1.0.1
** 说明:
**
** 修改者:
** 修改说明:
********************************************************************/
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
public struct Matrix2x2
{
public Matrix2x2(float m00, float m01, float m10, float m11)
{
this.m00 = m00;
this.m10 = m10;
this.m01 = m01;
this.m11 = m11;
}
public float m00;
public float m10;
public float m01;
public float m11;
public float this[int row, int column]
{
get
{
return this[row + column * 2];
}
set
{
this[row + column * 2] = value;
}
}
public float this[int index]
{
get
{
switch (index)
{
case 0:
return this.m00;
case 1:
return this.m10;
case 2:
return this.m01;
case 3:
return this.m11;
default:
throw new IndexOutOfRangeException("Invalid matrix index!");
}
}
set
{
switch (index)
{
case 0:
this.m00 = value;
break;
case 1:
this.m10 = value;
break;
case 2:
this.m01 = value;
break;
case 3:
this.m11 = value;
break;
default:
throw new IndexOutOfRangeException("Invalid matrix index!");
}
}
}
public static Vector2 operator *(Matrix2x2 lhs, Vector2 v)
{
Vector2 Vector2;
Vector2.x = (float)((double)lhs.m00 * (double)v.x + (double)lhs.m01 * (double)v.y);
Vector2.y = (float)((double)lhs.m10 * (double)v.x + (double)lhs.m11 * (double)v.y);
return Vector2;
}
public static Vector3 operator *(Matrix2x2 lhs, Vector3 v)
{
Vector3 Vector2;
Vector2.x = (float)((double)lhs.m00 * (double)v.x + (double)lhs.m01 * (double)v.y);
Vector2.y = (float)((double)lhs.m10 * (double)v.x + (double)lhs.m11 * (double)v.y);
Vector2.z = v.z;
return Vector2;
}
/// <summary>
///
/// <para>
/// Get a column of the matrix.
/// </para>
///
/// </summary>
/// <param name="i"/>
public Vector2 GetColumn(int i)
{
return new Vector2(this[0, i], this[1, i]);
}
/// <summary>
///
/// <para>
/// Returns a row of the matrix.
/// </para>
///
/// </summary>
/// <param name="i"/>
public Vector2 GetRow(int i)
{
return new Vector2(this[i, 0], this[i, 1]);
}
/// <summary>
///
/// <para>
/// Sets a column of the matrix.
/// </para>
///
/// </summary>
/// <param name="i"/><param name="v"/>
public void SetColumn(int i, Vector2 v)
{
this[0, i] = v.x;
this[1, i] = v.y;
}
/// <summary>
///
/// <para>
/// Sets a row of the matrix.
/// </para>
///
/// </summary>
/// <param name="i"/><param name="v"/>
public void SetRow(int i, Vector2 v)
{
this[i, 0] = v.x;
this[i, 1] = v.y;
}
/// <summary>
///
/// <para>
/// Returns a nicely formatted string for this matrix.
/// </para>
///
/// </summary>
/// <param name="format"/>
public string ToString(string format)
{
string fmt = "{0}\t{1}\t{2}\t{3}\n{4}\t{5}\t{6}\t{7}\n{8}\t{9}\t{10}\t{11}\n{12}\t{13}\t{14}\t{15}\n";
object[] objArray = new object[16];
int index1 = 0;
string str1 = this.m00.ToString(format);
objArray[index1] = (object)str1;
int index2 = 1;
string str2 = this.m01.ToString(format);
objArray[index2] = (object)str2;
int index3 = 2;
int index5 = 4;
string str5 = this.m10.ToString(format);
objArray[index5] = (object)str5;
int index6 = 5;
string str6 = this.m11.ToString(format);
objArray[index6] = (object)str6;
int index7 = 6;
return string.Format(fmt, objArray);
}
public void Add(int i)
{
throw new NotImplementedException();
}
}
QQ交流群:162136059