Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Editor/Animation/ShapeKeyDriver.meta

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

54 changes: 54 additions & 0 deletions Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tenta não incluir System do C# que gera conflitos com os tipos dentro do UnityEngine

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace BitStrap
{
[CustomPropertyDrawer(typeof(ShapeKeyDefinition))]
public class ShapeKeyDrawer : PropertyDrawer
{
string[] blendShapeNames = null;

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
PropertyDrawerHelper.LoadAttributeTooltip( this, label );

var behaviour = property.serializedObject.targetObject as MonoBehaviour;

SkinnedMeshRenderer skinnedMeshRenderer = null;
var nameProperty = property.GetMemberProperty<ShapeKeyDefinition>( p => p.name );

if( behaviour != null )
{
skinnedMeshRenderer = behaviour.GetComponent<SkinnedMeshRenderer>();
}

if (skinnedMeshRenderer != null)
{
if (blendShapeNames == null)
{
var blendShapeCount = skinnedMeshRenderer.sharedMesh.blendShapeCount;
blendShapeNames = new string[blendShapeCount];
for (int i = 0; i < blendShapeCount; i++)
{
blendShapeNames[i] = skinnedMeshRenderer.sharedMesh.GetBlendShapeName(i);
}
}

int currentIndex = Array.IndexOf(blendShapeNames, nameProperty.stringValue);

EditorGUI.BeginChangeCheck();
currentIndex = EditorGUI.Popup( position, label.text, currentIndex, blendShapeNames );

if( EditorGUI.EndChangeCheck() )
{
nameProperty.stringValue = blendShapeNames[currentIndex];
property.serializedObject.ApplyModifiedProperties();
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyDrawer.cs.meta

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

198 changes: 198 additions & 0 deletions Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyPositionConfigDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aqui também tá incluindo System

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace BitStrap
{
[CustomPropertyDrawer(typeof(ShapeKeyPositionConfig))]
public class ShapeKeyPositionConfigDrawer : PropertyDrawer
{
public override float GetPropertyHeight( SerializedProperty property, GUIContent label )
{
if (property.isExpanded)
return EditorHelper.singleLineHeight * 8;

return EditorHelper.singleLineHeight;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
PropertyDrawerHelper.LoadAttributeTooltip( this, label );
var rowFoldout = position.Row(0);
var rowDriverTransform = position.Row(1);
var rowPositionType = position.Row(2);
var rowAxis = position.Row(3);
var rowValues = position.Row(4);
var rowCurve = position.Row(5);

property.isExpanded = EditorGUI.Foldout(rowFoldout, property.isExpanded, label);

if (!property.isExpanded)
return;

using (IndentLevel.Do(EditorGUI.indentLevel + 1))
using (LabelWidth.Do(128.0f))
{
var driverTransformProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.driverTransform);
EditorGUI.PropertyField(rowDriverTransform, driverTransformProperty);

var positionTypeProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.positionType);
EditorGUI.PropertyField(rowPositionType, positionTypeProperty);

var startPropertyLabel = new GUIContent("Start Position");
var endPropertyLabel = new GUIContent("End Position");

switch ((ShapeKeyPositionConfig.PositionType)positionTypeProperty.enumValueIndex)
{
case ShapeKeyPositionConfig.PositionType.OneAxis:
{
var axisProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.positionOneAxis);
var positionAxisLabel = new GUIContent("Axis");
EditorGUI.PropertyField(rowAxis, axisProperty, positionAxisLabel);

rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect);
leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect);
rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect);

var startValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.oneAxisStartPosition);
EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel);

if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetOneAxis(axisProperty, startValueProperty, driverTransformProperty);
}

var endValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.oneAxisEndPosition);
EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel);

if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetOneAxis(axisProperty, endValueProperty, driverTransformProperty);
}

break;
}
case ShapeKeyPositionConfig.PositionType.TwoAxis:
{
var axisProperty = property.GetMemberProperty<ShapeKeyPositionConfig>(k => k.positionTwoAxis);
var positionAxisLabel = new GUIContent("Axis");
EditorGUI.PropertyField(rowAxis, axisProperty, positionAxisLabel);

rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect);
leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect);
rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect);

var startValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.twoAxisStartPosition);
EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel);

if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetTwoAxis(axisProperty, startValueProperty, driverTransformProperty);
}

var endValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>( k => k.twoAxisEndPosition);
EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel);

if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetTwoAxis(axisProperty, endValueProperty, driverTransformProperty);
}

break;
}
case ShapeKeyPositionConfig.PositionType.ThreeAxis:
{
rowValues.Left(rowValues.width * 0.5f, out var leftRect).Expand(out var rightRect);
leftRect.Right(26.0f, out var leftButtonRect).Left(-2.0f).Expand(out var outLeftRect);
rightRect.Right(26.0f, out var rightButtonRect).Left(-2.0f).Expand(out var outRightRect);

var startValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>(k => k.threeAxisStartPosition);
EditorGUI.PropertyField(outLeftRect, startValueProperty, startPropertyLabel);

if (GUI.Button(leftButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetThreeAxis(startValueProperty, driverTransformProperty);
}

var endValueProperty = property.GetMemberProperty<ShapeKeyPositionConfig>(k => k.threeAxisEndPosition);
EditorGUI.PropertyField(outRightRect, endValueProperty, endPropertyLabel);

if (GUI.Button(rightButtonRect, EditorGUIUtility.IconContent("d_Transform Icon")))
{
SetThreeAxis(endValueProperty, driverTransformProperty);
}

break;
}
}
var interpolationCurve = property.GetMemberProperty<ShapeKeyRotationConfig>( k => k.interpolationCurve);
var curveLabel = new GUIContent("Curve");

rowCurve.height = EditorHelper.singleLineHeight * 3;
EditorGUI.PropertyField(rowCurve, interpolationCurve, curveLabel);
}
}

private void SetOneAxis(SerializedProperty axisProperty, SerializedProperty propertyToSet,
SerializedProperty driverTransformProperty)
{
var driverPos = GetDriverPosition(driverTransformProperty.objectReferenceValue as Transform);

switch ((ShapeKeyPositionConfig.PositionOneAxis)axisProperty.enumValueIndex)
{
case ShapeKeyPositionConfig.PositionOneAxis.X:
propertyToSet.floatValue = driverPos.x;
break;
case ShapeKeyPositionConfig.PositionOneAxis.Y:
propertyToSet.floatValue = driverPos.y;
break;
case ShapeKeyPositionConfig.PositionOneAxis.Z:
propertyToSet.floatValue = driverPos.z;
break;
}
}

private void SetTwoAxis(SerializedProperty axisProperty, SerializedProperty propertyToSet,
SerializedProperty driverTransformProperty)
{
var driverPos = GetDriverPosition(driverTransformProperty.objectReferenceValue as Transform);

switch ((ShapeKeyPositionConfig.PositionTwoAxis)axisProperty.enumValueIndex)
{
case ShapeKeyPositionConfig.PositionTwoAxis.XY:
propertyToSet.vector2Value = new Vector2(driverPos.x, driverPos.y);
break;
case ShapeKeyPositionConfig.PositionTwoAxis.XZ:
propertyToSet.vector2Value = new Vector2(driverPos.x, driverPos.z);
break;
case ShapeKeyPositionConfig.PositionTwoAxis.YX:
propertyToSet.vector2Value = new Vector2(driverPos.y, driverPos.x);
break;
case ShapeKeyPositionConfig.PositionTwoAxis.YZ:
propertyToSet.vector2Value = new Vector2(driverPos.y, driverPos.z);
break;
case ShapeKeyPositionConfig.PositionTwoAxis.ZY:
propertyToSet.vector2Value = new Vector2(driverPos.z, driverPos.y);
break;
case ShapeKeyPositionConfig.PositionTwoAxis.ZX:
propertyToSet.vector2Value = new Vector2(driverPos.z, driverPos.x);
break;
}
}

private void SetThreeAxis(SerializedProperty propertyToSet, SerializedProperty driverTransformProperty)
{
var driverPos = GetDriverPosition(driverTransformProperty.objectReferenceValue as Transform);

propertyToSet.vector3Value = driverPos;
}


private Vector3 GetDriverPosition(Transform transform)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precisa dessa função já que ela quase só retorna o argumento dela?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, eu acho que fica mais organizadinho dessa forma, vou manter assim pra ficar menos doidera.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fiz tudo ficar inline, esquece o comentário desse maluco aí!

{
return transform.position;
}
}
}

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

55 changes: 55 additions & 0 deletions Assets/Editor/Animation/ShapeKeyDriver/ShapeKeyRecipeDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mais um using System

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace BitStrap
{
[CustomPropertyDrawer(typeof(ShapeKeyRecipe))]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

é uma boa tirar essa linha vazia que deixa mais claro que o atributo é referente a essa classe abaixo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É pq o Rider da uns espaços doidos. Tirei.

public class ShapeKeyRecipeDrawer : PropertyDrawer
{
public override float GetPropertyHeight( SerializedProperty property, GUIContent label )
{
if (property.isExpanded)
return EditorHelper.singleLineHeight * 10;

return EditorHelper.singleLineHeight;
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var row0 = position.Row(0);
var row1 = position.Row(1);
var row2 = position.Row(2);
var row3 = position.Row(3);
var row4 = position.Row(4);
var row5 = position.Row(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aqui também seria uma boa nomear mais explicito o que é cada linha


var shapeKeyProperty = property.GetMemberProperty<ShapeKeyRecipe>( k => k.shapeKeyDefinition);
EditorGUI.PropertyField(row0, shapeKeyProperty);

var driverTypeProperty = property.GetMemberProperty<ShapeKeyRecipe>( k => k.driverType);
EditorGUI.PropertyField(row1, driverTypeProperty);

switch ((ShapeKeyRecipe.DriverType)driverTypeProperty.enumValueIndex)
{
case ShapeKeyRecipe.DriverType.Rotation:
var shapeKeyRotationProperty = property.GetMemberProperty<ShapeKeyRecipe>( k => k.shapeKeyRotationConfig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

é uma boa envolver o case entre { ... } quando tem declaração de variável dentro porque o escopo do switch é um só pra todos os cases.

isso faz com que tu não possa declarar duas variaves com mesmo nome dentro de cases diferentes (a não ser que você ponha os {...}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dani

EditorGUI.PropertyField(row2, shapeKeyRotationProperty);
break;
case ShapeKeyRecipe.DriverType.Position:
var shapeKeyPositionProperty = property.GetMemberProperty<ShapeKeyRecipe>( k => k.shapeKeyPositionConfig);
EditorGUI.PropertyField(row2, shapeKeyPositionProperty);
break;
// case ShapeKeyRecipe.DriverType.MecanimParameter:
// break;
// case ShapeKeyRecipe.DriverType.Callback:
// break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dá pra tirar esses códigos comentados? ou é pra não se esquecer depois de implementar?
se for lembrete, talvez seja uma boa adicionar um // TODO: implement ou parecido

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adicionei o TODO aqui

}

}
}
}

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

Loading