Skip to content

Commit

Permalink
removed submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbabon committed Jun 9, 2022
1 parent 561af4c commit 5784584
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 1 deletion.
1 change: 0 additions & 1 deletion Packages/TransformsRecorder
Submodule TransformsRecorder deleted from 1b6dbd
8 changes: 8 additions & 0 deletions Packages/TransformsRecorder/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 Packages/TransformsRecorder/Editor/TransformRecorderEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(TransformRecorder))]
public class TransformsRecorderEditor : Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Record Transforms", EditorStyles.miniButton))
{
((TransformRecorder)target).RecordTransforms();
}
if (GUILayout.Button("Load Transforms", EditorStyles.miniButton))
{
((TransformRecorder)target).LoadTransforms();
}
DrawDefaultInspector ();
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "TransformsRecorder.Editor",
"references": [
"TransformsRecorder"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

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

8 changes: 8 additions & 0 deletions Packages/TransformsRecorder/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2022 Amit Netanel, Abbabon

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.
3 changes: 3 additions & 0 deletions Packages/TransformsRecorder/LICENSE.md.meta

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

46 changes: 46 additions & 0 deletions Packages/TransformsRecorder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Transforms Recorder

[![openupm]()
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FAbbabon%2FTransformsRecorder&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)

This tool can be used to record a complex hierarchy of GameObject's child transforms (during editor or runtime) in a ScriptableObject. This allows you to pose the character around your scene, take marketing screenshots, or anything similar.

More motivations and implementation details [can be found at my blog](https://abbabon.github.io/2020-11-09-serializing-transforms/)

# Install

## Open UPM

TransformsRecorder can be installed via [OpenUPM](https://openupm.com/). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli):

`openupm add com.mezookan.transforms-recorder`

## Git Dependency

You can add the package to your project as a [git upm dependency](https://docs.unity3d.com/Manual/upm-git.html).

Either add the following line to your project's `Packages/manifest.json` file's dependencies:

"com.mezookan.transforms-recorder":"https://github.com/abbabon/TransformsRecorder.git?path=Packages/TransformsRecorder",

or via the `Windows/PackageManager` menu, by adding the following git repo: `https://github.com/abbabon/TransformsRecorder.git?path=Packages/TransformsRecorder`

# How to use

1. Place the 'TransformRecorder' script on any object in your scene.
2. Drag the parent of the transform hierarchy you wish to record to the 'Parent Transform' field.
3. Create a scriptable object from TransformDataContainer by right clicking on you project window, and then `Create->ScriptableObjects->TransformDataContainer`
4. Drag the new TransformDataContainer to the TransformRecorder's relevant field.

You can now save the transform hierarchy by pressing the 'Record Transforms' button, or load with 'Load Transforms'.
Just remember to create a scriptable object for each pose / sate. I encourage you to experiment further and expand the system.

An example scene is setup in the [repo](https://github.com/Abbabon/TransformsRecorder) (not in the package), so you can see it in action.

# License

Free to use under the [MIT License](https://opensource.org/licenses/MIT)

# Third Party Notices

'The Boss' Model and animations supplied by Adobe (taken from Mixamo.com).
7 changes: 7 additions & 0 deletions Packages/TransformsRecorder/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 Packages/TransformsRecorder/Runtime.meta

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

10 changes: 10 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using UnityEngine;

[Serializable]
public class TransformData
{
public Vector3 Position;
public Quaternion Rotation;
public Vector3 Scale;
}
3 changes: 3 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformData.cs.meta

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

7 changes: 7 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformDataContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using UnityEngine;

[CreateAssetMenu(fileName = "TransformDataContainer", menuName = "ScriptableObjects/TransformDataContainer")]
public class TransformDataContainer : ScriptableObject
{
public TransformNode parentNode;
}

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

9 changes: 9 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;

[Serializable]
public class TransformNode
{
public TransformData NodeTransformData;
public List<TransformNode> ChildrenTransformsData;
}
3 changes: 3 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformNode.cs.meta

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

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

public class TransformRecorder : MonoBehaviour
{
[SerializeField] private Transform _transformsParent;
[SerializeField] private TransformDataContainer _transformDataContainer;

public void RecordTransforms()
{
if (_transformDataContainer != null)
{
_transformDataContainer.parentNode = RecordTransformsRecursively(_transformsParent);
}
}

public void LoadTransforms()
{
if (_transformDataContainer != null)
{
LoadTransformsRecursively(_transformsParent, _transformDataContainer.parentNode);
}
}

private TransformNode RecordTransformsRecursively(Transform parent)
{
var directChildren = GetDirectChildrenOfTransform(parent);

var nodeData = new TransformNode
{
NodeTransformData = new TransformData
{
Position = parent.localPosition,
Rotation = parent.localRotation,
Scale = parent.localScale
}
};

if (directChildren.Count > 0)
{
nodeData.ChildrenTransformsData = new List<TransformNode>();
foreach (var child in directChildren)
{
nodeData.ChildrenTransformsData.Add(RecordTransformsRecursively(child));
}
}
else
{
nodeData.ChildrenTransformsData = null;
}

return nodeData;
}

private void LoadTransformsRecursively(Transform parent, TransformNode nodeNode)
{
var directChildren = GetDirectChildrenOfTransform(parent);

if (directChildren.Count > 0)
{
for (var nodeIndex = 0; nodeIndex < nodeNode.ChildrenTransformsData.Count; nodeIndex++)
{
LoadTransformsRecursively(directChildren[nodeIndex], nodeNode.ChildrenTransformsData[nodeIndex]);
}
}

parent.localPosition = nodeNode.NodeTransformData.Position;
parent.localRotation = nodeNode.NodeTransformData.Rotation;
parent.localScale = nodeNode.NodeTransformData.Scale;
}

private List<Transform> GetDirectChildrenOfTransform(Transform parent)
{
var directChildren = new List<Transform>();
foreach (Transform directChild in parent)
{
directChildren.Add(directChild);
}
return directChildren;
}
}
11 changes: 11 additions & 0 deletions Packages/TransformsRecorder/Runtime/TransformRecorder.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 Packages/TransformsRecorder/Runtime/TransformsRecorder.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "TransformsRecorder"
}

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

11 changes: 11 additions & 0 deletions Packages/TransformsRecorder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "com.mezookan.transforms-recorder",
"displayName": "Transforms Recorder",
"version": "1.0.0",
"description": "Transforms Recorder",
"keywords": [
"3d",
"modeling"
],
"unity": "2019.4"
}
7 changes: 7 additions & 0 deletions Packages/TransformsRecorder/package.json.meta

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

0 comments on commit 5784584

Please sign in to comment.