| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | 
							- #if UNITY_EDITOR
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using GpuEcsAnimationBaker.Engine.Data;
 
- using UnityEditor;
 
- using UnityEngine;
 
- namespace GPUECSAnimationBaker.Engine.Baker
 
- {
 
-     [CustomEditor(typeof(GpuEcsAnimationBakerBehaviour))]
 
-     public class GpuEcsAnimationBakerEditor : UnityEditor.Editor
 
-     {
 
-         private SerializedProperty bakerDataProperty;
 
-         private SerializedProperty gpuEcsAnimatorProperty;
 
-         private bool showPrefabError = false;
 
-         void OnEnable()
 
-         {
 
-             bakerDataProperty = serializedObject.FindProperty("bakerData");
 
-             gpuEcsAnimatorProperty = serializedObject.FindProperty("gpuEcsAnimator");
 
-             showPrefabError = false;
 
-         }
 
-         public override void OnInspectorGUI()
 
-         {
 
-             GameObject sourceModel = ((GpuEcsAnimationBakerBehaviour)target).gameObject;
 
-             GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
 
-             labelStyle.normal.textColor = new Color(1f, 0.5f, 0f, 1f);
 
-             labelStyle.wordWrap = true;
 
-             labelStyle.alignment = TextAnchor.MiddleLeft;
 
-             labelStyle.fontSize = 22;
 
-             labelStyle.fontStyle = FontStyle.Bold;
 
-             labelStyle.fixedHeight = 36;
 
-             GUILayout.Label("GPU ECS Animation Baker", labelStyle);
 
-             serializedObject.Update();
 
-             EditorGUILayout.PropertyField(bakerDataProperty);
 
-             bool validated = GpuEcsAnimationBakerServices.ValidateAnimationBakerData(
 
-                 (GpuEcsAnimationBakerData)bakerDataProperty.boxedValue, sourceModel, out string errors);
 
-             if (!validated) EditorGUILayout.HelpBox(errors, MessageType.Error);
 
-             if (showPrefabError)
 
-                 EditorGUILayout.HelpBox("Generation can only happen on unloaded, selected prefabs", MessageType.Error);
 
-             GUI.enabled = validated;
 
-             GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
 
-             buttonStyle.normal.textColor = new Color(1f, 0.5f, 0f, 1f);
 
-             buttonStyle.alignment = TextAnchor.MiddleCenter;
 
-             buttonStyle.fontSize = 22;
 
-             buttonStyle.fontStyle = FontStyle.Bold;
 
-             buttonStyle.fixedHeight = 36;
 
-             if (GUILayout.Button("Generate GPU ECS Animator", buttonStyle))
 
-             {
 
-                 string path = AssetDatabase.GetAssetPath(sourceModel);
 
-                 if (string.IsNullOrEmpty(path) || !PrefabUtility.IsPartOfAnyPrefab(sourceModel))
 
-                     showPrefabError = true;
 
-                 else
 
-                 {
 
-                     string folder = "Assets/Art/BakedAssets/";
 
-                     string subFolder = $"BakedAssets_{sourceModel.name}";
 
-                     string generatedAssetsFolder = Path.Combine(folder, subFolder);
 
-                     string dirPath = Application.dataPath.Replace("Assets", generatedAssetsFolder);
 
-                     if (!Directory.Exists(dirPath))
 
-                     {
 
-                         Directory.CreateDirectory(dirPath);
 
-                     }
 
-                     // if (!AssetDatabase.IsValidFolder(generatedAssetsFolder))
 
-                     //     generatedAssetsFolder = AssetDatabase.CreateFolder("Assets/","Art/BakedAssets/"+subFolder);
 
-                     string animatorName = sourceModel.name;
 
-                     GpuEcsAnimationBakerData bakerData = (GpuEcsAnimationBakerData)bakerDataProperty.boxedValue;
 
-                     GpuEcsAnimationBakerBehaviour gpuEcsAnimationBakerBehaviour =
 
-                         serializedObject.targetObject as GpuEcsAnimationBakerBehaviour;
 
-                     IGPUSkeletonBake[] gpuSkeletonBakes = gpuEcsAnimationBakerBehaviour.gameObject.transform
 
-                         .GetComponentsInChildren<IGPUSkeletonBake>();
 
-                     if (gpuSkeletonBakes != null && gpuSkeletonBakes.Length > 0)
 
-                     {
 
-                         List<AttachmentAnchor> attachmentAnchors = new List<AttachmentAnchor>();
 
-                         attachmentAnchors.AddRange(bakerData.attachmentAnchors);
 
-                         for (int i = 0; i < gpuSkeletonBakes.Length; i++)
 
-                         {
 
-                             IGPUSkeletonBake iGPUSkeletonBake = gpuSkeletonBakes[i];
 
-                             Transform transform = iGPUSkeletonBake.GetTransform();
 
-                             if (transform != null)
 
-                             {
 
-                                 string skeletonName = iGPUSkeletonBake.GetSkeletonName();
 
-                                 if (!string.IsNullOrEmpty(skeletonName))
 
-                                 {
 
-                                     bool isOk = true;
 
-                                     for (int j = 0; j < attachmentAnchors.Count; j++)
 
-                                     {
 
-                                         if (attachmentAnchors[j].attachmentAnchorID.Equals(skeletonName))
 
-                                         {
 
-                                             isOk = false;
 
-                                             break;
 
-                                         }
 
-                                     }
 
-                                     if (isOk)
 
-                                     {
 
-                                         AttachmentAnchor attachmentAnchor = new AttachmentAnchor();
 
-                                         attachmentAnchor.attachmentAnchorID = skeletonName;
 
-                                         attachmentAnchor.attachmentAnchorTransform = transform;
 
-                                         attachmentAnchors.Add(attachmentAnchor);
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                         bakerData.attachmentAnchors = attachmentAnchors.ToArray();
 
-                     }
 
-                     GameObject newGpuEcsAnimator = GpuEcsAnimationBakerServices.GenerateAnimationObject(path, bakerData,
 
-                         animatorName, generatedAssetsFolder);
 
-                     gpuEcsAnimatorProperty.boxedValue = newGpuEcsAnimator;
 
-                     showPrefabError = false;
 
-                 }
 
-             }
 
-             GUI.enabled = true;
 
-             EditorGUILayout.PropertyField(gpuEcsAnimatorProperty);
 
-             serializedObject.ApplyModifiedProperties();
 
-         }
 
-     }
 
- }
 
- #endif
 
 
  |