Ejemplo n.º 1
0
        /// <summary>
        /// Instantiate a new grid of cells in a square, taking their size into account for cell placement. Then recalculates the placement of all environment objects.
        /// </summary>
        public void GenerateGridInEditor()
        {
            DestroyGridInEditor();

            grid = new Cell[Size, Size];

            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    CreateCell(x, y);
                }
            }

            GameObject[] envObjects = GameObject.FindGameObjectsWithTag("Environment");

            for (int i = 0; i < envObjects.Length; i++)
            {
                SnapToMap snappableObject = envObjects[i].GetComponent <SnapToMap>();
                if (snappableObject != null)
                {
                    snappableObject.OccupyCell();
                }
            }
        }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        SnapToMap snapObject = (SnapToMap)target;

        if (GUILayout.Button("Snap To Map Grid"))
        {
            snapObject.SnapToGrid();
        }
    }
Ejemplo n.º 3
0
    private void OnSceneGUI()
    {
        //Get the current GUI event, see if it is a mouse up event, and apply the snap to grid behavior if it is
        SnapToMap snapObject = (SnapToMap)target;
        Event     e          = Event.current;
        int       controlID  = GUIUtility.GetControlID(FocusType.Passive);

        switch (e.GetTypeForControl(controlID))
        {
        case EventType.MouseUp:
            GUIUtility.hotControl = 0;
            e.Use();
            snapObject.SnapToGrid();

            //Debug.Log("up");
            break;
        }
    }