Exemplo n.º 1
0
    void Update()
    {
        if (!VCEditor.DocumentOpen())
        {
            return;
        }

        // Check 's_LastCreate'
        if (s_LastCreate != null)
        {
            ClearSelection();
            SelectInfo si = new SelectInfo();
            si.m_Component = s_LastCreate;
            m_Selection.Add(si);
            OnSelectionChange();
        }

        VCEditor.s_ProtectLock0 = UsingGizmo;
        NormalizeSelection();

        // Update Pick Order
        Vector3 mousePos = Input.mousePosition;

        if ((mousePos - lastMousePos).magnitude > 3.1f)
        {
            pick_order   = 0;
            lastMousePos = mousePos;
        }

        #region PART_DESC
        // Part Description Board
        if (m_DescBoard != null)
        {
            m_DescBoard.m_Position = Vector3.Lerp(m_DescBoard.m_Position, VCEInput.s_PickRay.GetPoint(1.5f), 0.5f);
            List <VCEComponentTool> pickall = new List <VCEComponentTool> ();
            if (!UsingGizmo && !VCEInput.s_MouseOnUI)
            {
                pickall = VCEMath.RayPickComponents(VCEInput.s_PickRay);
            }
            List <VCPart> pps = new List <VCPart> ();
            Vector3       v   = Vector3.zero;
            if (pickall.Count > 0)
            {
                v = pickall[0].transform.localPosition;
            }
            foreach (VCEComponentTool ct in pickall)
            {
                if (Vector3.Distance(ct.transform.localPosition, v) > VCEditor.s_Scene.m_Setting.m_VoxelSize * 2)
                {
                    continue;
                }
                VCPart pp = ct.GetComponent <VCPart>();
                if (pp != null)
                {
                    pps.Add(pp);
                }
            }
            if (pickall.Count > 0)
            {
                m_DescBoard.FadeIn();
                VCEditor.Instance.m_UI.m_HoloBoardCamera.enabled = true;
            }
            else
            {
                VCEditor.Instance.m_UI.m_HoloBoardCamera.enabled = false;
                m_DescBoard.FadeOut();
            }
            pickall.Clear();
            VCEditor.Instance.m_UI.m_PartDescList.SyncList(pps);
            pps.Clear();
            pickall = null;
            pps     = null;
        }
        #endregion

        // Pick Component
        VCEComponentTool picked = null;
        if (!VCEInput.s_MouseOnUI && !m_MouseOnGizmo)
        {
            picked = VCEMath.RayPickComponent(VCEInput.s_PickRay, pick_order);
        }
        if (Input.GetMouseButtonDown(0) && !VCEInput.s_MouseOnUI && !m_MouseOnGizmo)
        {
            if (!VCEInput.s_Shift && !VCEInput.s_Control && !VCEInput.s_Alt)
            {
                m_Selection.Clear();
            }
            if (picked != null)
            {
                SelectInfo si = FindSelected(picked);
                if (si != null)
                {
                    m_Selection.Remove(si);
                }
                else
                {
                    si             = new SelectInfo();
                    si.m_Component = picked;
                    List <SelectInfo> del_list = new List <SelectInfo> ();
                    foreach (SelectInfo sel in m_Selection)
                    {
                        VCEComponentTool        ct     = sel.m_Component;
                        List <VCEComponentTool> images = MirrorImage(ct);
                        if (images.Contains(si.m_Component))
                        {
                            del_list.Add(sel);
                        }
                    }
                    m_Selection.Add(si);
                    foreach (SelectInfo del in del_list)
                    {
                        m_Selection.Remove(del);
                    }
                }
                pick_order++;
            }
            OnSelectionChange();
        }

        // Update bound color & highlight
        foreach (VCComponentData cd in VCEditor.s_Scene.m_IsoData.m_Components)
        {
            VCEComponentTool c = cd.m_Entity.GetComponent <VCEComponentTool>();
            c.m_SelBound.enabled = true;
            c.m_SelBound.GetComponent <Collider>().enabled = true;
            c.m_SelBound.m_Highlight  = (c == picked);
            c.m_SelBound.m_BoundColor = GLComponentBound.s_Blue;
        }

        // Update selection and mirror's bound color
        if (m_Selection.Count > 0)
        {
            VCEditor.s_Mirror.CalcPrepare(VCEditor.s_Scene.m_Setting.m_VoxelSize);
            foreach (SelectInfo si in m_Selection)
            {
                VCEComponentTool        c       = si.m_Component;
                List <VCEComponentTool> mirrors = MirrorImage(c);
                foreach (VCEComponentTool m in mirrors)
                {
                    m.m_SelBound.m_BoundColor = GLComponentBound.s_Orange;
                }
            }
            foreach (SelectInfo si in m_Selection)
            {
                VCEComponentTool c = si.m_Component;
                c.m_SelBound.m_BoundColor = GLComponentBound.s_Yellow;
            }
        }

        // Update Inspectors
        if (m_Selection.Count < 1)
        {
            HideInspectors();
        }
        else if (m_Selection.Count == 1)
        {
            ShowMainInspector();

            VCEUISelectComponentInspector sci = m_MainInspector.GetComponent <VCEUISelectComponentInspector>();
            if (m_Selection[0].m_Component != null)
            {
                sci.m_SelectInfo.text = m_Selection[0].m_Component.gameObject.name;
            }
            else
            {
                sci.m_SelectInfo.text = "< Deleted >";
            }
        }
        else
        {
            ShowMainInspector();
            HideDataInspector();
            VCEUISelectComponentInspector sci = m_MainInspector.GetComponent <VCEUISelectComponentInspector>();
            sci.m_SelectInfo.text = m_Selection.Count.ToString() + " " + "objects".ToLocalizationString() + " " + "selected".ToLocalizationString();
        }

        // Transform Gizmos
        if (m_Selection.Count > 0)
        {
            Vector3 avePos  = Vector3.zero;
            int     rotmask = 7;
            foreach (SelectInfo si in m_Selection)
            {
                avePos += si.m_Component.transform.position;
                VCPartData part_data = si.m_Component.m_Data as VCPartData;
                if (part_data != null)
                {
                    rotmask &= VCConfig.s_PartTypes[si.m_Component.m_Data.m_Type].m_RotateMask;
                }
            }
            avePos /= ((float)m_Selection.Count);
            m_MovingGizmo.transform.position   = avePos;
            m_RotatingGizmo.transform.position = avePos;
            m_MovingGizmo.gameObject.SetActive(VCEditor.TransformType == EVCETransformType.Move);
            m_RotatingGizmo.gameObject.SetActive(VCEditor.TransformType == EVCETransformType.Rotate);
            m_RotatingGizmo.m_AxisMask = rotmask;
        }
        else
        {
            m_MovingGizmo.gameObject.SetActive(false);
            m_RotatingGizmo.gameObject.SetActive(false);
        }
    }