Esempio n. 1
0
        public void SpawnMeshSequencePlayer()
        {
            GameObject         go     = new GameObject(string.Format("{0} Mesh Sequence Player", name));
            MeshSequencePlayer player = go.AddComponent <MeshSequencePlayer>();

            player.meshSequence = this;
        }
        void Import()
        {
            MeshSequencePlayer t  = target as MeshSequencePlayer;
            MeshSequence       ms = t.meshSequence;

            foreach (TaskInfo ti in t.ImportIE(t.meshSequence))
            {
                if (ti.Persentage < 0)
                {
                    EditorUtility.ClearProgressBar();
                    EditorUtility.DisplayDialog(string.Format("Error importing {0}", t.name), ti.Name, "OK", "");
                    return;
                }
                EditorUtility.DisplayProgressBar(string.Format("Importing {0} {1}%", ms.name, (ti.Persentage * 100).ToString("F0")), ti.Name, ti.Persentage);
            }

            List <Object> usedAssets = new List <Object>();

            for (int f = 0; f < ms.FramesCount; f++)
            {
                int vertcesCountBeforeCompression = ms[f].FrameMesh.vertexCount;
                MeshUtility.SetMeshCompression(ms[f].FrameMesh, (ModelImporterMeshCompression)ms.PreImport.MeshCompression);

                if (ms.PreImport.OptimizeMesh)
                {
                    MeshUtility.Optimize(ms[f].FrameMesh);
                }
                int vertcesCountAfterCompression = ms[f].FrameMesh.vertexCount;
                //Debug.LogFormat("Before:{0} after:{1}", vertcesCountBeforeCompression, vertcesCountAfterCompression);
                ms[f].FrameMesh = (Mesh)AddToAsset(ms, ms[f].FrameMesh);
                usedAssets.Add(ms[f].FrameMesh);
            }

            for (int m = 0; m < ms.Materials.Count; m++)
            {
                ms.Materials[m].Mat = (Material)AddToAsset(ms, ms.Materials[m].Mat);
                usedAssets.Add(ms.Materials[m].Mat);
            }


            CleanupAsset(ms, usedAssets);
            EditorUtility.SetDirty(ms);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            CollectProperties();
            EditorUtility.ClearProgressBar();
            string   path  = AssetDatabase.GetAssetPath(ms).Remove(0, 6);
            string   gPath = Application.dataPath + path;
            FileInfo fi    = new FileInfo(gPath);

            ms.AssetFileSize = fi.Length / 1000000f;
            EditorUtility.SetDirty(ms);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            GUIUtility.ExitGUI();
        }
        void OnSceneGUI()
        {
            MeshSequencePlayer t = target as MeshSequencePlayer;

            if (t.meshSequence != null && EnableAORadiusHandle)
            {
                Tools.hidden  = true;
                Handles.color = Color.red;
                float scale   = t.transform.localScale.magnitude;
                float nradius = Handles.RadiusHandle(Quaternion.identity, t.transform.position, t.meshSequence.PreImport.VColorSettings.AmbientOcclusionRadius * scale);
                if (nradius != t.meshSequence.PreImport.VColorSettings.AmbientOcclusionRadius)
                {
                    t.meshSequence.PreImport.VColorSettings.AmbientOcclusionRadius = nradius / scale;
                    Repaint();
                }
            }
            else
            {
                Tools.hidden = false;
            }
        }