Пример #1
0
 private void OnEnable()
 {
     Debug.Log("Black Object Editor Enable");
     if (rte == null)
     {
         rte = target as BlockObjectRTE;
     }
     rte.canvasSize = new Vector3Int(rte.data.Width, rte.data.Height, rte.data.Depth);
 }
Пример #2
0
        public void OnSceneGUI()
        {
            if (rte == null)
            {
                rte = target as BlockObjectRTE;
            }
            //            this.DrawBackgroundGrid(canvasSize.x, canvasSize.z, faceColor, lineColor);
            List <Bounds> bounds = new List <Bounds>();

            if (rte.canvasViewMode == BlockObjectRTE.CanvasViewMode.PanelXY)
            {
                var realPanelZ = rte.viewPanelZ - 1;
                this.DrawBgGridXY(realPanelZ, rte.canvasSize.x, rte.canvasSize.y);
                bounds = CreateHitBoundsXY(realPanelZ, rte.canvasSize.x, rte.canvasSize.y);
            }
            else if (rte.canvasViewMode == BlockObjectRTE.CanvasViewMode.PanelYZ)
            {
                var realPanelX = rte.viewPanelX - 1;
                this.DrawBgGridYZ(realPanelX, rte.canvasSize.y, rte.canvasSize.z);
                bounds = CreateHitBoundsYZ(realPanelX, rte.canvasSize.y, rte.canvasSize.z);
            }
            else if (rte.canvasViewMode == BlockObjectRTE.CanvasViewMode.PanelXZ)
            {
                var realPanelY = rte.viewPanelY - 1;
                this.DrawBgGridXZ(realPanelY, rte.canvasSize.x, rte.canvasSize.z);
                bounds = CreateHitBoundsXZ(realPanelY, rte.canvasSize.x, rte.canvasSize.z);
            }
            else if (rte.canvasViewMode == BlockObjectRTE.CanvasViewMode.Free)
            {
            }
            Ray mouseRay  = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            var hitBounds = CheckHitBounds(mouseRay, bounds);
            var oldColor  = Handles.color;

            Handles.color = Color.green;
            foreach (var hb in hitBounds)
            {
//                Handles.DrawWireCube(hb.center, hb.size);
                this.DrawHitBoundsRect(hb);
            }
            //process event
            var e = Event.current;

            if (hitBounds.Count > 0)
            {
                if (e.type == EventType.MouseDown && e.button == 0)
                {
                    var point = GetPointFromBounds(hitBounds[0]);
                    rte.SetBlock(point.x, point.y, point.z, (byte)(rte.selectedBlockIndex + 1));
                    e.Use();
                }
                else if (e.type == EventType.MouseDown && e.button == 1)
                {
                }
            }

            if (rte.isInit == false)
            {
                rte.Init();
            }
            if (rte.blocks == null || rte.blocks.Length == 0)
            {
                rte.InitBlocks();
            }
            //如果图块定义有变化,重新创建图块池
            if (rte.isDefDirty)
            {
                rte.CreateBlockPool();
            }
            //如果图块数据有变化,重新创建mesh
            if (rte.isDirty)
            {
                rte.isDirty = false;
                EditorCoroutineUtility.StartCoroutine(rte.CreateMeshAsyn(), this);
            }
            //ongui
            Handles.color = oldColor;

            Handles.BeginGUI();
            foreach (var hb in hitBounds)
            {
                Vector3 p    = new Vector3(hb.center.x - 0.5f, hb.center.y - 0.5f, hb.center.z - 0.5f);
                var     rect = new Rect(0, 0, 300, 30);
                rect.y += hitBounds.IndexOf(hb) * 30;
                GUI.Label(rect, "当前选择图块坐标:" + p.ToString());
            }
            Handles.EndGUI();

            SceneView.RepaintAll();
        }