Esempio n. 1
0
 // ----------- Submit ------------------------
 void Apply()
 {
     if (m_Target != null)
     {
         ulong old_guid           = 0;
         ulong new_guid           = 0;
         bool  need_update_isomat = (VCEditor.s_Scene.m_IsoData.QueryMaterial(m_Target.m_Guid) != null);
         if (VCEAssetMgr.s_Materials.ContainsKey(m_Target.m_Guid))
         {
             old_guid = m_Target.m_Guid;
             if (!VCEAssetMgr.DeleteMaterialDataFile(m_Target.m_Guid))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
             VCEAssetMgr.s_Materials.Remove(m_Target.m_Guid);
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_Materials.Add(m_Target.m_Guid, m_Target);
             if (!VCEAssetMgr.CreateMaterialDataFile(m_Target))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
         }
         else if (VCEAssetMgr.s_TempMaterials.ContainsKey(m_Target.m_Guid))
         {
             old_guid = m_Target.m_Guid;
             VCEAssetMgr.s_TempMaterials.Remove(m_Target.m_Guid);
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_TempMaterials.Add(m_Target.m_Guid, m_Target);
         }
         else
         {
             Debug.LogError("What the hell is that ?!");
             old_guid = m_Target.m_Guid;
             m_Target.Import(m_TempMaterial.Export());
             new_guid = m_Target.m_Guid;
             VCEAssetMgr.s_Materials.Add(m_Target.m_Guid, m_Target);
             if (!VCEAssetMgr.CreateMaterialDataFile(m_Target))
             {
                 VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED);
             }
         }
         VCEAlterMaterialMap.MatChange(old_guid, new_guid);
         if (need_update_isomat)
         {
             VCEditor.s_Scene.GenerateIsoMat();
         }
         VCEditor.SelectedMaterial = m_Target;
         VCEditor.Instance.m_UI.m_MaterialList.RefreshMaterialListThenFocusOnSelected();
         VCEditor.SelectedMaterial = m_Target;
     }
     else
     {
         Debug.LogError("No target material, Create new material instead !");
         CreateAsNew();
     }
 }
Esempio n. 2
0
 // Create material data file
 public static bool CreateMaterialDataFile(VCMaterial vcmat)
 {
     try
     {
         byte[]     buffer = vcmat.Export();
         ulong      guid   = CRC64.Compute(buffer);
         string     sguid  = guid.ToString("X").PadLeft(16, '0');
         FileStream fs     = new FileStream(VCConfig.s_MaterialPath + sguid + VCConfig.s_MaterialFileExt, FileMode.Create, FileAccess.ReadWrite);
         fs.Write(buffer, 0, buffer.Length);
         fs.Close();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 3
0
 // Send some default materials if user's material count is 0
 private static void SendDefaultMaterials()
 {
     foreach (KeyValuePair <int, VCMatterInfo> kvp in VCConfig.s_Matters)
     {
         VCMatterInfo matter = kvp.Value;
         VCMaterial   vcmat  = new VCMaterial();
         vcmat.m_Name       = "Default".ToLocalizationString() + " " + matter.Name;
         vcmat.m_MatterId   = matter.ItemIndex;
         vcmat.m_UseDefault = true;
         try
         {
             byte[]     buffer = vcmat.Export();
             ulong      guid   = CRC64.Compute(buffer);
             string     sguid  = guid.ToString("X").PadLeft(16, '0');
             FileStream fs     = new FileStream(VCConfig.s_MaterialPath + sguid + VCConfig.s_MaterialFileExt, FileMode.Create, FileAccess.ReadWrite);
             fs.Write(buffer, 0, buffer.Length);
             fs.Close();
             vcmat.Import(buffer);
         }
         catch (Exception e)
         {
             vcmat.Destroy();
             Debug.LogError("Save material [" + vcmat.m_Name + "] failed ! \r\n" + e.ToString());
             continue;
         }
         if (s_Materials.ContainsKey(vcmat.m_Guid))
         {
             s_Materials[vcmat.m_Guid].Destroy();
             s_Materials[vcmat.m_Guid] = vcmat;
         }
         else
         {
             s_Materials.Add(vcmat.m_Guid, vcmat);
         }
     }
 }