Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        EnvironmentElement element = (EnvironmentElement)target;


        if (GUILayout.Button("ApplyToTilemap", GUILayout.Width(200)))
        {
            if (element.tile != null)
            {
                element.tile.SetOccupied(false);
                EditorUtility.SetDirty(element.tile);
            }


            Vector3 pos = element.transform.position;
            pos.y -= 0.1f;
            GameObject collider = M_GameHelper.SGetObjectAtWorldPoint(pos);

            Tile tile = collider.transform.parent.gameObject.GetComponent <Tile>();

            if (tile != null)
            {
                pos   = tile.gameObject.transform.position;
                pos.y = M_MapManager.SGetYDepthValue(pos.z);
                element.transform.position = pos;
                element.tile = tile;
                tile.SetOccupied(true);
                EditorUtility.SetDirty(element);
                EditorUtility.SetDirty(element.tile);
            }
        }
    }
Ejemplo n.º 2
0
    public void FixedUpdate()
    {
        if (m_tempBuildingObj == null)
        {
            return;
        }

        Vector3 pos = m_tempBuildingObj.transform.position;

        pos.y -= 0.1f;
        GameObject collider = M_GameHelper.SGetObjectAtWorldPoint(pos);

        if (collider != null)
        {
            if (m_currentMiddleTile != collider.transform.parent.gameObject || m_currentMiddleTile == null)
            {
                foreach (Tile obj in m_tilesHighlighted)
                {
                    obj.HighlightOccupied(false);
                }
                m_tilesHighlighted.Clear();
                m_currentMiddleTile = collider.transform.parent.gameObject;

                Tile tile = collider.transform.parent.gameObject.GetComponent <Tile>();
                if (tile == null)
                {
                    return;
                }

                BuildingPhysics physics = m_tempBuildingComp.GetPhysics();
                bool[]          area    = physics.GetArea();
                int             middleI = physics.GetWidth() / 2;
                int             middleJ = physics.GetHeight() / 2;

                for (int i = 0; i < physics.GetWidth(); i++)
                {
                    for (int j = 0; j < physics.GetHeight(); j++)
                    {
                        int  tempI    = tile.i - (middleI - i);
                        int  tempJ    = tile.j - (middleJ - j);
                        Tile tempTile = M_MapManager.SGetTileObject(tempI, tempJ).GetComponent <Tile>();
                        tempTile.HighlightOccupied(true);
                        m_tilesHighlighted.Add(tempTile);
                    }
                }
            }
        }
    }