Exemple #1
0
    void CreateChilloutComponentIfNeeded()
    {
        cvrAvatar = vrcAvatarDescriptor.gameObject.GetComponent <CVRAvatar>();

        if (cvrAvatar != null)
        {
            Debug.Log("Avatar has a CVRAvatar, skipping...");
            return;
        }

        Debug.Log("Avatar does not have a CVRAvatar, adding...");

        cvrAvatar = vrcAvatarDescriptor.gameObject.AddComponent <CVRAvatar>() as CVRAvatar;

        Debug.Log("CVRAvatar component added");

        Repaint();
    }
        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);
                }
            }
        }
 public Extension(CVRAvatar avatar)
 {
     m_avatar = avatar;
 }
        void Start()
        {
            SwitchPage(0);
            CVRAssetInfo.AssetType type = asset.GetComponent <CVRAssetInfo>().type;

            if (type == CVRAssetInfo.AssetType.Avatar)
            {
                avtrSafety.SetActive(true);
            }
            if (type == CVRAssetInfo.AssetType.Spawnable)
            {
                propSafety.SetActive(true);
            }
            if (type == CVRAssetInfo.AssetType.World)
            {
                wrldSafety.SetActive(true);
                Scripts.Editor.CCK_WorldPreviewCapture.CreatePanoImages();
            }

            tex = new RenderTexture(512, 512, 1, RenderTextureFormat.ARGB32);
            tex.Create();

            camObj      = new GameObject();
            camObj.name = "ShotCam for CVR CCK";
            camObj.transform.rotation = new Quaternion(0, 180, 0, 0);
            CVRAvatar avatar = asset.GetComponent <CVRAvatar>();

            if (asset.type == CVRAssetInfo.AssetType.Avatar)
            {
                camObj.transform.position = new Vector3(avatar.viewPosition.x, avatar.viewPosition.y, avatar.viewPosition.z *= 5f);
            }
            var cam = camObj.AddComponent <Camera>();

            cam.aspect        = 1f;
            cam.nearClipPlane = 0.01f;
            cam.targetTexture = tex;
            texView.texture   = tex;

            #if UNITY_EDITOR
#endif

            string handle;
            if (type == CVRAssetInfo.AssetType.Avatar)
            {
                fileSizeText.text = "Asset Bundle File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvravatar").Length)
                                    + "\nAsset Bundle Manifest File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvravatar.manifest").Length)
                                    + "\nThumbnail File: creation pending";
            }
            if (type == CVRAssetInfo.AssetType.Spawnable)
            {
                fileSizeText.text = "Asset Bundle File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvrprop").Length)
                                    + "\nAsset Bundle Manifest File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvrprop.manifest").Length)
                                    + "\nThumbnail File: creation pending";
            }

            if (type == CVRAssetInfo.AssetType.World)
            {
                fileSizeText.text = "Asset Bundle File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvrworld").Length)
                                    + "\nAsset Bundle Manifest File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle.cvrworld.manifest").Length)
                                    + "\n1K Pano File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle_pano_1024.png").Length)
                                    + "\n4K Pano File: " + GetHumanReadableFileSize(new FileInfo(Application.persistentDataPath + "/bundle_pano_4096.png").Length)
                                    + "\nThumbnail File: creation pending";
            }
        }