private void Awake() { EditorApplication.update += UpdateHandler; time = Time.realtimeSinceStartup; if (!Application.isPlaying) { Object obj = AssetDatabase.LoadMainAssetAtPath(GPUSkinningSampler.ReadTempData(GPUSkinningSampler.TEMP_SAVED_ANIM_PATH)); if (obj != null && obj is GPUSkinningAnimation) { serializedObject.FindProperty("anim").objectReferenceValue = obj; } obj = AssetDatabase.LoadMainAssetAtPath(GPUSkinningSampler.ReadTempData(GPUSkinningSampler.TEMP_SAVED_MESH_PATH)); if (obj != null && obj is Mesh) { serializedObject.FindProperty("savedMesh").objectReferenceValue = obj; } obj = AssetDatabase.LoadMainAssetAtPath(GPUSkinningSampler.ReadTempData(GPUSkinningSampler.TEMP_SAVED_MTRL_PATH)); if (obj != null && obj is Material) { serializedObject.FindProperty("savedMtrl").objectReferenceValue = obj; } obj = AssetDatabase.LoadMainAssetAtPath(GPUSkinningSampler.ReadTempData(GPUSkinningSampler.TEMP_SAVED_SHADER_PATH)); if (obj != null && obj is Shader) { serializedObject.FindProperty("savedShader").objectReferenceValue = obj; } obj = AssetDatabase.LoadMainAssetAtPath(GPUSkinningSampler.ReadTempData(GPUSkinningSampler.TEMP_SAVED_TEXTURE_PATH)); if (obj != null && obj is TextAsset) { serializedObject.FindProperty("texture").objectReferenceValue = obj; } serializedObject.ApplyModifiedProperties(); GPUSkinningSampler.DeleteTempData(GPUSkinningSampler.TEMP_SAVED_ANIM_PATH); GPUSkinningSampler.DeleteTempData(GPUSkinningSampler.TEMP_SAVED_MESH_PATH); GPUSkinningSampler.DeleteTempData(GPUSkinningSampler.TEMP_SAVED_MTRL_PATH); GPUSkinningSampler.DeleteTempData(GPUSkinningSampler.TEMP_SAVED_SHADER_PATH); GPUSkinningSampler.DeleteTempData(GPUSkinningSampler.TEMP_SAVED_TEXTURE_PATH); } isBoundsFoldout = GetEditorPrefsBool("isBoundsFoldout", true); isJointsFoldout = GetEditorPrefsBool("isJointsFoldout", true); rootMotionEnabled = true; }
private void UpdateHandler() { GPUSkinningSampler sampler = target as GPUSkinningSampler; if (EditorApplication.isCompiling) { if (Selection.activeGameObject == sampler.gameObject) { Selection.activeGameObject = null; return; } } float deltaTime = Time.realtimeSinceStartup - time; if (preview != null) { PreviewDrawBounds(); PreviewDrawArrows(); PreviewDrawGrid(); preview.Update_Editor(deltaTime); PreviewInteraction_CameraRestriction(); cam.Render(); } time = Time.realtimeSinceStartup; if (!sampler.isSampling && sampler.IsSamplingProgress()) { if (++sampler.samplingClipIndex < sampler.animClips.Length) { sampler.StartSample(); } else { sampler.EndSample(); EditorApplication.isPlaying = false; EditorUtility.ClearProgressBar(); LockInspector(false); } } if (sampler.isSampling) { string msg = sampler.animClip.name + "(" + (sampler.samplingClipIndex + 1) + "/" + sampler.animClips.Length + ")"; EditorUtility.DisplayProgressBar("Sampling, DONOT stop playing", msg, (float)(sampler.samplingFrameIndex + 1) / sampler.samplingTotalFrams); } }
public override void OnInspectorGUI() { GPUSkinningSampler sampler = target as GPUSkinningSampler; if (sampler == null) { return; } sampler.MappingAnimationClips(); OnGUI_Sampler(sampler); OnGUI_Preview(sampler); if (preview != null) { Repaint(); } }
private void OnGUI_Sampler(GPUSkinningSampler sampler) { BeginBox(); { EditorGUILayout.PropertyField(serializedObject.FindProperty("animName"), new GUIContent("Animation Name")); GUI.enabled = false; EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedObject.FindProperty("anim"), new GUIContent()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedObject.FindProperty("savedMesh"), new GUIContent()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedObject.FindProperty("savedMtrl"), new GUIContent()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedObject.FindProperty("savedShader"), new GUIContent()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedObject.FindProperty("texture"), new GUIContent()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUI.enabled = true; EditorGUILayout.PropertyField(serializedObject.FindProperty("skinQuality"), new GUIContent("Quality")); EditorGUILayout.PropertyField(serializedObject.FindProperty("shaderType"), new GUIContent("Shader Type")); EditorGUILayout.PropertyField(serializedObject.FindProperty("rootBoneTransform"), new GUIContent("Root Bone")); OnGUI_AnimClips(sampler); if (GUILayout.Button("Step1: Play Scene")) { DestroyPreview(); EditorApplication.isPlaying = true; } if (Application.isPlaying) { if (GUILayout.Button("Step2: Start Sample")) { DestroyPreview(); LockInspector(true); sampler.BeginSample(); sampler.StartSample(); } } } EndBox(); }
private void OnGUI_Preview(GPUSkinningSampler sampler) { BeginBox(); { if (GUILayout.Button("Preview/Edit")) { anim = sampler.anim; mesh = sampler.savedMesh; mtrl = sampler.savedMtrl; texture = sampler.texture; if (mesh != null) { bounds = mesh.bounds; } if (anim == null || mesh == null || mtrl == null || texture == null) { EditorUtility.DisplayDialog("GPUSkinning", "Missing Sampling Resources", "OK"); } else { if (rt == null) { linearToGammeMtrl = new Material(Shader.Find("GPUSkinning/GPUSkinningSamplerEditor_LinearToGamma")); linearToGammeMtrl.hideFlags = HideFlags.HideAndDontSave; rt = new RenderTexture(1024, 1024, 32, RenderTextureFormat.Default, RenderTextureReadWrite.Default); rt.hideFlags = HideFlags.HideAndDontSave; if (PlayerSettings.colorSpace == ColorSpace.Linear) { rtGamma = new RenderTexture(512, 512, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); rtGamma.hideFlags = HideFlags.HideAndDontSave; } GameObject camGo = new GameObject("GPUSkinningSamplerEditor_CameraGo"); camGo.hideFlags = HideFlags.HideAndDontSave; cam = camGo.AddComponent <Camera>(); cam.hideFlags = HideFlags.HideAndDontSave; cam.farClipPlane = 100; cam.targetTexture = rt; cam.enabled = false; cam.clearFlags = CameraClearFlags.SolidColor; cam.backgroundColor = new Color(0.2f, 0.2f, 0.2f, 1); camGo.transform.position = new Vector3(999, 1002, 999); previewClipIndex = 0; GameObject previewGo = new GameObject("GPUSkinningPreview_Go"); previewGo.hideFlags = HideFlags.HideAndDontSave; previewGo.transform.position = new Vector3(999, 999, 1002); preview = previewGo.AddComponent <GPUSkinningPlayerMono>(); preview.hideFlags = HideFlags.HideAndDontSave; preview.Init(anim, mesh, mtrl, texture); preview.Player.RootMotionEnabled = rootMotionEnabled; } } } GetLastGUIRect(ref previewEditBtnRect); if (rt != null) { int previewRectSize = Mathf.Min((int)(previewEditBtnRect.width * 0.9f), 512); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); { if (PlayerSettings.colorSpace == ColorSpace.Linear) { RenderTexture tempRT = RenderTexture.active; Graphics.Blit(rt, rtGamma, linearToGammeMtrl); RenderTexture.active = tempRT; GUILayout.Box(rtGamma, GUILayout.Width(previewRectSize), GUILayout.Height(previewRectSize)); } else { GUILayout.Box(rt, GUILayout.Width(previewRectSize), GUILayout.Height(previewRectSize)); } GetLastGUIRect(ref interactionRect); PreviewInteraction(interactionRect); EditorGUILayout.HelpBox("Drag to Orbit\nCtrl + Drag to Pitch\nAlt+ Drag to Zoom\nPress P Key to Pause", MessageType.None); } EditorGUILayout.EndVertical(); EditorGUI.ProgressBar(new Rect(interactionRect.x, interactionRect.y + interactionRect.height, interactionRect.width, 5), preview.Player.NormalizedTime, string.Empty); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); OnGUI_PreviewClipsOptions(); OnGUI_RootMotion(); EditorGUILayout.Space(); OnGUI_EditBounds(); EditorGUILayout.Space(); OnGUI_Joints(); } } EndBox(); serializedObject.ApplyModifiedProperties(); }
private void OnGUI_AnimClips(GPUSkinningSampler sampler) { BeginBox(); { EditorGUILayout.PrefixLabel("Sample Clips"); GUI.enabled = sampler.IsAnimatorOrAnimation(); int no = serializedObject.FindProperty("animClips.Array.size").intValue; int no2 = serializedObject.FindProperty("wrapModes.Array.size").intValue; int no3 = serializedObject.FindProperty("fpsList.Array.size").intValue; int no4 = serializedObject.FindProperty("rootMotionEnabled.Array.size").intValue; int no5 = serializedObject.FindProperty("individualDifferenceEnabled.Array.size").intValue; int c = EditorGUILayout.IntField("Size", no); if (c != no) { serializedObject.FindProperty("animClips.Array.size").intValue = c; } if (c != no2) { serializedObject.FindProperty("wrapModes.Array.size").intValue = c; } if (c != no3) { serializedObject.FindProperty("fpsList.Array.size").intValue = c; } if (c != no4) { serializedObject.FindProperty("rootMotionEnabled.Array.size").intValue = c; } if (c != no5) { serializedObject.FindProperty("individualDifferenceEnabled.Array.size").intValue = c; } GUI.enabled = true; EditorGUILayout.BeginHorizontal(); { for (int j = -1; j < 5; ++j) { EditorGUILayout.BeginVertical(); { EditorGUILayout.BeginHorizontal(); { if (j == -1) { GUILayout.Label(" "); } if (j == 0) { GUILayout.Label("FPS"); } if (j == 1) { GUILayout.Label("Wrap Mode"); } if (j == 2) { GUILayout.Label("Anim Clip"); } if (j == 3) { GUILayout.Label("Root Motion"); } if (j == 4) { GUILayout.Label("Individual Difference"); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < no; i++) { var prop = serializedObject.FindProperty(string.Format("animClips.Array.data[{0}]", i)); var prop2 = serializedObject.FindProperty(string.Format("wrapModes.Array.data[{0}]", i)); var prop3 = serializedObject.FindProperty(string.Format("fpsList.Array.data[{0}]", i)); var prop4 = serializedObject.FindProperty(string.Format("rootMotionEnabled.Array.data[{0}]", i)); var prop5 = serializedObject.FindProperty(string.Format("individualDifferenceEnabled.Array.data[{0}]", i)); if (prop != null) { if (j == -1) { GUILayout.Label((i + 1) + ": "); } if (j == 0) { EditorGUILayout.PropertyField(prop3, new GUIContent()); prop3.intValue = Mathf.Clamp(prop3.intValue, 0, 60); } if (j == 1) { EditorGUILayout.PropertyField(prop2, new GUIContent()); } if (j == 2) { GUI.enabled = sampler.IsAnimatorOrAnimation(); EditorGUILayout.PropertyField(prop, new GUIContent()); GUI.enabled = true; } if (j == 3) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); prop4.boolValue = GUILayout.Toggle(prop4.boolValue, string.Empty); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } if (j == 4) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.enabled = prop2.enumValueIndex == 1; prop5.boolValue = GUILayout.Toggle(prop5.boolValue, string.Empty); if (!GUI.enabled) { prop5.boolValue = false; } GUI.enabled = true; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } } } } EditorGUILayout.EndVertical(); } } EditorGUILayout.EndHorizontal(); } EndBox(); }