コード例 #1
0
    public static void OpenDiagle()
    {
        //if (SceneFileCopy.OpenUf3dFile())
        //{
        //    Uf3dLoader loader = new Uf3dLoader();
        //    loader.parse(SceneFileCopy.SourceFile);
        //}
        var list = GetFilesPath(@"D:\特效\out");

        foreach (var item in list)
        {
            Uf3dLoader loader = new Uf3dLoader();
            SceneFileCopy.openUF3D(item);
            loader.parse(item);
        }


        //"D:\特效\out\战斗中特效\粒子特效\命中效果\圆心扩散\冲击波 绿\ZhenJi.uf3d"
        //D:\特效\out\待整理文档\2017.8月需求\RPG\征服者机甲\核子轰击
        //"D:\特效\out\翅膀分类专题\创世之翼\ChiBangShouQi.uf3d"
        //Uf3dLoader loader = new Uf3dLoader();
        //string[] names1 = new string[] { "Dun", "FengBaoShuangXiong_JuQi" , "FengBaoShuangXiong_QiangKouHuoHua", "ChiBang", "ChiBangShouQi", "BeiJi", "c1"};
        //string[] names = new string[] { "smoke", "xuanfeng0", "explosion1", "xuanfeng" , "UltraISO", "baofa" , "chuizi", "shuoji", "jian1", "GLOW", "HanDiYiJi", "HuoZhiQuan", "DianShanLeiMing", "TianLei_BaoZha", "JinQuTeXiao", "TianLei", "hjnbe" };
        //var tmp = names;
        //loader.parse("D:\\Users\\Administrator\\Desktop\\uf3d\\" + tmp[tmp.Length - 4] + ".uf3d");
    }
コード例 #2
0
    private static Material AssembleMaterial(ParticleSystem ps, Dictionary <int, object> resource)
    {
        string texName = (resource[ps.TexId] as Texture3D).Name;

        ps.UnityResourceParam.MaterialPath = SceneFileCopy.GetRelativeMaterialDir(ps.RootFileName) + ps.Name + ".mat";

        Material mtl = MaterialFactory.createMaterial(ps);

        mtl.SetTexture("_MainTex", UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.Texture2DPath, typeof(Texture2D)) as Texture2D);
        float baseTilingX = 1f;
        float baseTilingY = 1f;
        float baseOffsetX = 0f;
        float baseOffsetY = 0f;

        mtl.SetTextureScale("_MainTex", new Vector2(baseTilingX, baseTilingY));
        mtl.SetTextureOffset("_MainTex", new Vector2(baseOffsetX, baseOffsetY));
        uint color = 0xFFFFFFFF;

        mtl.SetColor("_Color", new Color(((color >> 16) & 0xFF) / 255.0f,
                                         ((color >> 8) & 0xFF) / 255.0f,
                                         (color & 0xFF) / 255.0f,
                                         ((color >> 24) & 0xFF) / 255.0f));
        UnityEditor.AssetDatabase.CreateAsset(mtl, ps.UnityResourceParam.MaterialPath);
        UnityEditor.AssetDatabase.Refresh();
        return(mtl);
    }
コード例 #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="ps"></param>
    /// <param name="resource"></param>
    /// <param name="rotate">是否旋转模型x轴90度</param>
    /// <returns></returns>
    private static Mesh AssembleMesh(ParticleSystem ps, Dictionary <int, object> resource, bool rotate = false)
    {
        Mesh mesh = null;

        if (ps.SurfId != 0)
        {
            //Surface3D surf = resource[(int)ps.SurfId] as Surface3D;
            //obj = new GameObject("ps.Name");
            //obj.AddComponent<MeshFilter>();
            //obj.AddComponent<MeshRenderer>();
            //obj.GetComponent<MeshRenderer>().sharedMaterial = mtl;

            ps.UnityResourceParam.MeshPath = SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + ps.Name + ".prefab";

            Surface3D surf = resource[(int)ps.SurfId] as Surface3D;
            mesh      = new Mesh();
            mesh.name = ps.Name;
            int       verticesCountInMesh = surf.VertexVector.Count / surf.SizePerVertex;
            Vector3[] xyz = new Vector3[surf.NumTriangles * 3];
            Vector2[] uv1 = new Vector2[surf.NumTriangles * 3];

            for (int i = 0; i < verticesCountInMesh; ++i)
            {
                //旋转方向
                xyz[i] = new Vector3(
                    surf.VertexVector[i * surf.SizePerVertex + surf.Offset[Surface3D.POSITION] + 0],
                    surf.VertexVector[i * surf.SizePerVertex + surf.Offset[Surface3D.POSITION] + 1],
                    surf.VertexVector[i * surf.SizePerVertex + surf.Offset[Surface3D.POSITION] + 2]
                    );
                uv1[i] = new Vector2(
                    surf.VertexVector[i * surf.SizePerVertex + surf.Offset[Surface3D.UV0] + 0],
                    //unity的UV坐标和as3不一样
                    1 - surf.VertexVector[i * surf.SizePerVertex + surf.Offset[Surface3D.UV0] + 1]
                    );
            }

            int[] triangles = new int[surf.IndexVector.Count];
            for (int i = 0; i < triangles.Length; ++i)
            {
                triangles[i] = (int)surf.IndexVector[i];
            }
            mesh.vertices  = xyz;
            mesh.uv        = uv1;
            mesh.triangles = triangles;
            mesh.RecalculateNormals();

            if (rotate)
            {
                PrimitiveHelper.RotateMeshVertices(mesh, new Vector3(0, 0, 0), new Vector3(90, 0, 0));
                mesh.RecalculateBounds();
                mesh.RecalculateNormals();
            }

            UnityEditor.AssetDatabase.CreateAsset(mesh, ps.UnityResourceParam.MeshPath);
            UnityEditor.AssetDatabase.Refresh();
        }

        return(mesh);
    }
コード例 #4
0
    private static void FillRenderModule(UnityEngine.ParticleSystem ups, ParticleSystem ps)
    {
        ParticleSystemRenderer psr = ups.GetComponent <ParticleSystemRenderer>();

        psr.sortingOrder = ps.Layer;
        var material = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MaterialPath, typeof(Material)) as Material;

        psr.renderMode = (ParticleSystemRenderMode)ps.RenderParam.BillboardType;
        if (psr.renderMode == ParticleSystemRenderMode.Mesh)
        {
            if (ps.SurfId != 0)
            {
                psr.mesh = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MeshPath, typeof(Mesh)) as Mesh;
            }
            else
            {
                if (!File.Exists(SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab"))
                {
                    PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Quad, true, SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab");
                }

                psr.mesh = UnityEditor.AssetDatabase.LoadAssetAtPath(SceneFileCopy.GetRelativeMeshDir(ps.RootFileName) + "quad90.prefab", typeof(Mesh)) as Mesh;
            }
        }
        else if (psr.renderMode == ParticleSystemRenderMode.Stretch)
        {
            psr.lengthScale = 1.0f;
            var texture    = material.mainTexture as Texture2D;
            var newtexture = ImageUtil.rotateTexture(texture, true);
            newtexture.alphaIsTransparency = true;
            newtexture.filterMode          = texture.filterMode;
            newtexture.wrapMode            = texture.wrapMode;
            newtexture.name = texture.name + "_rotNeg90";
            //UnityEditor.AssetDatabase.CreateAsset(newtexture, SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + newtexture.name);
            //UnityEditor.AssetDatabase.Refresh();
            material.SetTexture("_MainTex", newtexture);
            float baseTilingX = 1f;
            float baseTilingY = 1f;
            float baseOffsetX = 0f;
            float baseOffsetY = 0f;
            material.SetTextureScale("_MainTex", new Vector2(baseTilingX, baseTilingY));
            material.SetTextureOffset("_MainTex", new Vector2(baseOffsetX, baseOffsetY));
            uint color = 0xFFFFFFFF;
            material.SetColor("_Color", new Color(((color >> 16) & 0xFF) / 255.0f,
                                                  ((color >> 8) & 0xFF) / 255.0f,
                                                  (color & 0xFF) / 255.0f,
                                                  ((color >> 24) & 0xFF) / 255.0f));
            UnityEditor.AssetDatabase.Refresh();
        }
        //如果有mesh,强制使用meshbillboard 类型
        if (ps.SurfId != 0)
        {
            psr.renderMode = ParticleSystemRenderMode.Mesh;
            psr.mesh       = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.MeshPath, typeof(Mesh)) as Mesh;
        }
        psr.material = material;
    }
コード例 #5
0
    /// <summary>
    /// 把纹理放到编辑器中去
    /// </summary>
    /// <param name="ps"></param>
    private static Texture2D AssembleTexture(ParticleSystem ps, Dictionary <int, object> resource)
    {
        Texture2D tex2D = null;
        Texture3D tex   = resource[ps.TexId] as Texture3D;

        if (tex.IsATF)
        {
        }
        else
        {
            //实例化一个Texture2D,宽和高设置可以是任意的,因为当使用LoadImage方法会对Texture2D的宽和高会做相应的调整
            //Texture2D tex2D = new Texture2D(1,1);
            //tex2D.LoadImage(tex.Data);
            var fileName = string.Empty;
            //if (!File.Exists(SceneFileCopy.GetAbsoluteTextureDir() + tex.Name))
            {
                fileName = tex.Name;
                ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
            }
            //else
            //{
            //    fileName = tex.Name.Substring(0, UnityEngine.Mathf.Max(0, tex.Name.Length - 4)) + "_" + Guid.NewGuid().ToString() + tex.Name.Substring(tex.Name.Length - 4, 4);
            //    ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir() + fileName;
            //}
            ps.UnityResourceParam.Texture2DPath = SceneFileCopy.GetRelativeTextureDir(ps.RootFileName) + fileName;
            SaveFile(SceneFileCopy.GetAbsoluteTextureDir(ps.RootFileName) + fileName, tex.Data);
            tex2D = UnityEditor.AssetDatabase.LoadAssetAtPath(ps.UnityResourceParam.Texture2DPath, typeof(Texture2D)) as Texture2D;
            UnityEditor.TextureImporter         textureImporter = UnityEditor.AssetImporter.GetAtPath(ps.UnityResourceParam.Texture2DPath) as UnityEditor.TextureImporter;
            UnityEditor.TextureImporterSettings settings        = new UnityEditor.TextureImporterSettings();
            textureImporter.ReadTextureSettings(settings);
            settings.ApplyTextureType(UnityEditor.TextureImporterType.Default);
            textureImporter.SetTextureSettings(settings);
            textureImporter.textureType = UnityEditor.TextureImporterType.Default;
            //使用透明度
            textureImporter.alphaIsTransparency = true;
            textureImporter.isReadable          = true;
            textureImporter.filterMode          = (UnityEngine.FilterMode)tex.FilterMode;
            textureImporter.wrapMode            = (UnityEngine.TextureWrapMode)tex.WrapMode;
            textureImporter.mipmapEnabled       = tex.MipMode > 0;
            UnityEditor.AssetDatabase.ImportAsset(ps.UnityResourceParam.Texture2DPath);
        }
        UnityEditor.AssetDatabase.Refresh();
        return(tex2D);
    }
コード例 #6
0
    private static void AssembleParticleSystem(Uf3dLoader loader)
    {
        Dictionary <int, GameObject> particles = new Dictionary <int, GameObject>();
        var root = new GameObject(Path.GetFileNameWithoutExtension(loader.StrFileName));

        root.AddComponent <UnityEngine.ParticleSystem>();
        UnityEngine.ParticleSystem rootUPS = root.GetComponent <UnityEngine.ParticleSystem>();
        var rootMain = rootUPS.main;

        rootMain.duration = 0.1f;
        rootMain.loop     = false;
        var tmpEmission = rootUPS.emission;

        tmpEmission.enabled = false;
        var tmpShape = rootUPS.shape;

        tmpShape.enabled = false;

        var rotateOffset = new Quaternion();

        rotateOffset.eulerAngles     = new Vector3(0, 0, 0);
        root.transform.localRotation = rotateOffset;
        for (int i = 0; i < loader.ParticleSystemList.Count; i++)
        {
            ParticleSystem ps = loader.ParticleSystemList[i];
            ps.RootFileName = root.name;
            var tex2D = AssembleTexture(ps, loader.Resource);
            var mtl   = AssembleMaterial(ps, loader.Resource);
            var mesh  = AssembleMesh(ps, loader.Resource, true);
            var unityParticleSystem = new GameObject(ps.Name);
            unityParticleSystem.AddComponent <UnityEngine.ParticleSystem>();

            var matrix = ps.Matrix;

            //if (ps.Parent != -1)
            //{
            //    var father = particles[ps.Parent];
            //    unityParticleSystem.transform.parent = father.transform;
            //}
            //else
            //{
            //    unityParticleSystem.transform.parent = root.transform;
            //}

            unityParticleSystem.transform.parent = root.transform;

            TransformUtil.SetTransformFromMatrix(unityParticleSystem.transform, ref matrix);

            var tmpRotation = unityParticleSystem.transform.localRotation;

            Quaternion rotNeg90 = new Quaternion();
            rotNeg90.eulerAngles = new Vector3(-90, 0, 0);

            //local rotation tmpRotation * rotNeg90, NOT global rotation rotNeg90 * tmpRotation
            unityParticleSystem.transform.localRotation = tmpRotation * rotNeg90;

            //exchange y,z scale
            unityParticleSystem.transform.localScale = new Vector3(unityParticleSystem.transform.localScale.x, unityParticleSystem.transform.localScale.z, unityParticleSystem.transform.localScale.y);

            UnityEngine.ParticleSystem ups = unityParticleSystem.GetComponent <UnityEngine.ParticleSystem>();

            //StreamWriter sw = new StreamWriter("D:\\ps.txt", false, Encoding.UTF8);
            //sw.WriteLine(string.Format("displayName \t propertyPath \t type"));
            //UnityEditor.SerializedObject so = new UnityEditor.SerializedObject(ups);
            //UnityEditor.SerializedProperty it = so.GetIterator();
            //while (it.Next(true))
            //{
            //    UnityEngine.Debug.Log(it.propertyPath);
            //    int count = it.propertyPath.Count(f => f == '.');
            //    sw.WriteLine(string.Format("{0}{1},{2},{3},{4}", (count == 0 ? "" : String.Empty.PadLeft(count, '-')), it.displayName, it.propertyPath, it.type, it.tooltip));
            //}
            //sw.Close();
            FillMainModule(ups, ps);
            FillEmissionModule(ups, ps);
            FillShapeModule(ups, ps);
            FillVelocityOverLifetimeModule(ups, ps);
            FillRotationOverTimeModule(ups, ps);
            FillRenderModule(ups, ps);

            FillExtraParam(ups, ps);

            FillEffector(ups, ps);
            particles.Add(ps.ChunkId, unityParticleSystem);

            rootMain.loop     = rootMain.loop | ups.main.loop;
            rootMain.duration = UnityEngine.Mathf.Max(rootMain.duration, ups.main.duration);
        }
        UnityEngine.Object prefab = UnityEditor.PrefabUtility.CreateEmptyPrefab(SceneFileCopy.GetRelativePrefabDir(root.name) + root.name + ".prefab");
        UnityEditor.PrefabUtility.ReplacePrefab(root, prefab, UnityEditor.ReplacePrefabOptions.ReplaceNameBased);
    }