Ejemplo n.º 1
0
 private bool IsValidUnit()
 {
     if (unit.Coord.x < 0 || unit.Coord.y < 0)
     {
         return(false);
     }
     if (!m_bMedify)
     {
         if (UnitSetting.Contains(unit.Coord))
         {
             return(false);
         }
     }
     else
     {
         if (unit.Coord != new Vector2Int(previousX, previousY))
         {
             if (UnitSetting.Contains(unit.Coord))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        void OnSceneGUI()
        {
            unitSetting = (EnemyUnitSetting)target; //注意必须要获取target ,否则该事件不执行

            Handles.BeginGUI();
            GUILayout.BeginArea(new Rect(100, 100, 100, 100));

            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            RaycastHit rayHit;

            if (m_editable)
            {
                //编辑状态下显示右键菜单
                if (Event.current.button < 2)
                {
                    Selection.activeObject = unitSetting.transform;

                    if (Physics.Raycast(ray, out rayHit))
                    {
                        Vector2Int p = new Vector2Int((int)rayHit.point.x, (int)rayHit.point.y);

                        x = Mathf.Clamp(p.x, 0, int.MaxValue);
                        y = Mathf.Clamp(p.y, 0, int.MaxValue);
                        //按下右键弹出菜单
                        if (Event.current.button == 1)
                        {
                            if (unitSetting.Contains(new Vector2Int(x, y)))
                            {
                                setSceneMenu.ShowAsContext();
                            }
                            else
                            {
                                addSceneMenu = new GenericMenu();
                                addSceneMenu.AddItem(new GUIContent("添加敌人"), false, OnAddUnit, 0);
                                if (unitSetting.IsEmpty(unitMirror))
                                {
                                    addSceneMenu.AddDisabledItem(new GUIContent("粘贴"));
                                }
                                else
                                {
                                    addSceneMenu.AddItem(new GUIContent("粘贴"), false, OnPaste);
                                }
                                addSceneMenu.ShowAsContext();
                            }
                        }
                    }
                }
            }
            Undo.RecordObject(unitSetting, "EnemyUnitSetting");
            GUILayout.EndArea();
            Handles.EndGUI();
        }