Ejemplo n.º 1
0
    private void CreateAllAvatarRes()
    {
        DirectoryInfo dir = new DirectoryInfo("Assets/Resources/");

        foreach (var subdir in dir.GetDirectories())
        {
            string[] splits  = subdir.Name.Split('/');
            string   dirname = splits[splits.Length - 1];

            GameObject [] golist = Resources.LoadAll <GameObject>(dirname);

            AvatarRes avatarres = new AvatarRes();
            mAvatarResList.Add(avatarres);

            avatarres.mName      = dirname;
            avatarres.mSkeleton  = FindRes(golist, SkeletonName)[0];
            avatarres.mEyesList  = FindRes(golist, EyesName);
            avatarres.mFaceList  = FindRes(golist, FaceName);
            avatarres.mHairList  = FindRes(golist, HairName);
            avatarres.mPantsList = FindRes(golist, PantsName);
            avatarres.mShoesList = FindRes(golist, ShoesName);
            avatarres.mTopList   = FindRes(golist, TopName);

            string animpath            = "Assets/Anims/" + dirname + "/";
            List <AnimationClip> clips = FunctionUtil.CollectAll <AnimationClip>(animpath);
            avatarres.mAnimList.AddRange(clips);
        }
    }
Ejemplo n.º 2
0
    private static void GenerateSkeleton(GameObject srcobj, string dir, string middir)
    {
        string prefabpath = Prefab_PATH + "/" + middir + "/";
        string animpath   = ANIM_PATH + "/" + middir + "/";

        DirectoryInfo dirinfo = new DirectoryInfo(dir);

        if (!dirinfo.Exists)
        {
            return;
        }

        GameObject obj = GameObject.Instantiate(srcobj);

        obj.name = middir + "_skeleton";
        obj.transform.position   = Vector3.zero;
        obj.transform.rotation   = Quaternion.identity;
        obj.transform.localScale = Vector3.one;

        foreach (SkinnedMeshRenderer smr in obj.GetComponentsInChildren <SkinnedMeshRenderer>())
        {
            GameObject.DestroyImmediate(smr.gameObject);
        }

        Animation anim = obj.GetComponent <Animation>();

        GameObject.DestroyImmediate(anim);

        anim = obj.AddComponent <Animation>();

        List <AnimationClip> clips = FunctionUtil.CollectAll <AnimationClip>(animpath);

        foreach (var clip in clips)
        {
            anim.AddClip(clip, clip.name);
        }

        string dstpath = prefabpath + obj.name.ToLower() + PREAFAB_SUFFIX;

        PrefabUtility.CreatePrefab(dstpath, obj);

        GameObject.DestroyImmediate(obj);
    }
Ejemplo n.º 3
0
    private static void GeneratePrefab(GameObject srcobj, string dir, string middir)
    {
        string prefabpath = Prefab_PATH + "/" + middir + "/";
        string matpath    = MAT_PATH + middir + "/";

        DirectoryInfo dirinfo = new DirectoryInfo(dir);

        if (!dirinfo.Exists)
        {
            return;
        }

        dirinfo = new DirectoryInfo(prefabpath);
        if (!dirinfo.Exists)
        {
            Directory.CreateDirectory(prefabpath);
        }

        List <Material> materials = FunctionUtil.CollectAll <Material>(matpath);

        foreach (SkinnedMeshRenderer smr in srcobj.GetComponentsInChildren <SkinnedMeshRenderer>(true))
        {
            GameObject          obj            = (GameObject)PrefabUtility.InstantiatePrefab(smr.gameObject);
            SkinnedMeshRenderer renderer       = obj.GetComponent <SkinnedMeshRenderer>();
            GameObject          rendererParent = obj.transform.parent.gameObject;
            foreach (SkinnedMeshRenderer tempsmr in rendererParent.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                if (tempsmr != renderer)
                {
                    GameObject.DestroyImmediate(tempsmr.gameObject);
                }
            }

            Animation anim = rendererParent.GetComponent <Animation>();
            GameObject.DestroyImmediate(anim);

            foreach (var material in materials)
            {
                if (material == null)
                {
                    continue;
                }

                if (!material.name.Contains(obj.name))
                {
                    continue;
                }

                GameObject newobj = GameObject.Instantiate(rendererParent);
                newobj.name = material.name;
                newobj.transform.position   = Vector3.zero;
                newobj.transform.rotation   = Quaternion.identity;
                newobj.transform.localScale = Vector3.one;

                SkinnedMeshRenderer newrenderer = newobj.GetComponentInChildren <SkinnedMeshRenderer>();
                newrenderer.material = material;

                string dstpath = prefabpath + newobj.name + PREAFAB_SUFFIX;
                PrefabUtility.CreatePrefab(dstpath, newobj);

                GameObject.DestroyImmediate(newobj);
            }

            GameObject.DestroyImmediate(rendererParent);
        }
    }