void OnDestroy() { if (m_TmpDecal != null) { m_TmpDecal.Destroy(); m_TmpDecal = null; } }
public void OnDelClick() { s_CurrentDelDecal = VCEAssetMgr.GetDecal(m_GUID); if (s_CurrentDelDecal != null) { VCEMsgBox.Show(VCEMsgBoxType.DECAL_DEL_QUERY); } }
public void HideWindow() { m_PathInput.text = ""; if (m_TmpDecal != null) { m_TmpDecal.Destroy(); m_TmpDecal = null; } m_Window.SetActive(false); }
// Update is called once per frame void LateUpdate() { VCDecalAsset decal_asset = VCEAssetMgr.GetDecal(m_Guid); if (decal_asset == null) { if (m_Iso != null && m_Iso.m_DecalAssets != null && m_AssetIndex >= 0 && m_AssetIndex < VCIsoData.DECAL_ARR_CNT) { decal_asset = m_Iso.m_DecalAssets[m_AssetIndex]; } } if (decal_asset == null) { m_Projector.gameObject.SetActive(false); return; } if (VCEditor.DocumentOpen() && m_Tool != null && m_Tool.m_SelBound != null) { m_Tool.m_SelBound.transform.localScale = new Vector3(m_Size, m_Size, m_Depth * 2 - 0.002f); m_Tool.m_SelBound.transform.localPosition = new Vector3(0, 0, 0); } Material usedMaterial = null; if (m_ShaderIndex >= 0 && m_ShaderIndex < m_DecalMats.Length) { usedMaterial = m_DecalMats[m_ShaderIndex]; } m_Projector.gameObject.SetActive(usedMaterial != null); if (usedMaterial != null) { m_Projector.material = usedMaterial; m_Projector.nearClipPlane = 0.001f - m_Depth; m_Projector.farClipPlane = m_Depth - 0.001f; m_Projector.orthographicSize = m_Size * 0.5f; usedMaterial.SetTexture("_Texture", decal_asset.m_Tex); usedMaterial.SetColor("_TintColor", m_Color); usedMaterial.SetFloat("_Size", m_Size * 0.5f); usedMaterial.SetFloat("_Depth", m_Depth); usedMaterial.SetVector("_Center", new Vector4(transform.position.x, transform.position.y, transform.position.z, 1)); usedMaterial.SetVector("_Forward", new Vector4(transform.forward.x, transform.forward.y, transform.forward.z, 0)); if (m_Mirrored) { usedMaterial.SetVector("_Right", -new Vector4(transform.right.x, transform.right.y, transform.right.z, 0)); } else { usedMaterial.SetVector("_Right", new Vector4(transform.right.x, transform.right.y, transform.right.z, 0)); } usedMaterial.SetVector("_Up", new Vector4(transform.up.x, transform.up.y, transform.up.z, 0)); } }
public override void Redo() { VCDecalAsset old_dcl = VCEditor.s_Scene.m_IsoData.m_DecalAssets[m_Index]; VCDecalAsset new_dcl = VCEAssetMgr.GetDecal(m_NewDecal); ulong old_guid = (old_dcl == null) ? (0) : (old_dcl.m_Guid); ulong new_guid = (new_dcl == null) ? (0) : (new_dcl.m_Guid); if (old_guid != new_guid) { VCEditor.s_Scene.m_IsoData.m_DecalAssets[m_Index] = new_dcl; } }
// Query a decal index for a specified VCDecalAsset public int QueryNewDecalIndex(VCDecalAsset vcdcl) { if (vcdcl == null) { return(-1); } // Find the same decal for (int i = 0; i < DECAL_ARR_CNT; ++i) { if (m_DecalAssets[i] != null && vcdcl.m_Guid == m_DecalAssets[i].m_Guid) { return(i); } } // Find a null position for (int i = 0; i < DECAL_ARR_CNT; ++i) { if (m_DecalAssets[i] == null) { return(i); } } // Full, find not used int[] used_count = new int [DECAL_ARR_CNT]; for (int i = 0; i < DECAL_ARR_CNT; ++i) { used_count[i] = 0; } foreach (VCComponentData cdata in m_Components) { if (cdata.m_Type == EVCComponent.cpDecal) { VCDecalData ddata = cdata as VCDecalData; if (ddata != null) { if (ddata.m_AssetIndex >= 0 && ddata.m_AssetIndex < DECAL_ARR_CNT) { used_count[ddata.m_AssetIndex]++; } } } } for (int i = 0; i < DECAL_ARR_CNT; ++i) { if (used_count[i] == 0) { return(i); } } // Unfortunately, no decal avaliable return(-1); }
public static bool AddDecalFromTemp(ulong guid) { if (s_TempDecals.ContainsKey(guid)) { VCDecalAsset vcdcl = s_TempDecals[guid]; s_TempDecals.Remove(guid); s_Decals.Add(guid, vcdcl); return(CreateDecalDataFile(vcdcl)); } else { return(false); } }
public void OnAddClick() { if (VCEAssetMgr.AddDecalFromTemp(m_GUID)) { VCDecalAsset decal = VCEAssetMgr.GetDecal(m_GUID); VCEditor.SelectedDecalGUID = m_GUID; m_ParentList.RefreshDecalList(); VCEStatusBar.ShowText("Add decal".ToLocalizationString() + " [" + decal.GUIDString + "] " + "from the current ISO".ToLocalizationString() + " !", 6f, true); } else { VCEMsgBox.Show(VCEMsgBoxType.DECAL_NOT_SAVED); } s_CurrentDelDecal = null; }
public int QueryExistDecalIndex(VCDecalAsset vcdcl) { if (vcdcl == null) { return(-1); } // Find the same decal for (int i = 0; i < DECAL_ARR_CNT; ++i) { if (m_DecalAssets[i] != null && vcdcl.m_Guid == m_DecalAssets[i].m_Guid) { return(i); } } return(-1); }
// Use this for initialization void Start() { m_DecalUITexMat = Material.Instantiate(m_DecalUITex.material) as Material; m_DecalUITex.material = m_DecalUITexMat; m_SelectedSign.SetActive(false); VCDecalAsset dcl = VCEAssetMgr.GetDecal(m_GUID); if (dcl != null) { m_DecalUITexMat.SetTexture("_MainTex", dcl.m_Tex); } else { m_DecalUITexMat.SetTexture("_MainTex", null); } }
// Create decal data file public static bool CreateDecalDataFile(VCDecalAsset vcdcl) { 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(); return(true); } catch (Exception) { return(false); } }
public void OnOKClick() { if (m_ErrorLabel.text.Trim().Length < 1 && m_TmpDecal != null && m_TmpDecal.m_Tex != null) { VCDecalAsset newdcl = new VCDecalAsset(); newdcl.Import(m_TmpDecal.Export()); VCEAssetMgr.s_Decals.Add(newdcl.m_Guid, newdcl); if (!VCEAssetMgr.CreateDecalDataFile(newdcl)) { VCEMsgBox.Show(VCEMsgBoxType.DECAL_NOT_SAVED); } VCEditor.SelectedDecal = newdcl; VCEditor.Instance.m_UI.m_DecalList.RefreshDecalList(); VCEditor.SelectedDecal = newdcl; VCEStatusBar.ShowText("Added new decal".ToLocalizationString() + " !", 4f, true); } }
// Update is called once per frame void Update() { if (VCEditor.DocumentOpen()) { VCDecalAsset decal = VCEAssetMgr.GetDecal(m_GUID); m_SelectedSign.SetActive(VCEditor.SelectedDecalGUID == m_GUID && m_GUID != 0); int index = VCEditor.s_Scene.m_IsoData.QueryExistDecalIndex(decal); if (index >= 0 && VCEditor.s_Scene.m_IsoData.m_DecalAssets[index] == decal) { m_IndexLabel.text = (index + 1).ToString() + " of " + VCIsoData.DECAL_ARR_CNT.ToString(); m_IndexLabel.color = Color.white; } else if (VCEditor.SelectedDecal == decal) { if (VCEditor.SelectedDecalIndex < 0) { m_IndexLabel.text = "FULL"; m_IndexLabel.color = Color.red; } else { m_IndexLabel.text = (VCEditor.SelectedDecalIndex + 1).ToString() + " of " + VCIsoData.DECAL_ARR_CNT.ToString(); m_IndexLabel.color = Color.white; } } else { m_IndexLabel.text = ""; m_IndexLabel.color = Color.white; } bool tempdcl = VCEAssetMgr.s_TempDecals.ContainsKey(m_GUID); bool existdcl = VCEAssetMgr.s_Decals.ContainsKey(m_GUID); m_AddBtn.SetActive(tempdcl && !existdcl); m_DelBtn.SetActive(!tempdcl && existdcl && index < 0 && VCEditor.SelectedDecal == decal); } }
// 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 (!VCEditor.DocumentOpen()) { return; } if (VCEditor.Instance.m_UI.m_MaterialTab.isChecked) { if (VCEditor.SelectedMaterial != null) { if (m_lastMat != VCEditor.SelectedMaterial) { m_UIGroup.SetActive(true); m_MaterialIconTexture.mainTexture = VCEditor.SelectedMaterial.m_DiffuseTex; m_MaterialIcon.material = m_MaterialIconTexture; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_MaterialIcon.gameObject.SetActive(true); m_ComponentIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = VCEditor.SelectedMaterial.m_Name; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastMat = VCEditor.SelectedMaterial; m_lastDecal = null; m_lastPart = null; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_DecalTab.isChecked) { if (VCEditor.SelectedDecal != null) { if (m_lastDecal != VCEditor.SelectedDecal) { m_UIGroup.SetActive(true); m_MaterialIconTexture.mainTexture = VCEditor.SelectedDecal.m_Tex; m_MaterialIcon.material = m_MaterialIconTexture; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_MaterialIcon.gameObject.SetActive(true); m_ComponentIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = "1 " + "decal".ToLocalizationString() + " [999999](UID = " + VCEditor.SelectedDecal.GUIDString + ")[-]"; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastDecal = VCEditor.SelectedDecal; m_lastMat = null; m_lastPart = null; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_PartTab.isChecked) { if (VCEditor.SelectedPart != null) { if (m_lastPart != VCEditor.SelectedPart) { m_ComponentIcon.spriteName = VCEditor.SelectedPart.m_IconPath.Split(',')[0]; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_ComponentIcon.gameObject.SetActive(true); m_UIGroup.SetActive(true); m_MaterialIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = VCEditor.SelectedPart.m_Name; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastMat = null; m_lastDecal = null; m_lastPart = VCEditor.SelectedPart; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_PaintTab.isChecked) { Color color = VCEditor.SelectedColor; color.a = 1; m_ColorIcon.color = color; if (m_lastColor != color) { m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); } m_ColorIcon.gameObject.SetActive(true); m_UIGroup.SetActive(true); m_MaterialIcon.gameObject.SetActive(false); m_ComponentIcon.gameObject.SetActive(false); m_ItemNameLabel.text = "RGB ( " + (color.r * 100).ToString("0") + "%, " + (color.g * 100).ToString("0") + "%, " + (color.b * 100).ToString("0") + "% )"; m_IconMask.SetActive(true); m_lastMat = null; m_lastDecal = null; m_lastPart = null; m_lastColor = color; } else { m_UIGroup.SetActive(false); m_lastMat = null; m_lastDecal = null; m_lastPart = null; m_lastColor = Color.clear; } }
// 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); }
public void ShowWindow() { m_TmpDecal = new VCDecalAsset(); m_Window.SetActive(true); }
public bool Import(byte[] buffer, VAOption options) { if (buffer == null) { return(false); } Reset(options); int min_iso_size = 48; if (buffer.Length < min_iso_size) { return(false); } using (MemoryStream ms_iso = new MemoryStream(buffer)) { BinaryReader r = new BinaryReader(ms_iso); // Header string check_str = r.ReadString(); // r, string if (check_str != "VCISO") { r.Close(); return(false); } int l = 0; m_HeadInfo.Version = r.ReadInt32(); // r, int m_HeadInfo.Category = (EVCCategory)(r.ReadInt32()); // r, int string author = ""; if (m_HeadInfo.Version >= 0x02020000) { author = r.ReadString(); } m_HeadInfo.Name = r.ReadString(); // r, string m_HeadInfo.Desc = r.ReadString(); // r, string string remarks = ""; if (m_HeadInfo.Version >= 0x02020000) { remarks = r.ReadString(); } m_HeadInfo.xSize = r.ReadInt32(); // r, int m_HeadInfo.ySize = r.ReadInt32(); // r, int m_HeadInfo.zSize = r.ReadInt32(); // r, int l = r.ReadInt32(); // r, int m_HeadInfo.IconTex = r.ReadBytes(l); // r, byte[] //m_HeadInfo.EnsureIconTexValid(); m_HeadInfo.Author = ""; m_HeadInfo.Remarks = ""; if (m_HeadInfo.Version >= 0x02020000) { for (int c = 0; c < author.Length; ++c) { m_HeadInfo.Author += (char)(author[c] ^ (char)(0xAC)); } for (int c = 0; c < remarks.Length; ++c) { m_HeadInfo.Remarks += (char)(remarks[c] ^ (char)(0xAC)); } } switch (m_HeadInfo.Version) { case 0x02000000: case 0x02010000: case 0x02020000: case 0x02020001: { // Counts int mat_cnt = r.ReadInt32(); // r, int int dcl_cnt = 0; if (m_HeadInfo.Version >= 0x02010000) { dcl_cnt = r.ReadInt32(); // r, int } int com_cnt = r.ReadInt32(); // r, int int vxl_cnt = r.ReadInt32(); // r, int int clr_cnt = r.ReadInt32(); // r, int // Materials for (int i = 0; i < mat_cnt; ++i) { ulong guid = r.ReadUInt64(); // r, ulong; if (guid != 0) { l = r.ReadInt32(); // r, int byte[] mat_buffer = r.ReadBytes(l); // r, byte[] // Option // If for editor, find mats in VCEAssetMgr for the iso, or create mats in VCEAssetMgr. if (m_Options.ForEditor) { //if ( VCEAssetMgr.s_Materials.ContainsKey(guid) ) //{ // m_Materials[i] = VCEAssetMgr.s_Materials[guid]; //} //else //{ // VAMaterial vcmat = new VAMaterial (); // vcmat.Import(mat_buffer); // VCEAssetMgr.s_TempMaterials.Add(guid, vcmat); // m_Materials[i] = vcmat; //} } // If not for editor, these materials are belong to the iso. else { m_Materials[i] = new VAMaterial(); m_Materials[i].Import(mat_buffer); } } } // Decals for (int i = 0; i < dcl_cnt; ++i) { ulong guid = r.ReadUInt64(); // r, ulong; if (guid != 0) { l = r.ReadInt32(); // r, int byte[] dcl_buffer = r.ReadBytes(l); // r, byte[] // Option // If for editor, find decals in VCEAssetMgr for the iso, or create decals in VCEAssetMgr. if (m_Options.ForEditor) { if (VCEAssetMgr.s_Decals.ContainsKey(guid)) { m_DecalAssets[i] = VCEAssetMgr.s_Decals[guid]; } else { VCDecalAsset vcdcl = new VCDecalAsset(); vcdcl.Import(dcl_buffer); VCEAssetMgr.s_TempDecals.Add(guid, vcdcl); m_DecalAssets[i] = vcdcl; } } // If not for editor, these decals are belong to the iso. else { m_DecalAssets[i] = new VCDecalAsset(); m_DecalAssets[i].Import(dcl_buffer); } } } // Read compressed data // using (MemoryStream ms_zip = new MemoryStream()) { l = r.ReadInt32(); // r, int ms_zip.Write(r.ReadBytes(l), 0, l); // r, byte[] zip, byte[] // Decompress data // using (MemoryStream ms_unzip = new MemoryStream()) { ms_zip.Seek((long)(0), SeekOrigin.Begin); IonicZlib.Decompress(ms_zip, ms_unzip); ms_unzip.Seek((long)(0), SeekOrigin.Begin); BinaryReader r_unzip = new BinaryReader(ms_unzip); // Components for (int i = 0; i < com_cnt; ++i) { l = r_unzip.ReadInt32(); // unzip, int if (l > 0) { byte[] com_buffer = r_unzip.ReadBytes(l); // unzip, byte[] EVCComponent com_type = (EVCComponent)(r_unzip.ReadInt32()); // unzip, int VCComponentData cdata = VCComponentData.Create(com_type, com_buffer); if (cdata != null) { //cdata.m_CurrIso = this; m_Components.Add(cdata); } } } if (m_HeadInfo.Version >= 0x02020001) { ulong sig = r_unzip.ReadUInt64(); if (m_HeadInfo.HeadSignature != sig) { Debug.LogError("Check sig failed"); return(false); } } // Voxels for (int i = 0; i < vxl_cnt; ++i) { int key = r_unzip.ReadInt32(); // unzip, int ushort val = r_unzip.ReadUInt16(); // unzip, ushort m_Voxels[key] = (VCVoxel)(val); } // Colors for (int i = 0; i < clr_cnt; ++i) { int key = r_unzip.ReadInt32(); // unzip, int Color32 val; val.r = r_unzip.ReadByte(); // unzip, byte val.g = r_unzip.ReadByte(); // unzip, byte val.b = r_unzip.ReadByte(); // unzip, byte val.a = r_unzip.ReadByte(); // unzip, byte m_Colors.Add(key, val); } r_unzip.Close(); } } break; } default: return(false); } r.Close(); return(true); } }