Skip to content

Commit

Permalink
Bug fix update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaimi committed Nov 16, 2020
1 parent 165ba34 commit 07016a0
Show file tree
Hide file tree
Showing 23 changed files with 3,512 additions and 903 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ public override void OnInspectorGUI()
}
if (GUILayout.Button("Add All"))
{

foreach(string s in rawcachedRaceDNA)
{
AddSingleDNA(s);
}
}
GUILayout.EndHorizontal();

Expand Down Expand Up @@ -812,6 +815,9 @@ void GenerateSingleUMA()
ugb.InitialScaleFactor = ugb.editorInitialScaleFactor;
ugb.atlasResolution = ugb.editorAtlasResolution;


dca.activeRace.racedata.ResetDNA();

ugb.GenerateSingleUMA(dca.umaData);

ugb.fastGeneration = oldFastGen;
Expand Down Expand Up @@ -855,7 +861,7 @@ void UpdateCharacter()
private void AddSingleDNA(string theDna)
{
float value = 0.5f;
// todo: Get DNA from base race recipe, and

if (thisDCA.umaData != null)
{
var characterDNA = thisDCA.GetDNA();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public void GenerateSingleUMA()
private void CleanupGeneratedData()
{
List<GameObject> Cleaners = GetRenderers(gameObject);
Hide();
Hide(false);
foreach (GameObject go in Cleaners)
{
DestroyImmediate(go);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,21 @@ public override Dictionary<string, List<int>> IndexesForDnaNames

#region PRIVATE METHODS

private void ResetOnCharaterUpdated(UMAData umaData)
public void ResetOnCharaterUpdated(UMAData umaData)
{
_dnaAppliedTo.Remove(umaData.gameObject);
}

#endregion
#endregion

#region REQUIRED DYNAMICDNAPLUGIN METHODS
#region REQUIRED DYNAMICDNAPLUGIN METHODS
public override void Reset()
{
_dnaAppliedTo.Clear();
base.Reset();
}

public override void ApplyDNA(UMAData umaData, UMASkeleton skeleton, int dnaTypeHash)
public override void ApplyDNA(UMAData umaData, UMASkeleton skeleton, int dnaTypeHash)
{
//Add the reset listeners if we havent already
//we need this because if 'fastGeneration' is false we may still get another loop
Expand Down
4 changes: 4 additions & 0 deletions UMAProject/Assets/UMA/Core/Scripts/DynamicDNAPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public virtual string[] ImportSettingsMethods

#region VIRTUAL METHODS

public virtual void Reset()
{

}
//these all show when anything else gets a DynamicDNAPlugin - I'd prefer them to be protaected but also available to the pluginDrawer..How??

#if UNITY_EDITOR
Expand Down
7 changes: 7 additions & 0 deletions UMAProject/Assets/UMA/Core/Scripts/UMAMountedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ private bool Initialize()
public Transform FindOrCreateMountpoint()
{
Transform BoneTransform = SkeletonTools.RecursiveFindBone(avatar.gameObject.transform, BoneName);
foreach (Transform child in BoneTransform)
{
if (child.name == ID)
{
return child;
}
}
return CreateMountpoint(BoneTransform, avatar.gameObject.layer);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ private void SetAllKinematic(bool flag)
{
foreach (Rigidbody rigidbody in _rigidbodies)
{
rigidbody.isKinematic = flag;
if (rigidbody != null)
{
rigidbody.isKinematic = flag;
}
//rigidbody.detectCollisions = !flag;
}
}
Expand Down
17 changes: 17 additions & 0 deletions UMAProject/Assets/UMA/Core/StandardAssets/UMA/Scripts/RaceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
using UMA.CharacterSystem;

namespace UMA
{
Expand Down Expand Up @@ -98,6 +99,22 @@ public List<string> GetDNANames()
return Names;
}

public void ResetDNA()
{
foreach (IDNAConverter converter in dnaConverterList)
{
if (converter is DynamicDNAConverterController)
{
var c = converter as DynamicDNAConverterController;
for (int i=0;i<c.PluginCount;i++)
{
DynamicDNAPlugin ddp = c.GetPlugin(i);
ddp.Reset();
}
}
}
}

/// <summary>
/// Returns the list of DNA Converters that this race uses. These are usually DynamicDNAConverterController assets
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ public void PreApplyDNA(UMAData umaData, bool fixUpUMADnaToDynamicUMADna = false
}
}


/// <summary>
/// Applies each DNA converter to the UMA data and skeleton.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class UMAExpressionPlayer : ExpressionPlayer
public bool logResetErrors;

public bool useDisableDistance = false;
public bool processing = false;
public float disableDistance = 10f;
private Transform _mainCameraTransform;

Expand All @@ -42,80 +43,98 @@ void Start()
}

public void Initialize()
{
blinkDelay = Random.Range(minBlinkDelay, maxBlinkDelay);
{
blinkDelay = Random.Range(minBlinkDelay, maxBlinkDelay);

if(Camera.main != null)
_mainCameraTransform = Camera.main.transform;
if (Camera.main != null)
_mainCameraTransform = Camera.main.transform;

if (umaData == null)
{
// Find the UMAData, which could be up or down the hierarchy
umaData = gameObject.GetComponentInChildren<UMAData>();
if (umaData == null)
{
umaData = gameObject.GetComponentInParent<UMAData>();
}
if (umaData == null)
{
if (Debug.isDebugBuild)
Debug.LogError("Couldn't locate UMAData component");
}
}

if ((expressionSet != null) && (umaData != null) && (umaData.skeleton != null))
{
Transform jaw = null;
Transform neck = null;
Transform head = null;

if (umaData.animator != null)
{
jaw = umaData.animator.GetBoneTransform(HumanBodyBones.Jaw);
if (jaw != null)
jawHash = UMAUtils.StringToHash(jaw.name);
if (umaData == null)
{
// Find the UMAData, which could be up or down the hierarchy
umaData = gameObject.GetComponentInChildren<UMAData>();
if (umaData == null)
{
umaData = gameObject.GetComponentInParent<UMAData>();
}
if (umaData == null)
{
//if (Debug.isDebugBuild)
// Debug.LogError("Couldn't locate UMAData component");
return;
}
umaData.CharacterBegun.AddListener(CharacterBegun);
umaData.OnCharacterUpdated += UmaData_OnCharacterUpdated;
}

SetupBones();
initialized = true;
}

private void CharacterBegun(UMAData umaData)
{
processing = false;
}

private void SetupBones()
{
if ((expressionSet != null) && (umaData != null) && (umaData.skeleton != null))
{
Transform jaw = null;
Transform neck = null;
Transform head = null;

if (umaData.animator != null)
{
jaw = umaData.animator.GetBoneTransform(HumanBodyBones.Jaw);
if (jaw != null)
jawHash = UMAUtils.StringToHash(jaw.name);

neck = umaData.animator.GetBoneTransform(HumanBodyBones.Neck);
if (neck != null)
neckHash = UMAUtils.StringToHash(neck.name);
neck = umaData.animator.GetBoneTransform(HumanBodyBones.Neck);
if (neck != null)
neckHash = UMAUtils.StringToHash(neck.name);

head = umaData.animator.GetBoneTransform(HumanBodyBones.Head);
if (head != null)
headHash = UMAUtils.StringToHash(head.name);
}
if (overrideMecanimJaw && jaw == null)
head = umaData.animator.GetBoneTransform(HumanBodyBones.Head);
if (head != null)
headHash = UMAUtils.StringToHash(head.name);
}
if (overrideMecanimJaw && jaw == null)
{
if (Debug.isDebugBuild)
if (Debug.isDebugBuild)
{
Debug.Log("Jaw bone not found, but jaw override is requested. This will be ignored in a production build.");
Debug.Log("Jaw bone not found, but jaw override is requested. This will be ignored in a production build.");
}
overrideMecanimJaw = false;
return;
overrideMecanimJaw = false;
}
if (overrideMecanimNeck && neck == null)
{
if (Debug.isDebugBuild)
{
Debug.Log("Neck bone not found, but neck override is requested. This will be ignored in a production build.");
}
overrideMecanimNeck = false;
return;
}
if (overrideMecanimHead && head == null)
{
if (Debug.isDebugBuild)
{
Debug.Log("Head bone not found, but head override is requested. This will be ignored in a production build.");
}
overrideMecanimHead = false;
return;
}
initialized = true;
}
}
if (overrideMecanimNeck && neck == null)
{
if (Debug.isDebugBuild)
{
Debug.Log("Neck bone not found, but neck override is requested. This will be ignored in a production build.");
}
overrideMecanimNeck = false;
}
if (overrideMecanimHead && head == null)
{
if (Debug.isDebugBuild)
{
Debug.Log("Head bone not found, but head override is requested. This will be ignored in a production build.");
}
overrideMecanimHead = false;
}
}
}

private void UmaData_OnCharacterUpdated(UMAData obj)
{
SetupBones();
processing = true;
}

void Update()
void Update()
{
if (!processing)
return;
if (!initialized || umaData == null)
{
Initialize();
Expand All @@ -129,8 +148,15 @@ void Update()
Quaternion headRotation = Quaternion.identity;
Quaternion neckRotation = Quaternion.identity;

try { headRotation = umaData.skeleton.GetRotation(headHash); }
catch(System.Exception) { Debug.LogError("GetRotation: Head Bone not found!"); }
try
{
headRotation = umaData.skeleton.GetRotation(headHash);
}
catch(System.Exception ex)
{
Debug.LogException(ex);
Debug.LogError("GetRotation: Head Bone not found!");
}

try { neckRotation = umaData.skeleton.GetRotation(neckHash); }
catch(System.Exception) { Debug.LogError("GetRotation: Neck Bone not found!"); }
Expand All @@ -155,6 +181,9 @@ void Update()

void LateUpdate()
{
if (!processing)
return;

if (!initialized)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public bool GenerateSingleUMA(UMAData data)
umaData.FireCharacterBegunEvents();
PreApply(umaData);


if (umaData.isTextureDirty)
{
TextureProcessPROCoroutine textureProcessCoroutine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ public virtual GameObject GetBoneGameObject(int nameHash)
if (boneHashData.TryGetValue(nameHash, out res))
{
res.accessedFrame = frame;
if (res.boneTransform == null)
{
return null;
}
return res.boneTransform.gameObject;
}
return null;
Expand Down
Loading

0 comments on commit 07016a0

Please sign in to comment.