예제 #1
0
 /*
  * Setup
  */
 void Awake()
 {
     _renderer = GetComponent <InventoryRenderer>();
     if (_renderer == null)
     {
         throw new NullReferenceException("Could not find a renderer. This is not allowed!");
     }
 }
예제 #2
0
        /*
         * Returns the offset between dragged item and the grid
         */
        private Vector2 GetDraggedItemOffset(InventoryRenderer renderer, IInventoryItem item)
        {
            var scale = new Vector2(
                Screen.width / _canvasRect.sizeDelta.x,
                Screen.height / _canvasRect.sizeDelta.y
                );
            var gx = -(item.width * renderer.cellSize.x / 2f) + (renderer.cellSize.x / 2);
            var gy = -(item.height * renderer.cellSize.y / 2f) + (renderer.cellSize.y / 2);

            return(new Vector2(gx, gy) * scale);
        }
예제 #3
0
        /*
         * Setup
         */
        void Awake()
        {
            _renderer = GetComponent <InventoryRenderer>();
            if (_renderer == null)
            {
                throw new NullReferenceException("Could not find a renderer. This is not allowed!");
            }

            // Find the canvas
            var canvases = GetComponentsInParent <Canvas>();

            if (canvases.Length == 0)
            {
                throw new NullReferenceException("Could not find a canvas.");
            }
            _canvas = canvases[canvases.Length - 1];
        }