Пример #1
0
            private void GetViewpoint()
            {
                Transform LeftEye;
                Transform RightEye;
                Animator  animator = m_avatar.GetComponent <Animator>();

                if ((LeftEye = animator.GetBoneTransform(HumanBodyBones.LeftEye)) != null &&
                    (RightEye = animator.GetBoneTransform(HumanBodyBones.RightEye)) != null)
                {
                    m_avatar.useEyeMovement = true;
                    var center = Vector3.Lerp(LeftEye.position, RightEye.position, 0.5f) - m_avatar.transform.position;
                    m_avatar.viewPosition = new Vector3
                    {
                        x = (Mathf.Round(center.x * 1000f) / 1000f),
                        y = (Mathf.Round(center.y * 1000f) / 1000f),
                        z = (Mathf.Round(center.z * 1000f) / 1000f)
                    };
                }
                else
                {
                    Transform Neck;
                    // if you don't have a neck bone the head can be used for this
                    // while the neck is optional, the head isn't.
                    if ((Neck = animator.GetBoneTransform(HumanBodyBones.Neck)) == null)
                    {
                        Neck = animator.GetBoneTransform(HumanBodyBones.Neck);
                    }
                    m_avatar.useEyeMovement = false;
                    Vector3 eyeLevel = (Neck.position - m_avatar.transform.position) * 1.1f;
                    eyeLevel.z           += eyeLevel.y * 0.03f;
                    m_avatar.viewPosition = new Vector3
                    {
                        x = (Mathf.Round(eyeLevel.x * 1000f) / 1000f),
                        y = (Mathf.Round(eyeLevel.y * 1000f) / 1000f),
                        z = (Mathf.Round(eyeLevel.z * 1000f) / 1000f)
                    };
                }
            }
        void OnGUIAvatar(CVRAvatar avatar)
        {
            GameObject avatarObject = avatar.gameObject;

            GUI.enabled = true;
            EditorGUILayout.InspectorTitlebar(avatarObject.activeInHierarchy, avatarObject);
            int errors = 0;
            int overallPolygonsCount       = 0;
            int overallSkinnedMeshRenderer = 0;
            int overallUniqueMaterials     = 0;
            int overallMissingScripts      = 0;

            foreach (MeshFilter filter in avatar.gameObject.GetComponentsInChildren <MeshFilter>())
            {
                if (filter.sharedMesh != null)
                {
                    overallPolygonsCount = overallPolygonsCount + filter.sharedMesh.triangles.Length / 3;
                }
            }
            foreach (SkinnedMeshRenderer renderer in avatar.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                overallSkinnedMeshRenderer++;
                if (renderer.sharedMaterials != null)
                {
                    overallUniqueMaterials = overallUniqueMaterials + renderer.sharedMaterials.Length;
                }
            }
            overallMissingScripts = CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection, false, avatarObject);
            if (overallMissingScripts > 0)
            {
                errors++;
            }

            //Errors
            if (overallMissingScripts > 0)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_ERROR_AVATAR_MISSING_SCRIPTS"), MessageType.Error);
            }
            var animator = avatar.GetComponent <Animator>();

            if (animator == null)
            {
                errors++;
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_ERROR_ANIMATOR"), MessageType.Error);
            }
            if (animator != null && animator.avatar == null)
            {
                //errors++;
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_GENERIC"), MessageType.Warning);
            }

            //Warnings
            if (overallPolygonsCount > 100000)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Warning);
            }
            if (overallSkinnedMeshRenderer > 10)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Warning);
            }
            if (overallUniqueMaterials > 20)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Warning);
            }
            if (avatar.viewPosition == Vector3.zero)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_VIEWPOINT"), MessageType.Warning);
            }
            if (animator != null && animator.avatar != null && !animator.avatar.isHuman)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_NON_HUMANOID"), MessageType.Warning);
            }

            var avatarMeshes = getAllAssetMeshesInAvatar(avatarObject);

            if (CheckForLegacyBlendShapeNormals(avatarMeshes))
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_LEGACY_BLENDSHAPES"), MessageType.Warning);
                if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_FIX_IMPORT_SETTINGS")))
                {
                    FixLegacyBlendShapeNormals(avatarMeshes);
                }
            }

            //Info
            if (overallPolygonsCount >= 50000 && overallPolygonsCount <= 100000)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Info);
            }
            if (overallSkinnedMeshRenderer >= 5 && overallSkinnedMeshRenderer <= 10)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Info);
            }
            if (overallUniqueMaterials >= 10 && overallUniqueMaterials <= 20)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Info);
            }
            if (avatar.viewPosition.y <= 0.5f)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_SMALL"), MessageType.Info);
            }
            if (avatar.viewPosition.y > 3f)
            {
                EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_HUGE"), MessageType.Info);
            }

            if (errors <= 0)
            {
                if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_UPLOAD_BUTTON")))
                {
                    CCK_BuildUtility.BuildAndUploadAvatar(avatarObject);
                }
            }
            if (overallMissingScripts > 0)
            {
                if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UTIL_REMOVE_MISSING_SCRIPTS_BUTTON")))
                {
                    CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection, true, avatarObject);
                }
            }
        }