public static VCComponentData Create(VCPartInfo part) { if (part == null) { return(null); } VCComponentData data = Create(part.m_Type); data.m_ComponentId = part.m_ID; data.m_Type = part.m_Type; data.m_Position = Vector3.zero; data.m_Rotation = Vector3.zero; data.m_Scale = Vector3.one; data.m_Visible = true; return(data); }
private static void LoadParts() { s_Parts = new Dictionary <int, VCPartInfo> (); #if PLANET_EXPLORERS string sql = " SELECT a.id, a.itemid, a.costcount, a.type, b._engName as name, a.path as respath, " + " b._iconId as iconpath, b.currency_value as sellprice, a.weight, a.volume, a.mirror_mask, a.symmetric " + " FROM vc_part a, PrototypeItem b" + " WHERE a.itemid = b.id " + " ORDER BY cast(a.type as int) ASC, cast(a.sort as int) ASC"; SqliteDataReader reader = LocalDatabase.Instance.ExecuteQuery(sql); while (reader.Read()) { VCPartInfo part = new VCPartInfo(); try{ part.m_ID = Convert.ToInt32(reader.GetString(reader.GetOrdinal("id"))); part.m_ItemID = Convert.ToInt32(reader.GetString(reader.GetOrdinal("itemid"))); part.m_CostCount = Convert.ToInt32(reader.GetString(reader.GetOrdinal("costcount"))); part.m_Type = (EVCComponent)(Convert.ToInt32(reader.GetString(reader.GetOrdinal("type")))); // part.m_Name = reader.GetString(reader.GetOrdinal("name")); part.m_ResPath = reader.GetString(reader.GetOrdinal("respath")); //Debug.Log("[VCPart]Loading "+part.m_ResPath); part.m_ResObj = Resources.Load(part.m_ResPath) as GameObject; part.m_IconPath = reader.GetString(reader.GetOrdinal("iconpath")); part.m_SellPrice = Convert.ToSingle(reader.GetString(reader.GetOrdinal("sellprice"))); part.m_Weight = Convert.ToSingle(reader.GetString(reader.GetOrdinal("weight"))); part.m_Volume = Convert.ToSingle(reader.GetString(reader.GetOrdinal("volume"))); part.m_MirrorMask = Convert.ToInt32(reader.GetString(reader.GetOrdinal("mirror_mask"))); part.m_Symmetric = Convert.ToInt32(reader.GetString(reader.GetOrdinal("symmetric"))); s_Parts.Add(part.m_ID, part); }catch (Exception ex) { Debug.LogWarning("Exception on load parts:" + part.m_ID + "\n" + ex); } } #endif }
// 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; } }
void Update() { if (VCEditor.SelectedPart == null) { return; } if (VCEInput.s_Cancel) { Cancel(); return; } if (VCEditor.SelectedPart != m_LastSelectedPart) { if (m_PartInst != null) { GameObject.Destroy(m_PartInst); } if (VCEditor.SelectedPart.m_ResObj == null) { Debug.LogError("This part has no prefab resource: " + VCEditor.SelectedPart.m_Name); Cancel(); return; } m_PartInst = GameObject.Instantiate(VCEditor.SelectedPart.m_ResObj) as GameObject; m_PartInst.SetActive(false); m_PartInst.transform.parent = this.transform; m_PartInst.transform.localPosition = Vector3.zero; m_Tool = m_PartInst.GetComponent <VCEComponentTool>(); m_Tool.m_IsBrush = true; m_Tool.m_InEditor = true; m_Tool.m_ToolGroup.SetActive(true); Collider[] cs = m_PartInst.GetComponentsInChildren <Collider>(true); foreach (Collider c in cs) { if (c.gameObject != m_Tool.m_ToolGroup.gameObject) { Collider.Destroy(c); } else { c.enabled = false; } } m_LastSelectedPart = VCEditor.SelectedPart; } float voxel_size = VCEditor.s_Scene.m_Setting.m_VoxelSize; if (!VCEInput.s_MouseOnUI && VCEMath.RayCastDrawTarget(VCEInput.s_PickRay, out m_Target, VCEMath.MC_ISO_VALUE) && VCEditor.s_Scene.m_IsoData.IsPointIn(m_Target.cursor)) { m_PartInst.SetActive(true); Vector3 point = m_Target.rch.point * 2; IntVector3 ipoint = new IntVector3(point); m_Tool.SetPivotPos(ipoint.ToVector3() * 0.5f * voxel_size); bool canput = true; if (VCEditor.s_Scene.m_IsoData.FindComponentsAtPos(m_PartInst.transform.localPosition).Count > 0) { canput = false; } // Mirror if (VCEditor.s_Mirror.Enabled_Masked) { VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize); if (m_PartInst.transform.localPosition.x == VCEditor.s_Mirror.WorldPos.x && VCEditor.s_Mirror.XPlane_Masked) { canput = false; } if (m_PartInst.transform.localPosition.y == VCEditor.s_Mirror.WorldPos.y && VCEditor.s_Mirror.YPlane_Masked) { canput = false; } if (m_PartInst.transform.localPosition.z == VCEditor.s_Mirror.WorldPos.z && VCEditor.s_Mirror.ZPlane_Masked) { canput = false; } } if (canput) { m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Green; m_Tool.m_SelBound.m_Highlight = false; } else { m_Tool.m_SelBound.m_BoundColor = GLComponentBound.s_Red; m_Tool.m_SelBound.m_Highlight = true; } if (Input.GetMouseButtonDown(0) && canput) { Do(); } } else { m_PartInst.SetActive(false); } }