Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MileyHollenberg committed Jun 6, 2020
0 parents commit 435ca2f
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

8 changes: 8 additions & 0 deletions Editor.meta

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

30 changes: 30 additions & 0 deletions Editor/RIgidbodyCenterOfMassEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MegaTools.Utils;
using UnityEditor;
using UnityEngine;

namespace MegaTools.Editor.Utils
{
[CustomEditor(typeof(RigidbodyCenterOfMass))]
public class RigidbodyCenterOfMassEditor : UnityEditor.Editor
{
private void OnSceneGUI()
{
RigidbodyCenterOfMass rb = target as RigidbodyCenterOfMass;

EditorGUI.BeginChangeCheck();

Handles.color = new Color(1f, 0.18f, 0.24f, 0.5f);
Handles.SphereHandleCap(0, rb.transform.TransformPoint(rb.CenterOfMass), Quaternion.identity, 0.25f,
EventType.Repaint);

Vector3 newTargetPosition =
Handles.PositionHandle(rb.transform.TransformPoint(rb.CenterOfMass), Quaternion.identity);

if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(rb, "Change Center Of Mass Position");
rb.CenterOfMass = newTargetPosition - rb.transform.position;
}
}
}
}
3 changes: 3 additions & 0 deletions Editor/RIgidbodyCenterOfMassEditor.cs.meta

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

17 changes: 17 additions & 0 deletions Editor/RigidbodyCenterOfMassEditor.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "RigidbodyCenterOfMassEditor.Editor",
"references": [
"GUID:82f26132c37a5ed4a80fdbb22a7f013e"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/RigidbodyCenterOfMassEditor.Editor.asmdef.meta

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

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Miley Hollenberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions LICENSE.md.meta

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

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Rigidbody Center Of Mass Editor
Allows you to change the center of mass of Rigidbodies within the Unity editor

# Usage
Add the `RigidbodyCenterOfMass` component to an object with a `Rigidbody` component (one will be created if it doesn't exist already) and modify the X,Y,Z position of the center of mass either through the inspector or the red sphere in the scene
7 changes: 7 additions & 0 deletions 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 Scripts.meta

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

21 changes: 21 additions & 0 deletions Scripts/RigidbodyCenterOfMass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;

namespace MegaTools.Utils
{
[RequireComponent(typeof(Rigidbody))]
public class RigidbodyCenterOfMass : MonoBehaviour
{
public Vector3 CenterOfMass = new Vector3(0, 0, 0);
private Rigidbody _rb;

private void Awake()
{
_rb = GetComponent<Rigidbody>();
}

private void Start()
{
_rb.centerOfMass = CenterOfMass;
}
}
}
11 changes: 11 additions & 0 deletions Scripts/RigidbodyCenterOfMass.cs.meta

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

13 changes: 13 additions & 0 deletions Scripts/RigidbodyCenterOfMassEditor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "RigidbodyCenterOfMassEditor",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Scripts/RigidbodyCenterOfMassEditor.asmdef.meta

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

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "io.megamiley.rigidbody-center-of-mass-editor",
"version": "1.0.0",
"displayName": "Rigidbody Center Of Mass Editor",
"description": "Allows you to change the Center of Mass of a Rigidbody inside the editor",
"unity": "2018.1",
"keywords": [
"editor",
"rigidbody",
"center of mass"
],
"author": {
"name": "Miley Hollenberg",
"email": "[email protected]",
"url": "https://github.com/MileyHollenberg/RigidbodyCenterOfMassEditor"
}
}
7 changes: 7 additions & 0 deletions package.json.meta

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

0 comments on commit 435ca2f

Please sign in to comment.