// Read file and add decal work private static void LoadDecalFromList(string[] files) { foreach (string s in files) { VCDecalAsset vcdcl = new VCDecalAsset(); try { FileStream fs = new FileStream(s, FileMode.Open, FileAccess.ReadWrite); byte[] buffer = new byte [(int)(fs.Length)]; fs.Read(buffer, 0, (int)(fs.Length)); fs.Close(); vcdcl.Import(buffer); // Check file valid string guid_from_filename = new FileInfo(s).Name.ToUpper(); string filename_should_be = (vcdcl.GUIDString + VCConfig.s_DecalFileExt).ToUpper(); if (guid_from_filename != filename_should_be) { throw new Exception("The name and GUID doesn't match!"); } } catch (Exception e) { vcdcl.Destroy(); Debug.LogError("Load decal [" + s + "] failed ! \r\n" + e.ToString()); continue; } if (s_Decals.ContainsKey(vcdcl.m_Guid)) { s_Decals[vcdcl.m_Guid].Destroy(); s_Decals[vcdcl.m_Guid] = vcdcl; } else { s_Decals.Add(vcdcl.m_Guid, vcdcl); } } }
// Send some default decals if user's decal count is 0 private static void SendDefaultDecals() { for (int i = 0; i < 6; ++i) { TextAsset ta = Resources.Load("Decals/Default" + i.ToString("00")) as TextAsset; if (ta == null) { continue; } VCDecalAsset vcdcl = new VCDecalAsset(); vcdcl.Import(ta.bytes); try { byte[] buffer = vcdcl.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_DecalPath + sguid + VCConfig.s_DecalFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); } catch (Exception e) { vcdcl.Destroy(); Debug.LogError("Save decal [" + vcdcl.GUIDString + "] failed ! \r\n" + e.ToString()); continue; } if (s_Decals.ContainsKey(vcdcl.m_Guid)) { s_Decals[vcdcl.m_Guid].Destroy(); s_Decals[vcdcl.m_Guid] = vcdcl; } else { s_Decals.Add(vcdcl.m_Guid, vcdcl); } } }
// Update is called once per frame void Update() { if (!WindowVisible()) { return; } if (VCEditor.SelectedDecal != null) { HideWindow(); } if (m_PathInput.text.Length > 0) { string s = m_PathInput.text.Replace("\\", "/"); if (m_PathInput.text != s) { m_PathInput.text = s; } } if (m_LastPath.Length < 4) { if (m_TmpDecal != null) { m_TmpDecal.Destroy(); m_TmpDecal = null; } } if (m_LastPath != m_PathInput.text) { m_LastPath = m_PathInput.text; if (m_TmpDecal != null) { m_TmpDecal.Destroy(); m_TmpDecal = null; } Texture2D tmptex = VCUtils.LoadTextureFromFile(m_PathInput.text); if (tmptex != null) { m_TmpDecal = new VCDecalAsset(); m_TmpDecal.Import(tmptex.EncodeToPNG()); Texture2D.Destroy(tmptex); } } if (m_TmpDecal != null && m_TmpDecal.m_Tex != null) { m_UIDLabel.text = m_TmpDecal.GUIDString; m_DecalUIMat.mainTexture = m_TmpDecal.m_Tex; m_DecalUITex.gameObject.SetActive(true); if (VCEAssetMgr.GetDecal(m_TmpDecal.m_Guid) != null) { m_ErrorLabel.text = "The same decal image already exist".ToLocalizationString() + " !"; } else if (m_TmpDecal.m_Tex.width > 512 || m_TmpDecal.m_Tex.height > 512) { m_ErrorLabel.text = "Decal size must smaller than 512px".ToLocalizationString() + " !"; } else { m_ErrorLabel.text = ""; } } else { m_UIDLabel.text = "0000000000000000"; m_DecalUITex.gameObject.SetActive(false); m_DecalUIMat.mainTexture = null; m_ErrorLabel.text = "Please specify a decal image".ToLocalizationString() + " (*.png)"; } m_CreateBtnGO.SetActive(m_ErrorLabel.text.Trim().Length < 1); }