static void CreateMask() { Animator animator; if(!Selection.activeGameObject) { return; } animator = Selection.activeGameObject.GetComponent<Animator>(); if(!animator) { return; } List<Transform> transforms = new List<Transform>(); AvatarMask avatarMask = new AvatarMask(); animator.GetComponentsInChildren<Transform>(true,transforms); avatarMask.transformCount = transforms.Count; int index = 0; foreach(Transform transform in transforms) { avatarMask.SetTransformPath(index, AnimationUtility.CalculateTransformPath(transform,animator.transform)); avatarMask.SetTransformActive(index, true); index++; } ScriptableObjectUtility.CreateAssetWithSavePanel<AvatarMask>(avatarMask,"Create Mask",animator.name+".mask","mask","Create a new Avatar Mask"); }
public static void UpdateTransformMask(AvatarMask mask, string[] refTransformsPath, string[] humanTransforms) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey87 maskCAnonStorey87 = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey87(); // ISSUE: reference to a compiler-generated field maskCAnonStorey87.refTransformsPath = refTransformsPath; // ISSUE: reference to a compiler-generated field mask.transformCount = maskCAnonStorey87.refTransformsPath.Length; // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey88 maskCAnonStorey88 = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey88(); // ISSUE: reference to a compiler-generated field maskCAnonStorey88.\u003C\u003Ef__ref\u0024135 = maskCAnonStorey87; // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field for (maskCAnonStorey88.i = 0; maskCAnonStorey88.i < maskCAnonStorey87.refTransformsPath.Length; maskCAnonStorey88.i = maskCAnonStorey88.i + 1) { // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field mask.SetTransformPath(maskCAnonStorey88.i, maskCAnonStorey87.refTransformsPath[maskCAnonStorey88.i]); // ISSUE: reference to a compiler-generated method bool flag = humanTransforms == null || ArrayUtility.FindIndex<string>(humanTransforms, new Predicate<string>(maskCAnonStorey88.\u003C\u003Em__149)) != -1; // ISSUE: reference to a compiler-generated field mask.SetTransformActive(maskCAnonStorey88.i, flag); } }
public static void SetActiveHumanTransforms(AvatarMask mask, string[] humanTransforms) { for (int i = 0; i < mask.transformCount; i++) { string path = mask.GetTransformPath(i); if (ArrayUtility.FindIndex<string>(humanTransforms, (string s) => path == s) != -1) { mask.SetTransformActive(i, true); } } }
public static void UpdateTransformMask(AvatarMask mask, string[] refTransformsPath, string[] humanTransforms) { AvatarMaskUtility.<UpdateTransformMask>c__AnonStorey69 <UpdateTransformMask>c__AnonStorey = new AvatarMaskUtility.<UpdateTransformMask>c__AnonStorey69(); <UpdateTransformMask>c__AnonStorey.refTransformsPath = refTransformsPath; mask.transformCount = <UpdateTransformMask>c__AnonStorey.refTransformsPath.Length; int i; for (i = 0; i < <UpdateTransformMask>c__AnonStorey.refTransformsPath.Length; i++) { mask.SetTransformPath(i, <UpdateTransformMask>c__AnonStorey.refTransformsPath[i]); bool value = humanTransforms == null || ArrayUtility.FindIndex<string>(humanTransforms, (string s) => <UpdateTransformMask>c__AnonStorey.refTransformsPath[i] == s) != -1; mask.SetTransformActive(i, value); } }
internal void Copy(AvatarMask other) { for (int i = 0; i < this.humanoidBodyPartCount; i++) { this.SetHumanoidBodyPartActive(i, other.GetHumanoidBodyPartActive(i)); } this.transformCount = other.transformCount; for (int j = 0; j < other.transformCount; j++) { this.SetTransformPath(j, other.GetTransformPath(j)); this.SetTransformActive(j, other.GetTransformActive(j)); } }
internal void Copy(AvatarMask other) { for (AvatarMaskBodyPart part = AvatarMaskBodyPart.Root; part < AvatarMaskBodyPart.LastBodyPart; part += 1) { this.SetHumanoidBodyPartActive(part, other.GetHumanoidBodyPartActive(part)); } this.transformCount = other.transformCount; for (int i = 0; i < other.transformCount; i++) { this.SetTransformPath(i, other.GetTransformPath(i)); this.SetTransformActive(i, other.GetTransformActive(i)); } }
internal void Copy(AvatarMask other) { for (AvatarMaskBodyPart index = AvatarMaskBodyPart.Root; index < AvatarMaskBodyPart.LastBodyPart; ++index) { this.SetHumanoidBodyPartActive(index, other.GetHumanoidBodyPartActive(index)); } this.transformCount = other.transformCount; for (int index = 0; index < other.transformCount; ++index) { this.SetTransformPath(index, other.GetTransformPath(index)); this.SetTransformActive(index, other.GetTransformActive(index)); } }
internal void Copy(AvatarMask other) { for (AvatarMaskBodyPart avatarMaskBodyPart = AvatarMaskBodyPart.Root; avatarMaskBodyPart < AvatarMaskBodyPart.LastBodyPart; avatarMaskBodyPart++) { this.SetHumanoidBodyPartActive(avatarMaskBodyPart, other.GetHumanoidBodyPartActive(avatarMaskBodyPart)); } this.transformCount = other.transformCount; for (int i = 0; i < other.transformCount; i++) { this.SetTransformPath(i, other.GetTransformPath(i)); this.SetTransformActive(i, other.GetTransformActive(i)); } }
/// <summary> /// <para>Creates a mask that matches the model hierarchy, and applies it to the provided ModelImporterClipAnimation.</para> /// </summary> /// <param name="clip">Clip to which the mask will be applied.</param> public void CreateDefaultMaskForClip(ModelImporterClipAnimation clip) { if (this.defaultClipAnimations.Length > 0) { AvatarMask mask = new AvatarMask(); this.defaultClipAnimations[0].ConfigureMaskFromClip(ref mask); clip.ConfigureClipFromMask(mask); Object.DestroyImmediate(mask); } else { Debug.LogError("Cannot create default mask because the current importer doesn't have any animation information"); } }
private void AddClip(TakeInfo takeInfo) { this.m_ClipAnimations.InsertArrayElementAtIndex(this.m_ClipAnimations.arraySize); AnimationClipInfoProperties animationClipInfoAtIndex = this.GetAnimationClipInfoAtIndex(this.m_ClipAnimations.arraySize - 1); animationClipInfoAtIndex.name = this.MakeUniqueClipName(takeInfo.defaultClipName, -1); this.SetupTakeNameAndFrames(animationClipInfoAtIndex, takeInfo); animationClipInfoAtIndex.wrapMode = 0; animationClipInfoAtIndex.loop = false; animationClipInfoAtIndex.orientationOffsetY = 0f; animationClipInfoAtIndex.level = 0f; animationClipInfoAtIndex.cycleOffset = 0f; animationClipInfoAtIndex.loopTime = false; animationClipInfoAtIndex.loopBlend = false; animationClipInfoAtIndex.loopBlendOrientation = false; animationClipInfoAtIndex.loopBlendPositionY = false; animationClipInfoAtIndex.loopBlendPositionXZ = false; animationClipInfoAtIndex.keepOriginalOrientation = false; animationClipInfoAtIndex.keepOriginalPositionY = true; animationClipInfoAtIndex.keepOriginalPositionXZ = false; animationClipInfoAtIndex.heightFromFeet = false; animationClipInfoAtIndex.mirror = false; animationClipInfoAtIndex.maskType = ClipAnimationMaskType.CreateFromThisModel; AvatarMask mask = new AvatarMask(); string[] humanTransforms = null; SerializedObject serializedObject = animationClipInfoAtIndex.maskTypeProperty.serializedObject; ModelImporter targetObject = serializedObject.targetObject as ModelImporter; if ((this.animationType == ModelImporterAnimationType.Human) && !targetObject.isAssetOlderOr42) { humanTransforms = AvatarMaskUtility.GetAvatarHumanTransform(serializedObject, targetObject.transformPaths); if (humanTransforms == null) { return; } } AvatarMaskUtility.UpdateTransformMask(mask, targetObject.transformPaths, humanTransforms); animationClipInfoAtIndex.MaskToClip(mask); animationClipInfoAtIndex.ClearEvents(); animationClipInfoAtIndex.ClearCurves(); UnityEngine.Object.DestroyImmediate(mask); }
void OnGUI() { GUILayout.Label("SSC Animator Creator Wizard", EditorStyles.boldLabel); animPath_face = EditorGUILayout.TextField("Face Animations Folder", animPath_face); animPath_hands = EditorGUILayout.TextField("Hand Animations Folder", animPath_hands); filename = EditorGUILayout.TextField("Output Filename", filename); gestureController = EditorGUILayout.ObjectField("Gesture Controller", gestureController, typeof(GestureAnimationController), true) as GestureAnimationController; maskLeftHand = EditorGUILayout.ObjectField("Left Hand Mask", maskLeftHand, typeof(AvatarMask), true) as AvatarMask; maskRightHand = EditorGUILayout.ObjectField("Right Hand Mask", maskRightHand, typeof(AvatarMask), true) as AvatarMask; maskFace = EditorGUILayout.ObjectField("Face Mask", maskFace, typeof(AvatarMask), true) as AvatarMask; maskBody = EditorGUILayout.ObjectField("Body Mask", maskBody, typeof(AvatarMask), true) as AvatarMask; idleAnimation = EditorGUILayout.ObjectField("Idle Animation", idleAnimation, typeof(AnimationClip), true) as AnimationClip; bool everythingSet = !string.IsNullOrEmpty(animPath_face) && !string.IsNullOrEmpty(animPath_hands) && !string.IsNullOrEmpty(filename) && gestureController && maskLeftHand && maskRightHand && maskFace && maskBody; EditorGUI.BeginDisabledGroup(!everythingSet); if (GUILayout.Button(everythingSet ? "Create" : "First select all Objects and Folders")) { CreateController(); } EditorGUI.EndDisabledGroup(); }
AnimatorControllerLayer CreateLayer(AnimatorController controller, string name, AvatarMask mask, float weight = 1f) { AnimatorControllerLayer layer = new AnimatorControllerLayer(); layer.avatarMask = mask; layer.name = name; layer.stateMachine = new AnimatorStateMachine(); layer.defaultWeight = weight; layer.stateMachine.name = layer.name; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(controller) != "") AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(controller)); return layer; }
void InitDefaults() { var obj = GameObject.Find("Char2"); if (obj) gestureController = obj.GetComponent<GestureAnimationController>(); maskLeftHand = AssetDatabase.LoadAssetAtPath<AvatarMask>("Assets/Animations/Masks/LeftHandOnly.mask"); maskRightHand = AssetDatabase.LoadAssetAtPath<AvatarMask>("Assets/Animations/Masks/RightHandOnly.mask"); maskFace = AssetDatabase.LoadAssetAtPath<AvatarMask>("Assets/Animations/Masks/Face.mask"); maskBody = AssetDatabase.LoadAssetAtPath<AvatarMask>("Assets/Animations/Masks/BodyWithoutArms.mask"); idleAnimation = AssetDatabase.LoadAssetAtPath<AnimationClip>("Assets/Animations/Idle/idle_2.anim"); ; }
public static void builAvatarMask(GameObject gameObject, SpineData spineData, Animator animator, string directory, string name) { Avatar avatar = AvatarBuilder.BuildGenericAvatar(gameObject,""); animator.avatar = avatar; AvatarMask avatarMask = new AvatarMask(); string[] transofrmPaths = getTransformPaths(gameObject, spineData); avatarMask.transformCount = transofrmPaths.Length; for (int i=0; i< transofrmPaths.Length; i++){ avatarMask.SetTransformPath(i, transofrmPaths[i]); avatarMask.SetTransformActive(i, true); } createFolderIfNoExists(directory, ANIMATION_FOLDER); AssetDatabase.CreateAsset(avatar , directory + "/" + ANIMATION_FOLDER + "/" + name + ".anim.asset"); AssetDatabase.CreateAsset(avatarMask, directory + "/" + ANIMATION_FOLDER + "/" + name + ".mask.asset"); }
private void DestroyEditorsAndData() { if ((UnityEngine.Object) this.m_AnimationClipEditor != (UnityEngine.Object) null) { UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_AnimationClipEditor); this.m_AnimationClipEditor = (AnimationClipEditor) null; } if ((bool) ((UnityEngine.Object) this.m_MaskInspector)) { UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_MaskInspector); this.m_MaskInspector = (AvatarMaskInspector) null; } if (!(bool) ((UnityEngine.Object) this.m_Mask)) return; UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_Mask); this.m_Mask = (AvatarMask) null; }
public void MaskToClip(AvatarMask mask) { SerializedProperty property = this.Get("bodyMask"); if ((property != null) && property.isArray) { for (int i = 0; i < mask.humanoidBodyPartCount; i++) { if (i >= property.arraySize) { property.InsertArrayElementAtIndex(i); } property.GetArrayElementAtIndex(i).intValue = !mask.GetHumanoidBodyPartActive(i) ? 0 : 1; } } SerializedProperty serializedProperty = this.Get("transformMask"); ModelImporter.UpdateTransformMask(mask, serializedProperty); }
public void MaskToClip(AvatarMask mask) { SerializedProperty serializedProperty1 = this.Get("bodyMask"); if (serializedProperty1 != null && serializedProperty1.isArray) { for (AvatarMaskBodyPart index = AvatarMaskBodyPart.Root; index < AvatarMaskBodyPart.LastBodyPart; ++index) { if (index >= (AvatarMaskBodyPart) serializedProperty1.arraySize) serializedProperty1.InsertArrayElementAtIndex((int) index); serializedProperty1.GetArrayElementAtIndex((int) index).intValue = !mask.GetHumanoidBodyPartActive(index) ? 0 : 1; } } SerializedProperty serializedProperty2 = this.Get("transformMask"); ModelImporter.UpdateTransformMask(mask, serializedProperty2); }
public void MaskToClip(AvatarMask mask) { SerializedProperty property = this.Get("bodyMask"); if ((property != null) && property.isArray) { for (AvatarMaskBodyPart part = AvatarMaskBodyPart.Root; part < AvatarMaskBodyPart.LastBodyPart; part += 1) { if (part >= property.arraySize) { property.InsertArrayElementAtIndex((int) part); } property.GetArrayElementAtIndex((int) part).intValue = !mask.GetHumanoidBodyPartActive(part) ? 0 : 1; } } SerializedProperty serializedProperty = this.Get("transformMask"); ModelImporter.UpdateTransformMask(mask, serializedProperty); }
/// <summary> /// <para>Copy the mask settings from an AvatarMask to the clip configuration.</para> /// </summary> /// <param name="mask">AvatarMask from which the mask settings will be imported.</param> public void ConfigureClipFromMask(AvatarMask mask) { this.m_TransformMask = new TransformMaskElement[mask.transformCount]; for (int i = 0; i < mask.transformCount; i++) { this.m_TransformMask[i].path = mask.GetTransformPath(i); this.m_TransformMask[i].weight = !mask.GetTransformActive(i) ? 0f : 1f; } this.m_BodyMask = new int[13]; for (int j = 0; j < 13; j++) { this.m_BodyMask[j] = !mask.GetHumanoidBodyPartActive((AvatarMaskBodyPart) j) ? 0 : 1; } }
private void InitMask() { if (this.m_Mask == null) { this.m_Mask = new AvatarMask(); this.m_MaskInspector = (AvatarMaskInspector)Editor.CreateEditor(this.m_Mask); this.m_MaskInspector.canImport = false; if (this.m_ClipInfo != null) { this.m_MaskInspector.clipInfo = this.m_ClipInfo; } if (this.m_Mask.transformCount == 0) { this.SetTransformMaskFromReference(); } } }
private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, TransitionInfo info, Animator previewObject) { this.m_IsResampling = true; this.m_MustResample = false; bool flag = this.m_RefTransition != transition; this.m_RefTransition = transition; this.m_RefTransitionInfo = info; this.m_LayerMask = layerMask; if (this.m_AvatarPreview != null) { this.m_AvatarPreview.OnDestroy(); this.m_AvatarPreview = null; } this.ClearController(); Motion motion = this.m_RefSrcState.motion; this.Init(previewObject, (motion == null) ? this.m_RefDstState.motion : motion); if (this.m_Controller != null) { this.m_AvatarPreview.Animator.allowConstantClipSamplingOptimization = false; this.m_StateMachine.defaultState = this.m_DstState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-05f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); float length = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; this.m_StateMachine.defaultState = this.m_SrcState; this.m_Transition.mute = false; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-05f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); float num2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; if (this.m_LayerIndex > 0) { this.m_AvatarPreview.Animator.stabilizeFeet = false; } float num3 = ((num2 * this.m_RefTransition.exitTime) + (this.m_Transition.duration * (!this.m_RefTransition.hasFixedDuration ? num2 : 1f))) + length; if (num3 > 2000f) { Debug.LogWarning("Transition duration is longer than 2000 second, Disabling previewer."); this.m_ValidTransition = false; } else { float num4 = (this.m_RefTransition.exitTime <= 0f) ? num2 : (num2 * this.m_RefTransition.exitTime); float a = (num4 <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float) (num4 / 300f), (float) 0.03333334f), num4 / 5f); float num6 = (length <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float) (length / 300f), (float) 0.03333334f), length / 5f); a = Mathf.Max(a, num3 / 300f); num6 = Mathf.Max(num6, num3 / 300f); float deltaTime = a; float num8 = 0f; bool flag2 = false; bool flag3 = false; bool flag4 = false; this.m_AvatarPreview.Animator.StartRecording(-1); this.m_LeftStateWeightA = 0f; this.m_LeftStateTimeA = 0f; this.m_AvatarPreview.Animator.Update(0f); int num9 = 0; while (!flag4) { num9++; this.m_AvatarPreview.Animator.Update(deltaTime); AnimatorStateInfo currentAnimatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex); num8 += deltaTime; if (!flag2) { this.m_LeftStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeA = num8; flag2 = true; } if (flag3 && (num8 >= num3)) { flag4 = true; } if (!flag3 && currentAnimatorStateInfo.IsName(this.m_DstState.name)) { this.m_RightStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeA = num8; flag3 = true; } if (!flag3) { this.m_LeftStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeB = num8; } if (flag3) { this.m_RightStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeB = num8; } if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex)) { deltaTime = num6; } } float num10 = num8; this.m_AvatarPreview.Animator.StopRecording(); if (Mathf.Approximately(this.m_LeftStateWeightB, this.m_LeftStateWeightA) || Mathf.Approximately(this.m_RightStateWeightB, this.m_RightStateWeightA)) { Debug.LogWarning("Speed difference between states is too big. Transition preview will be disabled."); this.m_ValidTransition = false; } else { float num11 = (this.m_LeftStateTimeB - this.m_LeftStateTimeA) / (this.m_LeftStateWeightB - this.m_LeftStateWeightA); float num12 = (this.m_RightStateTimeB - this.m_RightStateTimeA) / (this.m_RightStateWeightB - this.m_RightStateWeightA); if (this.m_MustSampleMotions) { this.m_MustSampleMotions = false; this.m_SrcPivotList.Clear(); this.m_DstPivotList.Clear(); deltaTime = num6; this.m_StateMachine.defaultState = this.m_DstState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(0f); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); for (num8 = 0f; num8 <= num12; num8 += deltaTime * 2f) { Timeline.PivotSample item = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_DstPivotList.Add(item); this.m_AvatarPreview.Animator.Update(deltaTime * 2f); } deltaTime = a; this.m_StateMachine.defaultState = this.m_SrcState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); for (num8 = 0f; num8 <= num11; num8 += deltaTime * 2f) { Timeline.PivotSample sample2 = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_SrcPivotList.Add(sample2); this.m_AvatarPreview.Animator.Update(deltaTime * 2f); } this.m_Transition.mute = false; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); } this.m_Timeline.StopTime = this.m_AvatarPreview.timeControl.stopTime = num10; this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time; if (flag) { float num13; this.m_AvatarPreview.timeControl.currentTime = num13 = this.m_AvatarPreview.timeControl.startTime = 0f; this.m_Timeline.StartTime = num13; this.m_Timeline.Time = num13; this.m_Timeline.ResetRange(); } this.m_AvatarPreview.Animator.StartPlayback(); this.m_IsResampling = false; } } } }
internal void Copy(AvatarMask other) { for (AvatarMaskBodyPart index = AvatarMaskBodyPart.Root; index < AvatarMaskBodyPart.LastBodyPart; ++index) this.SetHumanoidBodyPartActive(index, other.GetHumanoidBodyPartActive(index)); this.transformCount = other.transformCount; for (int index = 0; index < other.transformCount; ++index) { this.SetTransformPath(index, other.GetTransformPath(index)); this.SetTransformActive(index, other.GetTransformActive(index)); } }
private void InitMask(AnimationClipInfoProperties clipInfo) { if (!((UnityEngine.Object) this.m_Mask == (UnityEngine.Object) null)) return; AnimationClip target = this.m_AnimationClipEditor.target as AnimationClip; this.m_Mask = new AvatarMask(); this.m_MaskInspector = (AvatarMaskInspector) Editor.CreateEditor((UnityEngine.Object) this.m_Mask); this.m_MaskInspector.canImport = false; this.m_MaskInspector.showBody = target.isHumanMotion; this.m_MaskInspector.clipInfo = clipInfo; }
private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, TransitionPreview.TransitionInfo info, Animator previewObject) { this.m_IsResampling = true; this.m_MustResample = false; bool flag1 = (UnityEngine.Object) this.m_RefTransition != (UnityEngine.Object) transition; this.m_RefTransition = transition; this.m_RefTransitionInfo = info; this.m_LayerMask = layerMask; if (this.m_AvatarPreview != null) { this.m_AvatarPreview.OnDestroy(); this.m_AvatarPreview = (AvatarPreview) null; } this.ClearController(); Motion motion = this.m_RefSrcState.motion; this.Init(previewObject, !((UnityEngine.Object) motion != (UnityEngine.Object) null) ? this.m_RefDstState.motion : motion); if ((UnityEngine.Object) this.m_Controller == (UnityEngine.Object) null) return; this.m_AvatarPreview.Animator.allowConstantClipSamplingOptimization = false; this.m_StateMachine.defaultState = this.m_DstState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-05f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); float length1 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; this.m_StateMachine.defaultState = this.m_SrcState; this.m_Transition.mute = false; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-05f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); float length2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; if (this.m_LayerIndex > 0) this.m_AvatarPreview.Animator.stabilizeFeet = false; float num1 = (float) ((double) length2 * (double) this.m_RefTransition.exitTime + (double) this.m_Transition.duration * (!this.m_RefTransition.hasFixedDuration ? (double) length2 : 1.0)) + length1; if ((double) num1 > 2000.0) { Debug.LogWarning((object) "Transition duration is longer than 2000 second, Disabling previewer."); this.m_ValidTransition = false; } else { float num2 = (double) this.m_RefTransition.exitTime <= 0.0 ? length2 : length2 * this.m_RefTransition.exitTime; float a1 = (double) num2 <= 0.0 ? 0.03333334f : Mathf.Min(Mathf.Max(num2 / 300f, 0.03333334f), num2 / 5f); float a2 = (double) length1 <= 0.0 ? 0.03333334f : Mathf.Min(Mathf.Max(length1 / 300f, 0.03333334f), length1 / 5f); float num3 = Mathf.Max(a1, num1 / 600f); float num4 = Mathf.Max(a2, num1 / 600f); float deltaTime = num3; float num5 = 0.0f; bool flag2 = false; bool flag3 = false; bool flag4 = false; this.m_AvatarPreview.Animator.StartRecording(-1); this.m_LeftStateWeightA = 0.0f; this.m_LeftStateTimeA = 0.0f; this.m_AvatarPreview.Animator.Update(0.0f); while (!flag4) { this.m_AvatarPreview.Animator.Update(deltaTime); AnimatorStateInfo animatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex); num5 += deltaTime; if (!flag2) { this.m_LeftStateWeightA = this.m_LeftStateWeightB = animatorStateInfo.normalizedTime; this.m_LeftStateTimeA = this.m_LeftStateTimeB = num5; flag2 = true; } if (flag3 && (double) num5 >= (double) num1) flag4 = true; if (!flag3 && animatorStateInfo.IsName(this.m_DstState.name)) { this.m_RightStateWeightA = animatorStateInfo.normalizedTime; this.m_RightStateTimeA = num5; flag3 = true; } if (!flag3) { this.m_LeftStateWeightB = animatorStateInfo.normalizedTime; this.m_LeftStateTimeB = num5; } if (flag3) { this.m_RightStateWeightB = animatorStateInfo.normalizedTime; this.m_RightStateTimeB = num5; } if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex)) deltaTime = num4; } float num6 = num5; this.m_AvatarPreview.Animator.StopRecording(); if (Mathf.Approximately(this.m_LeftStateWeightB, this.m_LeftStateWeightA) || Mathf.Approximately(this.m_RightStateWeightB, this.m_RightStateWeightA)) { Debug.LogWarning((object) "Difference in effective length between states is too big. Transition preview will be disabled."); this.m_ValidTransition = false; } else { float num7 = (float) (((double) this.m_LeftStateTimeB - (double) this.m_LeftStateTimeA) / ((double) this.m_LeftStateWeightB - (double) this.m_LeftStateWeightA)); float num8 = (float) (((double) this.m_RightStateTimeB - (double) this.m_RightStateTimeA) / ((double) this.m_RightStateWeightB - (double) this.m_RightStateWeightA)); if (this.m_MustSampleMotions) { this.m_MustSampleMotions = false; this.m_SrcPivotList.Clear(); this.m_DstPivotList.Clear(); float num9 = num4; this.m_StateMachine.defaultState = this.m_DstState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(0.0f); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); float num10 = 0.0f; while ((double) num10 <= (double) num8) { this.m_DstPivotList.Add(new Timeline.PivotSample() { m_Time = num10, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }); this.m_AvatarPreview.Animator.Update(num9 * 2f); num10 += num9 * 2f; } float num11 = num3; this.m_StateMachine.defaultState = this.m_SrcState; this.m_Transition.mute = true; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); float num12 = 0.0f; while ((double) num12 <= (double) num7) { this.m_SrcPivotList.Add(new Timeline.PivotSample() { m_Time = num12, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }); this.m_AvatarPreview.Animator.Update(num11 * 2f); num12 += num11 * 2f; } this.m_Transition.mute = false; AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); } this.m_Timeline.StopTime = this.m_AvatarPreview.timeControl.stopTime = num6; this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time; if (flag1) { Timeline timeline = this.m_Timeline; float num9 = this.m_AvatarPreview.timeControl.currentTime = this.m_AvatarPreview.timeControl.startTime = 0.0f; this.m_Timeline.StartTime = num9; double num10 = (double) num9; timeline.Time = (float) num10; this.m_Timeline.ResetRange(); } this.m_AvatarPreview.Animator.StartPlayback(); this.m_IsResampling = false; } } }
public void MaskFromClip(AvatarMask mask) { SerializedProperty property = this.Get("bodyMask"); if ((property != null) && property.isArray) { for (AvatarMaskBodyPart part = AvatarMaskBodyPart.Root; part < AvatarMaskBodyPart.LastBodyPart; part += 1) { mask.SetHumanoidBodyPartActive(part, property.GetArrayElementAtIndex((int) part).intValue != 0); } } SerializedProperty property2 = this.Get("transformMask"); if ((property2 != null) && property2.isArray) { if ((property2.arraySize > 0) && (mask.transformCount != property2.arraySize)) { mask.transformCount = property2.arraySize; } int arraySize = property2.arraySize; if (arraySize != 0) { SerializedProperty arrayElementAtIndex = property2.GetArrayElementAtIndex(0); for (int i = 0; i < arraySize; i++) { SerializedProperty property4 = arrayElementAtIndex.FindPropertyRelative("m_Path"); SerializedProperty property5 = arrayElementAtIndex.FindPropertyRelative("m_Weight"); mask.SetTransformPath(i, property4.stringValue); mask.SetTransformActive(i, property5.floatValue > 0.5); arrayElementAtIndex.Next(false); } } } }
public static void SetActiveHumanTransforms(AvatarMask mask, string[] humanTransforms) { for (int index = 0; index < mask.transformCount; ++index) { // ISSUE: object of a compiler-generated type is created // ISSUE: reference to a compiler-generated method if (ArrayUtility.FindIndex<string>(humanTransforms, new Predicate<string>(new AvatarMaskUtility.\u003CSetActiveHumanTransforms\u003Ec__AnonStorey8B() { path = mask.GetTransformPath(index) }.\u003C\u003Em__14B)) != -1) mask.SetTransformActive(index, true); } }
public void ConfigureMaskFromClip(ref AvatarMask mask) { mask.transformCount = this.m_TransformMask.Length; for (int i = 0; i < mask.transformCount; i++) { mask.SetTransformPath(i, this.m_TransformMask[i].path); mask.SetTransformActive(i, this.m_TransformMask[i].weight > 0f); } for (int j = 0; j < this.m_BodyMask.Length; j++) { mask.SetHumanoidBodyPartActive((AvatarMaskBodyPart) j, this.m_BodyMask[j] != 0); } }
private void CheckChildren(AvatarMask mask, int index, bool value) { foreach (int current in this.m_NodeInfos[index].m_ChildIndices) { if (this.m_NodeInfos[current].m_Enabled) { mask.SetTransformActive(current, value); } this.CheckChildren(mask, current, value); } }
public void MaskFromClip(AvatarMask mask) { SerializedProperty serializedProperty1 = this.Get("bodyMask"); if (serializedProperty1 != null && serializedProperty1.isArray) { for (AvatarMaskBodyPart index = AvatarMaskBodyPart.Root; index < AvatarMaskBodyPart.LastBodyPart; ++index) mask.SetHumanoidBodyPartActive(index, serializedProperty1.GetArrayElementAtIndex((int) index).intValue != 0); } SerializedProperty serializedProperty2 = this.Get("transformMask"); if (serializedProperty2 == null || !serializedProperty2.isArray) return; if (serializedProperty2.arraySize > 0 && mask.transformCount != serializedProperty2.arraySize) mask.transformCount = serializedProperty2.arraySize; int arraySize = serializedProperty2.arraySize; for (int index = 0; index < arraySize; ++index) { SerializedProperty propertyRelative1 = serializedProperty2.GetArrayElementAtIndex(index).FindPropertyRelative("m_Path"); SerializedProperty propertyRelative2 = serializedProperty2.GetArrayElementAtIndex(index).FindPropertyRelative("m_Weight"); mask.SetTransformPath(index, propertyRelative1.stringValue); mask.SetTransformActive(index, (double) propertyRelative2.floatValue > 0.5); } }
public void MaskFromClip(AvatarMask mask) { SerializedProperty property = this.Get("bodyMask"); if ((property != null) && property.isArray) { for (int i = 0; i < mask.humanoidBodyPartCount; i++) { mask.SetHumanoidBodyPartActive(i, property.GetArrayElementAtIndex(i).intValue != 0); } } SerializedProperty property2 = this.Get("transformMask"); if ((property2 != null) && property2.isArray) { if ((property2.arraySize > 0) && (mask.transformCount != property2.arraySize)) { mask.transformCount = property2.arraySize; } int arraySize = property2.arraySize; for (int j = 0; j < arraySize; j++) { SerializedProperty property3 = property2.GetArrayElementAtIndex(j).FindPropertyRelative("m_Path"); SerializedProperty property4 = property2.GetArrayElementAtIndex(j).FindPropertyRelative("m_Weight"); mask.SetTransformPath(j, property3.stringValue); mask.SetTransformActive(j, property4.floatValue > 0.5); } } }
internal static extern void UpdateTransformMask(AvatarMask mask, SerializedProperty serializedProperty);
private void FillNodeInfos(AvatarMask mask) { this.m_NodeInfos = new AvatarMaskInspector.NodeInfo[mask.transformCount]; for (int i = 1; i < this.m_NodeInfos.Length; i++) { string fullPath = mask.GetTransformPath(i); if (this.humanTransforms != null) { this.m_NodeInfos[i].m_Enabled = (ArrayUtility.FindIndex<string>(this.humanTransforms, (string s) => fullPath == s) == -1); } else { this.m_NodeInfos[i].m_Enabled = true; } this.m_NodeInfos[i].m_Expanded = true; this.m_NodeInfos[i].m_ParentIndex = -1; this.m_NodeInfos[i].m_ChildIndices = new List<int>(); AvatarMaskInspector.NodeInfo[] arg_F6_0_cp_0 = this.m_NodeInfos; int arg_F6_0_cp_1 = i; int arg_F6_1; if (i == 0) { arg_F6_1 = 0; } else { arg_F6_1 = fullPath.Count((char f) => f == '/'); } arg_F6_0_cp_0[arg_F6_0_cp_1].m_Depth = arg_F6_1; string text = string.Empty; int num = fullPath.LastIndexOf('/'); if (num > 0) { text = fullPath.Substring(0, num); } int transformCount = mask.transformCount; for (int j = 0; j < transformCount; j++) { string transformPath = mask.GetTransformPath(j); if (text != string.Empty && transformPath == text) { this.m_NodeInfos[i].m_ParentIndex = j; } if (transformPath.StartsWith(fullPath)) { if (transformPath.Count((char f) => f == '/') == this.m_NodeInfos[i].m_Depth + 1) { this.m_NodeInfos[i].m_ChildIndices.Add(j); } } } } }