示例#1
0
        public void AddPart(string partAssetPath)
        {
            if (avatarInstance == null)
            {
                return;
            }

            AvatarPartData partData = AssetDatabase.LoadAssetAtPath <AvatarPartData>(partAssetPath);

            if (partData != null)
            {
                UnloadPart(partData.partName);

                partInstanceDic.Add(partData.partName, AvatarUtil.AssemblePart(nodeBehaviour, partData));
                AvatarUtil.AssemblePart(nodeBehaviour, partData);
            }
        }
示例#2
0
        private void DeleteCreatorData(AvatarCreatorData data)
        {
            string skeletonAssetPath = data.skeletonData.GetSkeletonPrefabPath();

            if (AssetDatabase.LoadAssetAtPath <UnityObject>(skeletonAssetPath) != null)
            {
                AssetDatabase.DeleteAsset(skeletonAssetPath);
            }

            AvatarSkeletonPartCreatorData partOutputData = data.skeletonPartData;

            foreach (var partData in partOutputData.partDatas)
            {
                string         partAssetPath  = partData.GetPartAssetPath(partOutputData.outputFolder);
                AvatarPartData avatarPartData = AssetDatabase.LoadAssetAtPath <AvatarPartData>(partAssetPath);
                if (avatarPartData != null)
                {
                    foreach (var avatarRendererPartData in avatarPartData.rendererParts)
                    {
                        if (avatarRendererPartData.mesh != null)
                        {
                            string meshAssetPath = AssetDatabase.GetAssetPath(avatarRendererPartData.mesh);
                            if (Path.GetExtension(meshAssetPath).ToLower() == ".asset" && Path.GetFileNameWithoutExtension(meshAssetPath).EndsWith("_mesh"))
                            {
                                AssetDatabase.DeleteAsset(meshAssetPath);
                            }
                        }
                    }

                    AssetDatabase.DeleteAsset(partAssetPath);
                }
            }

            string assetPath = AssetDatabase.GetAssetPath(currentCreatorData);

            AssetDatabase.DeleteAsset(assetPath);
        }
示例#3
0
        public static AvatarPartData CreatePart(string outputFolder, AvatarPartCreatorData data)
        {
            if (data == null)
            {
                Debug.LogError("AvatarCreatorUtil::CreatePart->the data is null");
                return(null);
            }

            if (string.IsNullOrEmpty(outputFolder))
            {
                Debug.LogError("AvatarCreatorUtil::CreatePart->The outputFolder is empty");
                return(null);
            }

            if (string.IsNullOrEmpty(data.name))
            {
                Debug.LogError("AvatarCreatorUtil::CreatePart->The name is empty");
                return(null);
            }

            string partAssetPath = data.GetPartAssetPath(outputFolder);

            AvatarPartData partData = ScriptableObject.CreateInstance <AvatarPartData>();

            partData.name     = data.name;
            partData.partName = data.partName;

            List <PrefabPartData> prefabPartDatas = new List <PrefabPartData>();

            foreach (var prefabCreatorData in data.prefabDatas)
            {
                if (string.IsNullOrEmpty(prefabCreatorData.bindNodeName))
                {
                    Debug.LogError("AvatarCreatorUtil::CreatePart->The bindNodeName is empty");
                    return(null);
                }

                if (prefabCreatorData.bindPrefab == null)
                {
                    Debug.LogError("AvatarCreatorUtil::CreatePart->The bindPrefab is null");
                    return(null);
                }

                PrefabAssetType assetType = UnityEditor.PrefabUtility.GetPrefabAssetType(prefabCreatorData.bindPrefab);
                if (assetType != PrefabAssetType.Regular)
                {
                    Debug.LogError($"AvatarCreatorUtil::CreatePart->The bindPrefab is not a Prefab.type = {assetType}");
                    return(null);
                }

                PrefabPartData prefabPartData = new PrefabPartData();
                prefabPartData.bindName = prefabCreatorData.bindNodeName;
                prefabPartData.prefabGO = prefabCreatorData.bindPrefab;
                prefabPartDatas.Add(prefabPartData);
            }
            partData.prefabParts = prefabPartDatas.ToArray();

            List <RendererPartData> rendererPartDatas = new List <RendererPartData>();

            foreach (var rendererCreatorData in data.rendererDatas)
            {
                if (rendererCreatorData.fbx == null)
                {
                    Debug.LogError("AvatarCreatorUtil::CreatePart->The fbx is null");
                    return(null);
                }

                PrefabAssetType assetType = UnityEditor.PrefabUtility.GetPrefabAssetType(rendererCreatorData.fbx);
                if (assetType != PrefabAssetType.Model)
                {
                    Debug.LogError($"AvatarCreatorUtil::CreatePart->The fbx is not a model.type = {assetType}");
                    return(null);
                }

                SkinnedMeshRenderer[] renderers = rendererCreatorData.fbx.GetComponentsInChildren <SkinnedMeshRenderer>(true);
                foreach (var renderer in renderers)
                {
                    RendererPartData rendererPartData = new RendererPartData();
                    rendererPartData.rendererName = renderer.name;
                    rendererPartData.rootBoneName = renderer.rootBone.name;
                    rendererPartData.boneNames    = (from bone in renderer.bones select bone.name).ToArray();
                    rendererPartData.materials    = renderer.sharedMaterials;

                    Mesh   mesh          = renderer.sharedMesh;
                    string meshAssetPath = $"{outputFolder}/{mesh.name}_mesh.asset";
                    if (rendererCreatorData.IsCopyMesh)
                    {
                        mesh = Utilities.MeshUtility.CopyMeshTo(mesh, meshAssetPath);
                    }
                    else
                    {
                        if (AssetDatabase.LoadAssetAtPath <UnityObject>(meshAssetPath) != null)
                        {
                            AssetDatabase.DeleteAsset(meshAssetPath);
                        }
                    }
                    rendererPartData.mesh = mesh;

                    rendererPartDatas.Add(rendererPartData);
                }
            }
            partData.rendererParts = rendererPartDatas.ToArray();


            AssetDatabase.CreateAsset(partData, partAssetPath);
            AssetDatabase.ImportAsset(partAssetPath);

            return(partData);
        }