Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit b9e9876

Browse files
author
DaZombieKiller
committed
Add more extension methods.
1 parent 7895891 commit b9e9876

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using UnityEngine;
2+
3+
namespace PluginManager.Plugin.Extensions
4+
{
5+
/// <summary>Extension methods for the Matrix4x4 class.</summary>
6+
public static class Matrix4x4Extensions
7+
{
8+
/// <summary>Decomposes a Matrix4x4.</summary>
9+
/// <param name="self">The matrix.</param>
10+
/// <param name="transform">The transform component.</param>
11+
/// <param name="rotate">The rotate component.</param>
12+
/// <param name="scale">The scale component.</param>
13+
public static void Decompose(this Matrix4x4 self, out Vector3 transform, out Quaternion rotate, out Vector3 scale)
14+
{
15+
transform = self.GetColumn(3);
16+
17+
rotate = Quaternion.LookRotation(
18+
self.GetColumn(2),
19+
self.GetColumn(1)
20+
);
21+
22+
scale = new Vector3(
23+
self.GetColumn(0).magnitude,
24+
self.GetColumn(1).magnitude,
25+
self.GetColumn(2).magnitude
26+
);
27+
}
28+
}
29+
}

Source/PluginManager/Plugin/Extensions/Texture2DExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public static Texture2D GetReadable(this Texture2D self)
1414
var prevRender = RenderTexture.active;
1515

1616
var newRender = RenderTexture.GetTemporary(self.width, self.height, 0,
17-
self.format.GetRenderTextureFormat(),
18-
RenderTextureReadWrite.Linear);
17+
self.format.GetRenderTextureFormat(), RenderTextureReadWrite.Linear);
1918

2019
Graphics.Blit(self, newRender);
2120
RenderTexture.active = newRender;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using UnityEngine;
2+
3+
namespace PluginManager.Plugin.Extensions
4+
{
5+
/// <summary>Extension methods for the Texture class.</summary>
6+
public static class TextureExtensions
7+
{
8+
/// <summary>Returns the width and height of a texture as a Vector2.</summary>
9+
/// <param name="self">The texture.</param>
10+
/// <returns>The dimensions of the texture.</returns>
11+
public static Vector2 GetDimensions(this Texture self)
12+
{
13+
return new Vector2(self.width, self.height);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)