This commit is contained in:
1605296300@qq.com
2022-08-19 02:56:00 +08:00
parent 46be47a262
commit 5fb42a0fe7
7 changed files with 70 additions and 141 deletions
-8
View File
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 020a75ca2e43f90458872197fe59530d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
-66
View File
@@ -1,66 +0,0 @@
// Copyright (c) 2014 Luminary LLC
// Licensed under The MIT License (See LICENSE for full text)
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Reflection;
[CustomPropertyDrawer(typeof(SetPropertyAttribute))]
public class SetPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Rely on the default inspector GUI
EditorGUI.BeginChangeCheck ();
EditorGUI.PropertyField(position, property, label);
// Update only when necessary
SetPropertyAttribute setProperty = attribute as SetPropertyAttribute;
if (EditorGUI.EndChangeCheck())
{
// When a SerializedProperty is modified the actual field does not have the current value set (i.e.
// FieldInfo.GetValue() will return the prior value that was set) until after this OnGUI call has completed.
// Therefore, we need to mark this property as dirty, so that it can be updated with a subsequent OnGUI event
// (e.g. Repaint)
setProperty.IsDirty = true;
}
else if (setProperty.IsDirty)
{
// The propertyPath may reference something that is a child field of a field on this Object, so it is necessary
// to find which object is the actual parent before attempting to set the property with the current value.
object parent = GetParentObjectOfProperty(property.propertyPath, property.serializedObject.targetObject);
Type type = parent.GetType();
PropertyInfo pi = type.GetProperty(setProperty.Name);
if (pi == null)
{
Debug.LogError("Invalid property name: " + setProperty.Name + "\nCheck your [SetProperty] attribute");
}
else
{
// Use FieldInfo instead of the SerializedProperty accessors as we'd have to deal with every
// SerializedPropertyType and use the correct accessor
pi.SetValue(parent, fieldInfo.GetValue(parent), null);
}
setProperty.IsDirty = false;
}
}
private object GetParentObjectOfProperty(string path, object obj)
{
string[] fields = path.Split('.');
// We've finally arrived at the final object that contains the property
if (fields.Length == 1)
{
return obj;
}
// We may have to walk public or private fields along the chain to finding our container object, so we have to allow for both
FieldInfo fi = obj.GetType().GetField(fields[0], BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
obj = fi.GetValue(obj);
// Keep searching for our object that contains the property
return GetParentObjectOfProperty(string.Join(".", fields, 1, fields.Length - 1), obj);
}
}
-11
View File
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f52efb0d2eca47e40ab251ae0e23e311
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+68 -28
View File
@@ -67,13 +67,15 @@ namespace Gallop
}
}
private void Update()
private void FixedUpdate()
{
bool changed = false;
for (int i = 0; i < EyeBrowMorphs.Count; i++)
{
if(EyeBrowMorphs[i].LastWeight!= EyeBrowMorphs[i].Weight)
{
ChangeMorph();
changed = true;
EyeBrowMorphs[i].LastWeight = EyeBrowMorphs[i].Weight;
}
}
@@ -81,7 +83,7 @@ namespace Gallop
{
if (EyeMorphs[i].LastWeight != EyeMorphs[i].Weight)
{
ChangeMorph();
changed = true;
EyeMorphs[i].LastWeight = EyeMorphs[i].Weight;
}
}
@@ -89,10 +91,12 @@ namespace Gallop
{
if (MouthMorphs[i].LastWeight != MouthMorphs[i].Weight)
{
ChangeMorph();
changed = true;
MouthMorphs[i].LastWeight = MouthMorphs[i].Weight;
}
}
if (changed)ChangeMorph();
}
public void ChangeMorph()
@@ -105,17 +109,13 @@ namespace Gallop
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget==1)
if (!trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)],trs._position,morph.Weight);
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)],trs._scale, morph.Weight);
}
else
{
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles+ (trs._rotation* morph.Weight));
bone.localPosition += trs._position*morph.Weight;
bone.localScale += trs._scale* morph.Weight;
var tmp = bone.localRotation.eulerAngles;
tmp += (trs._rotation * morph.Weight);
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles + (trs._rotation * morph.Weight));
bone.localPosition += trs._position * morph.Weight;
bone.localScale += trs._scale * morph.Weight;
}
};
}
@@ -128,13 +128,7 @@ namespace Gallop
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget == 1)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)], trs._position, morph.Weight);
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)], trs._scale, morph.Weight);
}
else
if (!trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles + (trs._rotation * morph.Weight));
bone.localPosition += trs._position * morph.Weight;
@@ -151,13 +145,7 @@ namespace Gallop
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget == 1)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)], trs._position, morph.Weight);
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)], trs._scale, morph.Weight);
}
else
if (!trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles + (trs._rotation * morph.Weight));
bone.localPosition += trs._position * morph.Weight;
@@ -166,6 +154,58 @@ namespace Gallop
};
}
}
foreach (FacialMorph morph in EyeBrowMorphs)//´¦Àí¸²¸Ç±íÇé
{
foreach (TrsArray trs in morph.trsArray)
{
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(bone.localRotation.eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(bone.localPosition, trs._position, morph.Weight);
bone.localScale = Vector3.Lerp(bone.localScale, trs._scale, morph.Weight);
}
};
}
}
foreach (FacialMorph morph in EyeMorphs)
{
foreach (TrsArray trs in morph.trsArray)
{
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(bone.localRotation.eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(bone.localPosition, trs._position, morph.Weight);
bone.localScale = Vector3.Lerp(bone.localScale, trs._scale, morph.Weight);
}
};
}
}
foreach (FacialMorph morph in MouthMorphs)
{
foreach (TrsArray trs in morph.trsArray)
{
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
if (bone)
{
if (trs.IsOverrideTarget)
{
bone.localRotation = Quaternion.Euler(Vector3.Lerp(bone.localRotation.eulerAngles, trs._rotation, morph.Weight));
bone.localPosition = Vector3.Lerp(bone.localPosition, trs._position, morph.Weight);
bone.localScale = Vector3.Lerp(bone.localScale, trs._scale, morph.Weight);
}
};
}
}
}
public void FacialReset()
+2 -2
View File
@@ -34,11 +34,11 @@ public class StringValuePair
public class TrsArray
{
public string _path;
public int _isValidScaleTransform;
public bool _isValidScaleTransform;
public Vector3 _position;
public Vector3 _scale;
public Vector3 _rotation;
public int IsOverrideTarget;
public bool IsOverrideTarget;
}
[System.Serializable]
@@ -1,15 +0,0 @@
// Copyright (c) 2014 Luminary LLC
// Licensed under The MIT License (See LICENSE for full text)
using UnityEngine;
using System.Collections;
public class SetPropertyAttribute : PropertyAttribute
{
public string Name { get; private set; }
public bool IsDirty { get; set; }
public SetPropertyAttribute(string name)
{
this.Name = name;
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5d72052b442fcfe42b1433eeb25729bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: