Skip to content

Commit

Permalink
Merge pull request #1 from HankunYu/dev
Browse files Browse the repository at this point in the history
Add new package Utilis
  • Loading branch information
HankunYu authored Jul 22, 2024
2 parents b63ccf8 + f4ad3a3 commit c7b9c3b
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Packages/Utilis.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Packages/Utilis/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/Packages/Utilis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Utilis

A collection of useful utilities for Unity development.



### General

1. <u>ReverseNormals</u>
- require MeshFilter component, will reverse mesh normals after start



### Extensions

1. <u>GetAllChildren</u>
- return all children's transform
- Etc. transform.GetAllChildren

7 changes: 7 additions & 0 deletions Assets/Packages/Utilis/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Packages/Utilis/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Assets/Packages/Utilis/Runtime/ReverseNormals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using UnityEngine;

public class ReverseNormals : MonoBehaviour
{
private void Start()
{
var meshFilter = GetComponent<MeshFilter>();
if (meshFilter == null)
{
Debug.LogError("Mesh filter not found!");
return;
}

var mesh = meshFilter.mesh;
var normals = mesh.normals;

// 反转法线方向
for (var i = 0; i < normals.Length; i++)
{
normals[i] = -normals[i];
}

mesh.normals = normals;

// 重新计算顶点顺序以保持正确的渲染
for (var i = 0; i < mesh.subMeshCount; i++)
{
var triangles = mesh.GetTriangles(i);
for (var j = 0; j < triangles.Length; j += 3)
{
(triangles[j], triangles[j + 1]) = (triangles[j + 1], triangles[j]);
}

mesh.SetTriangles(triangles, i);
}
}
}
2 changes: 2 additions & 0 deletions Assets/Packages/Utilis/Runtime/ReverseNormals.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Assets/Packages/Utilis/Runtime/TransformExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using UnityEngine;

public static class TransformExtensions
{
/// <summary>
/// Get all children of a transform
/// </summary>
/// <param name="transform"></param>
/// <returns>List of all children transform</returns>
public static List<Transform> GetAllChildren(this Transform transform)
{
var children = new List<Transform>();
GetAllChildrenRecursive(transform, children);
return children;
}

private static void GetAllChildrenRecursive(Transform transform, List<Transform> children)
{
foreach (Transform child in transform)
{
children.Add(child);
GetAllChildrenRecursive(child, children);
}
}
}
2 changes: 2 additions & 0 deletions Assets/Packages/Utilis/Runtime/TransformExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Packages/Utilis/Runtime/com.hankun.utilis.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "com.hankun.utilis"
}
7 changes: 7 additions & 0 deletions Assets/Packages/Utilis/Runtime/com.hankun.utilis.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Packages/Utilis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "com.hankun.utilis",
"version": "1.0.0",
"displayName": "Utilis",
"description": "A collection of useful utilities for Unity development.",
"unity": "2020.3",
"author": {
"name": "hankun",
"email": "kmcyd1@gmail.com"
}
}
7 changes: 7 additions & 0 deletions Assets/Packages/Utilis/package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7b9c3b

Please sign in to comment.