示例#1
0
 private void InitDragProcessor()
 {
     DragProcessor_UIInventoryItem = new DragProcessor <UIInventoryItem>();
     DragProcessor_UIInventoryItem.Init(
         camera: GameManager.Instance.UICamera,
         layerMask: 1 << UIInventoryItemGridPrefab.layer,
             getScreenMousePositionHandler: (out Vector2 mouseScreenPos) =>
             {
             mouseScreenPos = Input.mousePosition;
             return(true);
             },
             screenMousePositionToWorldHandler: UIInventory_Panel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea,
             onBeginDrag: null,
             onCancelDrag: null);
 }
示例#2
0
    private void Init()
    {
        foreach (Building buildingPrefab in BuildingPrefabList)
        {
            LevelManager.Instance.BuildingPrefabDict.Add(buildingPrefab.BuildingInfo.buildingKey, buildingPrefab);
            LevelManager.Instance.BuildingInfoDict.Add(buildingPrefab.BuildingInfo.buildingKey, buildingPrefab.BuildingInfo);
        }

        DragProcessor <Building> DragProcessor_Building = new DragProcessor <Building>();

        DragProcessor_Building.Init(
            UIManager.Instance.UICamera,
            BuildingLayerMask.value,
            (out Vector2 mouseScreenPos) =>
        {
            mouseScreenPos = Input.mousePosition;
            return(true);
        },
            City.CityEditAreaIndicator.GetMousePosOnThisArea,
            delegate(Building building, Collider collider, DragProcessor dragProcessor) { },
            delegate(Building building, Collider collider, DragProcessor dragProcessor) { }
            );
        CityInventory = new CityInventory(
            InventoryName,
            City.CityEditAreaIndicator,
            DragProcessor_Building,
            gridSize: ConfigManager.GRID_SIZE, // UI units
            rows: Rows,
            columns: Columns,
            x_Mirror: false,
            z_Mirror: false,
            unlockedPartialGrids: false,
            unlockedGridCount: Rows * Columns,
            dragOutDrop: false,
            rotateItemKeyDownHandler: () => Input.GetKeyDown(KeyCode.R), // Rotate building
            instantiateCityInventoryVirtualOccupationQuadHandler: (parent) => Instantiate(CityInventoryVirtualOccupationQuadPrefab, parent).GetComponent <CityInventoryVirtualOccupationQuad>(),
            instantiateCityInventoryGridHandler: (parent) => Instantiate(CityInventoryGridPrefab, parent).GetComponent <CityInventoryGrid>()
            );

        CityInventory.ToggleDebugKeyDownHandler = () => Input.GetKeyDown(KeyCode.BackQuote); // Toggle debug log
        City.Init(CityInventory, CityConfig);
        CityInventory.City = City;
    }
    public void Init()
    {
        DragManager.Instance.Init(
            () => Input.GetMouseButtonDown(0),
            () => Input.GetMouseButtonUp(0),
            Debug.LogError,
            LayerManager.Instance.LayerMask_DragAreas);
        DragProcessor <Building> dragProcessor_Building = new DragProcessor <Building>(); // building里面不包含draggable组件,因此不响应拖拽事件

        dragProcessor_Building.Init(
            CameraManager.Instance.MainCamera,
            LayerManager.Instance.LayerMask_BuildingHitBox,
            (out Vector2 mouseScreenPos) =>
        {
            mouseScreenPos = Input.mousePosition;
            return(true);
        }
            ,
            ScreenMousePositionToWorld_CityInventory,
            delegate(Building building, Collider collider, DragProcessor dragProcessor) { },
            delegate(Building building, Collider collider, DragProcessor dragProcessor) { }
            );
    }
    public void Init()
    {
        DragProcessor <BackpackItem> dragProcessor_BackpackItem = new DragProcessor <BackpackItem>();

        dragProcessor_BackpackItem.Init(
            UIManager.Instance.UICamera,
            LayerManager.Instance.LayerMask_BackpackItemGrid,
            (out Vector2 mouseScreenPos) =>
        {
            if (ControlManager.Instance.BuildingInputActionEnabled)
            {
                mouseScreenPos = ControlManager.Instance.Building_MousePosition;
                return(true);
            }
            else
            {
                mouseScreenPos = Vector2.zero;
                return(false);
            }
        },
            ScreenMousePositionToWorld_BackpackDragArea,
            delegate(BackpackItem bi, Collider collider, DragProcessor dragProcessor) { },
            delegate(BackpackItem bi, Collider collider, DragProcessor dragProcessor) { }
            );

        DragProcessor <MechaComponentDropSprite> dragProcessor_MechaComponentDropSprite = new DragProcessor <MechaComponentDropSprite>();

        dragProcessor_MechaComponentDropSprite.Init(
            CameraManager.Instance.MainCamera,
            LayerManager.Instance.LayerMask_ItemDropped,
            (out Vector2 mouseScreenPos) =>
        {
            if (ControlManager.Instance.BuildingInputActionEnabled)
            {
                mouseScreenPos = ControlManager.Instance.Building_MousePosition;
                return(true);
            }
            else
            {
                mouseScreenPos = Vector2.zero;
                return(false);
            }
        },
            ScreenMousePositionToWorld_MechaEditorInventory,
            delegate(MechaComponentDropSprite mcds, Collider collider, DragProcessor dragProcessor)
        {
            Ray ray = CameraManager.Instance.MainCamera.ScreenPointToRay(ControlManager.Instance.Building_MousePosition);
            MechaComponentInfo mci = mcds.MechaComponentInfo.Clone();
            ClientBattleManager.Instance.PlayerMecha.MechaInfo.AddMechaComponentInfo(mci, GridPosR.Zero);
            MechaComponent mc = ClientBattleManager.Instance.PlayerMecha.MechaComponentDict[mci.GUID];
            GridPos gp        = GridUtils.GetGridPosByMousePos(ClientBattleManager.Instance.PlayerMecha.transform, ray, Vector3.up, ConfigManager.GridSize);
            mci.InventoryItem.SetGridPosition(gp);
            DragManager.Instance.CurrentDrag = mc.GetComponent <Draggable>();
            DragManager.Instance.CurrentDrag.SetOnDrag(true, collider, dragProcessor);
            mcds.PoolRecycle();
        },
            delegate(MechaComponentDropSprite mcds, Collider collider, DragProcessor dragProcessor) { }
            );

        DragManager.Instance.Init(
            () => ControlManager.Instance.Building_MouseLeft.Down,
            () => ControlManager.Instance.Building_MouseLeft.Up,
            Debug.LogError,
            LayerManager.Instance.LayerMask_DragAreas);
        DragProcessor <MechaComponent> dragProcessor_MechaComponent = new DragProcessor <MechaComponent>();

        dragProcessor_MechaComponent.Init(
            CameraManager.Instance.MainCamera,
            LayerManager.Instance.LayerMask_ComponentHitBox_Player,
            (out Vector2 mouseScreenPos) =>
        {
            if (ControlManager.Instance.BuildingInputActionEnabled)
            {
                mouseScreenPos = ControlManager.Instance.Building_MousePosition;
                return(true);
            }
            else
            {
                mouseScreenPos = Vector2.zero;
                return(false);
            }
        }
            ,
            ScreenMousePositionToWorld_MechaEditorInventory,
            delegate(MechaComponent mc, Collider collider, DragProcessor dragProcessor) { },
            delegate(MechaComponent mc, Collider collider, DragProcessor dragProcessor) { }
            );
    }